### Question:
DeletePathsListener extends AbstractFunction1<SparkListenerJobEnd, Unit> { @Override public Unit apply(@Nonnull final SparkListenerJobEnd jobEnd) { if (!closed && jobEnd.jobResult() instanceof JobSucceeded$ && flag.value() == Boolean.TRUE) { closed = true; if (loader != null) { loader.runWithThreadContext(new Runnable() { @Override public void run() { deletePaths(); } }); } else { deletePaths(); } } return null; } DeletePathsListener(@Nonnull final List<String> paths, @Nonnull final Accumulable<Boolean, ?> flag, @Nonnull final Configuration conf); @Override Unit apply(@Nonnull final SparkListenerJobEnd jobEnd);  }### Answer:
@Test public void testFlag() { final SparkListenerJobEnd event = new SparkListenerJobEnd(1, 0, JobSucceeded$.MODULE$); apply(false, event); Assert.assertTrue("Expected file to exist", tempFile.exists()); }
@Test public void testJobFailed() { final SparkListenerJobEnd event = new SparkListenerJobEnd(1, 0, JobFailed$.MODULE$.apply(new RuntimeException())); apply(true, event); Assert.assertTrue("Expected file to exist", tempFile.exists()); }
@Test public void testJobSucceeded() throws IOException { final SparkListenerJobEnd event = new SparkListenerJobEnd(1, 0, JobSucceeded$.MODULE$); final DeletePathsListener function = apply(true, event); Assert.assertFalse("Expected file to be deleted", tempFile.exists()); setUp(); function.apply(event); Assert.assertTrue("Expected file to exist", tempFile.exists()); }