@Override public void setUp() { source = new TestCharSource(STRING); }
public void testForEachLine() throws IOException { source = new TestCharSource(LINES); ImmutableList.Builder<String> builder = ImmutableList.builder(); source.forEachLine(builder::add); assertEquals(SPLIT_LINES, builder.build()); assertTrue(source.wasStreamOpened()); assertTrue(source.wasStreamClosed()); }
public void testReadLines_toList() throws IOException { TestCharSource lines = new TestCharSource(LINES); assertEquals(ImmutableList.of("foo", "bar", "baz", "something"), lines.readLines()); assertTrue(lines.wasStreamOpened() && lines.wasStreamClosed()); }
public void testReadLines_withProcessor() throws IOException { TestCharSource lines = new TestCharSource(LINES); List<String> list = lines.readLines( new LineProcessor<List<String>>() { List<String> list = Lists.newArrayList(); @Override public boolean processLine(String line) throws IOException { list.add(line); return true; } @Override public List<String> getResult() { return list; } }); assertEquals(ImmutableList.of("foo", "bar", "baz", "something"), list); assertTrue(lines.wasStreamOpened() && lines.wasStreamClosed()); }
public void testReadLines_withProcessor_stopsOnFalse() throws IOException { TestCharSource lines = new TestCharSource(LINES); List<String> list = lines.readLines( new LineProcessor<List<String>>() { List<String> list = Lists.newArrayList(); @Override public boolean processLine(String line) throws IOException { list.add(line); return false; } @Override public List<String> getResult() { return list; } }); assertEquals(ImmutableList.of("foo"), list); assertTrue(lines.wasStreamOpened() && lines.wasStreamClosed()); }
public void testClosesOnErrors_whenWriteThrows() { TestCharSink failSink = new TestCharSink(WRITE_THROWS); try { new TestCharSource(STRING).copyTo(failSink); fail(); } catch (IOException expected) { } assertTrue(failSink.wasStreamClosed()); }
public void testClosesOnErrors_copyingToCharSinkThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, WRITE_THROWS, CLOSE_THROWS)) { TestCharSource okSource = new TestCharSource(STRING); try { okSource.copyTo(new TestCharSink(option)); fail(); } catch (IOException expected) { } // ensure reader was closed IF it was opened (depends on implementation whether or not it's // opened at all if sink.newWriter() throws). assertTrue( "stream not closed when copying to sink with option: " + option, !okSource.wasStreamOpened() || okSource.wasStreamClosed()); } }
public void testClosesOnErrors_whenReadThrows() { TestCharSource failSource = new TestCharSource(STRING, READ_THROWS); try { failSource.copyTo(new TestCharSink()); fail(); } catch (IOException expected) { } assertTrue(failSource.wasStreamClosed()); }
public void testClosesOnErrors_copyingFromCharSourceThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, READ_THROWS, CLOSE_THROWS)) { TestCharSource failSource = new TestCharSource(STRING, option); TestCharSink okSink = new TestCharSink(); try { failSource.copyTo(okSink); fail(); } catch (IOException expected) { } // ensure writer was closed IF it was opened (depends on implementation whether or not it's // opened at all if source.newReader() throws). assertTrue( "stream not closed when copying from source with option: " + option, !okSink.wasStreamOpened() || okSink.wasStreamClosed()); } }
public void testReadFirstLine() throws IOException { TestCharSource lines = new TestCharSource(LINES); assertEquals("foo", lines.readFirstLine()); assertTrue(lines.wasStreamOpened() && lines.wasStreamClosed()); }
public void testClosesOnErrors_copyingToWriterThatThrows() { TestCharSource okSource = new TestCharSource(STRING); try { okSource.copyTo(new TestWriter(WRITE_THROWS)); fail(); } catch (IOException expected) { } assertTrue(okSource.wasStreamClosed()); }
public void testLines() throws IOException { source = new TestCharSource(LINES); ImmutableList<String> lines; try (Stream<String> linesStream = source.lines()) { assertTrue(source.wasStreamOpened()); assertFalse(source.wasStreamClosed()); lines = linesStream.collect(toImmutableList()); } assertTrue(source.wasStreamClosed()); assertEquals(SPLIT_LINES, lines); }
@Override public void setUp() { source = new TestCharSource(STRING); }
public void testForEachLine() throws IOException { source = new TestCharSource(LINES); ImmutableList.Builder<String> builder = ImmutableList.builder(); source.forEachLine(builder::add); assertEquals(SPLIT_LINES, builder.build()); assertTrue(source.wasStreamOpened()); assertTrue(source.wasStreamClosed()); }
public void testReadLines_toList() throws IOException { TestCharSource lines = new TestCharSource(LINES); assertEquals(ImmutableList.of("foo", "bar", "baz", "something"), lines.readLines()); assertTrue(lines.wasStreamOpened() && lines.wasStreamClosed()); }
public void testClosesOnErrors_copyingToWriterThatThrows() { TestCharSource okSource = new TestCharSource(STRING); try { okSource.copyTo(new TestWriter(WRITE_THROWS)); fail(); } catch (IOException expected) { } assertTrue(okSource.wasStreamClosed()); }
public void testReadFirstLine() throws IOException { TestCharSource lines = new TestCharSource(LINES); assertEquals("foo", lines.readFirstLine()); assertTrue(lines.wasStreamOpened() && lines.wasStreamClosed()); }
public void testClosesOnErrors_whenReadThrows() { TestCharSource failSource = new TestCharSource(STRING, READ_THROWS); try { failSource.copyTo(new TestCharSink()); fail(); } catch (IOException expected) { } assertTrue(failSource.wasStreamClosed()); }
public void testClosesOnErrors_whenWriteThrows() { TestCharSink failSink = new TestCharSink(WRITE_THROWS); try { new TestCharSource(STRING).copyTo(failSink); fail(); } catch (IOException expected) { } assertTrue(failSink.wasStreamClosed()); }
public void testLines() throws IOException { source = new TestCharSource(LINES); ImmutableList<String> lines; try (Stream<String> linesStream = source.lines()) { assertTrue(source.wasStreamOpened()); assertFalse(source.wasStreamClosed()); lines = linesStream.collect(toImmutableList()); } assertTrue(source.wasStreamClosed()); assertEquals(SPLIT_LINES, lines); }