DocumentWriteToLineTest.java 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package rocks.zipcode.document;
  2. import org.junit.Assert;
  3. import org.junit.Test;
  4. import rocks.zipcode.Document;
  5. import java.io.IOException;
  6. /**
  7. * @author leon on 16/11/2018.
  8. */
  9. public class DocumentWriteToLineTest {
  10. @Test
  11. public void writeToLineTest1() throws IOException {
  12. // given
  13. String fileName = "target/file.txt";
  14. String contentToBeWritten = "The\nquick\nbrown\nfox";
  15. String replacement = "quicker";
  16. String expected = contentToBeWritten.replaceAll("quick", replacement);
  17. Document documentWriter = new Document(fileName);
  18. documentWriter.write(contentToBeWritten);
  19. // when
  20. documentWriter.write(1, replacement);
  21. // then
  22. Assert.assertEquals(expected, documentWriter.read());
  23. }
  24. @Test
  25. public void writeToLineTest2() throws IOException {
  26. // given
  27. String fileName = "target/file.txt";
  28. String contentToBeWritten = "The\nquick\nbrown\nfox";
  29. String replacement = "quickest";
  30. String expected = contentToBeWritten.replaceAll("The", replacement);
  31. Document documentWriter = new Document(fileName);
  32. documentWriter.write(contentToBeWritten);
  33. // when
  34. documentWriter.write(0, replacement);
  35. // then
  36. Assert.assertEquals(expected, documentWriter.read());
  37. }
  38. }