### Question:
IOFactory { void writeContent(BufferedWriter writer, File content, ContentConverter contentConverter) throws IOException { BufferedReader contentReader = null; try { contentReader = newReader(content); String line; while ((line = contentReader.readLine()) != null) { writeLine(writer, contentConverter.convert(line)); } } finally { if (contentReader != null) { contentReader.close(); } } }    }### Answer:
@Test public void shouldWriteContent() throws IOException { BufferedWriter writer = mock(BufferedWriter.class); File content = mock(File.class); ContentConverter contentConverter = mock(ContentConverter.class); given(reader.readLine()) .willReturn("LINE1") .willReturn("LINE2") .willReturn(null); ioFactory.writeContent(writer, content, contentConverter); verify(contentConverter, times(2)).convert(nullable(String.class)); verify(writer, times(2)).write(nullable(String.class)); verify(writer, times(2)).newLine(); verify(reader).close(); verify(writer, never()).flush(); verify(writer, never()).close(); }
@Test public void shouldWriteContent() throws IOException { BufferedWriter writer = mock(BufferedWriter.class); File content = mock(File.class); ContentConverter contentConverter = mock(ContentConverter.class); given(reader.readLine()) .willReturn("LINE1") .willReturn("LINE2") .willReturn(null); ioFactory.writeContent(writer, content, contentConverter); verify(contentConverter, times(2)).convert(anyString()); verify(writer, times(2)).write(anyString()); verify(writer, times(2)).newLine(); verify(reader).close(); verify(writer, never()).flush(); verify(writer, never()).close(); }