SpecialCharDocumentTest.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package rocks.zipcode.specialdocument;
  2. import org.junit.Assert;
  3. import org.junit.Test;
  4. import rocks.zipcode.Document;
  5. import rocks.zipcode.SpecialCharDocument;
  6. import java.io.IOException;
  7. /**
  8. * @author leon on 18/11/2018.
  9. */
  10. public class SpecialCharDocumentTest {
  11. @Test(expected = IllegalArgumentException.class)
  12. public void writeNumericValuesToFile() throws IOException {
  13. // given
  14. String fileName = "target/file.txt";
  15. String contentToBeWritten = "123";
  16. Document documentWriter = new SpecialCharDocument(fileName);
  17. // when
  18. documentWriter.write(contentToBeWritten);
  19. }
  20. @Test
  21. public void writeSpecialCharacter1() throws IOException {
  22. // given
  23. String fileName = "target/file.txt";
  24. String contentToBeWritten = "()";
  25. Document documentWriter = new SpecialCharDocument(fileName);
  26. // when
  27. documentWriter.write(contentToBeWritten);
  28. }
  29. @Test
  30. public void writeSpecialCharacter2() throws IOException {
  31. // given
  32. String fileName = "target/file.txt";
  33. String contentToBeWritten = "()_*";
  34. Document documentWriter = new SpecialCharDocument(fileName);
  35. // when
  36. documentWriter.write(contentToBeWritten);
  37. }
  38. @Test(expected = IllegalArgumentException.class)
  39. public void writeAlphaValuesTest() throws IOException {
  40. // given
  41. String fileName = "target/file.txt";
  42. String expected = "The quick brown foxy";
  43. Document documentWriter = new SpecialCharDocument(fileName);
  44. // when
  45. documentWriter.write(expected);
  46. String actual = documentWriter.read();
  47. // then
  48. Assert.assertEquals(expected, actual);
  49. }
  50. }