### Question:
FileResultWriter implements ResultListener<T>, Closeable { @Override public void receiveResult(T result) { out.println(result); out.flush(); } FileResultWriter(File file); @Override void close(); @Override void receiveResult(T result);  }### Answer:
@Test public void test() throws IOException { File file = folder.newFile(); try (FileResultWriter<String> resultWriter = new FileResultWriter<>(file)) { resultWriter.receiveResult("foo"); resultWriter.receiveResult("bar"); } try (BufferedReader in = new BufferedReader(new FileReader(file))) { assertThat(in.readLine()).isEqualTo("foo"); assertThat(in.readLine()).isEqualTo("bar"); } }
@Test public void testWriteNull() throws IOException { File file = folder.newFile(); try (FileResultWriter<String> resultWriter = new FileResultWriter<>(file)) { resultWriter.receiveResult(null); } try (BufferedReader in = new BufferedReader(new FileReader(file))) { assertThat(in.readLine()).isEqualTo(Objects.toString(null)); } }