DocumentToStringTest.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 DocumentToStringTest {
  10. @Test
  11. public void toStringTest1() throws IOException {
  12. // given
  13. String fileName = "target/file.txt";
  14. String contentToBeWritten = "The quick brown fox";
  15. Document documentWriter = new Document(fileName);
  16. String expected = new StringBuilder(fileName)
  17. .append("{")
  18. .append(contentToBeWritten)
  19. .append("}")
  20. .toString();
  21. // when
  22. documentWriter.write(contentToBeWritten);
  23. String actual = documentWriter.toString();
  24. // then
  25. Assert.assertEquals(expected, actual);
  26. }
  27. @Test
  28. public void toStringTest2() throws IOException {
  29. // given
  30. String fileName = "target/file.txt";
  31. String contentToBeWritten = "The quicker browner fox";
  32. Document documentWriter = new Document(fileName);
  33. String expected = new StringBuilder(fileName)
  34. .append("{")
  35. .append(contentToBeWritten)
  36. .append("}")
  37. .toString();
  38. // when
  39. documentWriter.write(contentToBeWritten);
  40. String actual = documentWriter.toString();
  41. // then
  42. Assert.assertEquals(expected, actual);
  43. }
  44. }