### Question:
ScheduledTaskExecutorServiceImpl implements ScheduledTaskExecutorService, InitializingBean, DisposableBean { @Override public void scheduleTaskForExecution(@Nonnull final Runnable runnable, @Nonnull final int delay, @Nonnull final TimeUnit timeUnit, @Nonnull final boolean runInPersistenceContext) { Assert.notNull(runnable, "Runnable task should not be null"); Assert.isTrue(delay > 0, "Delay should be positive integer"); Assert.notNull(timeUnit, "Time unit should not be null"); LOGGER.debug("Scheduling task for execution after - {} , time units - {}, run in persistence context - {}", delay, timeUnit, runInPersistenceContext); scheduledExecutorService.schedule(new ScheduledTaskExecutorDecorator(runnable, runInPersistenceContext), delay, timeUnit); } ScheduledTaskExecutorServiceImpl(); @Override void afterPropertiesSet(); @Override void destroy(); @Override void scheduleTaskForExecution(@Nonnull final Runnable runnable, @Nonnull final int delay, @Nonnull final TimeUnit timeUnit, @Nonnull final boolean runInPersistenceContext); PersistenceUtilityService getPersistenceUtilityService(); void setPersistenceUtilityService(final PersistenceUtilityService persistenceUtilityService); ScheduledExecutorService getScheduledExecutorService(); void setScheduledExecutorService(final ScheduledExecutorService scheduledExecutorService);  }### Answer:
@Test public void testScheduleTaskForExecutionWithInvalidArguments() { final Runnable runnable = () -> { }; final int delay = 10; final TimeUnit timeUnit = TimeUnit.MILLISECONDS; final boolean runInPersistenceContext = false; resetAll(); replayAll(); try { scheduledTaskExecutorService.scheduleTaskForExecution(null, delay, timeUnit, runInPersistenceContext); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } try { scheduledTaskExecutorService.scheduleTaskForExecution(runnable, -1, timeUnit, runInPersistenceContext); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } try { scheduledTaskExecutorService.scheduleTaskForExecution(runnable, delay, null, runInPersistenceContext); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } verifyAll(); }
@Test public void testScheduleTaskForExecutionWithPersistenceContext() { final MutableHolder<Boolean> booleanMutableHolder = new MutableHolder<>(Boolean.FALSE); final Runnable runnable = () -> { booleanMutableHolder.setValue(Boolean.TRUE); }; final int delay = 10; final TimeUnit timeUnit = TimeUnit.MILLISECONDS; final boolean runInPersistenceContext = true; resetAll(); persistenceUtilityService.runInPersistenceSession(eq(runnable)); expectLastCall().andAnswer(() -> { final Runnable taskToExecute = (Runnable) getCurrentArguments()[0]; taskToExecute.run(); return null; }).once(); expect(scheduledExecutorService.schedule(isA(Runnable.class), eq(Long.valueOf(delay).longValue()), eq(timeUnit))).andAnswer(() -> { final Runnable taskToExecute = (Runnable) getCurrentArguments()[0]; taskToExecute.run(); return null; }).once(); replayAll(); scheduledTaskExecutorService.scheduleTaskForExecution(runnable, delay, timeUnit, runInPersistenceContext); assertTrue(booleanMutableHolder.getValue().booleanValue()); verifyAll(); }
@Test public void testScheduleTaskForExecutionWithoutPersistenceContext() { final MutableHolder<Boolean> booleanMutableHolder = new MutableHolder<>(Boolean.FALSE); final Runnable runnable = () -> { booleanMutableHolder.setValue(Boolean.TRUE); }; final int delay = 10; final TimeUnit timeUnit = TimeUnit.MILLISECONDS; final boolean runInPersistenceContext = false; resetAll(); expect(scheduledExecutorService.schedule(isA(Runnable.class), eq(Long.valueOf(delay).longValue()), eq(timeUnit))).andAnswer(() -> { final Runnable taskToExecute = (Runnable) getCurrentArguments()[0]; taskToExecute.run(); return null; }).once(); replayAll(); scheduledTaskExecutorService.scheduleTaskForExecution(runnable, delay, timeUnit, runInPersistenceContext); assertTrue(booleanMutableHolder.getValue().booleanValue()); verifyAll(); }