### Question:
TempFileGenerator implements FileGenerator { @Override public void close() { for (File tempFile : createdFiles) { try { tempFile.delete(); } catch (Exception e) { System.out.println("A file could not be deleted."); } } } TempFileGenerator(); @Override File getTemporaryFile(); @Override void close();  }### Answer:
@Test public void testClose() throws IOException, FileCreationException { TempFileGenerator tempFileGenerator = new TempFileGenerator(); File actualFile1 = tempFileGenerator.getTemporaryFile(); File actualFile2 = tempFileGenerator.getTemporaryFile(); tempFileGenerator.close(); assertFalse(actualFile1.exists()); assertFalse(actualFile2.exists()); }
@Test public void testCloseWithException() throws UnsupportedEncodingException { File file1 = mock(File.class); File file2 = mock(File.class); File file3 = mock(File.class); TempFileGenerator tempFileGenerator = new TempFileGenerator(); tempFileGenerator.createdFiles.add(file1); tempFileGenerator.createdFiles.add(file2); tempFileGenerator.createdFiles.add(file3); doThrow(new RuntimeException()).when(file2).delete(); tempFileGenerator.close(); assertFalse(file1.exists()); assertFalse(file3.exists()); }