VertexListStreamWriter implements AutoCloseable { public void writeAll() throws IOException { while (inputStream.hasNextVertex()) { writeNextVertex(); } outputWriter.flush(); } VertexListStreamWriter(VertexListStream inputStream, OutputStream outputStream); void writeAll(); @Override void close();  }
@Test public void testWriteAllOnMockVertexListStream() throws IOException { VertexListStream vertexListStream = new MockVertexListStream(vertices); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try (VertexListStreamWriter writer = new VertexListStreamWriter(vertexListStream, outputStream)) { writer.writeAll(); assertEquals("Output of VertexListStreamWriter is correct", expectedOutput, outputStream.toString()); } }