NumericDocumentWriteTest.java 1.4KB

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