@Test public void should_get_a_new_iterator_if_the_input_was_closed() throws Exception { Iterator<String> it1 = VALID_DIRECTORY_INPUT.iterator(); VALID_DIRECTORY_INPUT.close(); Iterator<String> it2 = VALID_DIRECTORY_INPUT.iterator(); assertNotSame(it1, it2); }
@Test(expected = IllegalStateException.class) public void should_throw_IllegalStateException_if_IOException_while_reading_files() throws Exception { Iterator<String> it = VALID_DIRECTORY_INPUT.iterator(); SOME_FILE.delete(); OTHER_FILE.delete(); it.hasNext(); }
@Test public void should_iterate_all_lines() throws Exception { Iterator<String> it = VALID_DIRECTORY_INPUT.iterator(); int nbLines = 0; while (it.hasNext()) { nbLines++; it.next(); } assertEquals(5, nbLines); }
@Test public void should_read_all_lines_in_any_order() throws Exception { String[] expectedContent = new String[] { SOME_FILE_LINE1, SOME_FILE_LINE2, OTHER_FILE_LINE1, OTHER_FILE_LINE2, OTHER_FILE_LINE3 }; Iterator<String> it = VALID_DIRECTORY_INPUT.iterator(); List<String> actualContent = new ArrayList<String>(); while (it.hasNext()) { String line = it.next(); actualContent.add(line); } assertThat(actualContent, hasItems(expectedContent)); }
@Test public void should_get_valid_non_empty_iterator() throws Exception { Iterator<String> it = VALID_DIRECTORY_INPUT.iterator(); assertNotNull(it); assertTrue(it.hasNext()); }
@Test public void should_not_throw_exception_if_close_when_no_iterator() throws Exception { VALID_DIRECTORY_INPUT.close(); }