@Test
public void testExceptionIsNotUncaught() {
final Logger logger = mock(Logger.class);
final Periodical periodical1 = new Periodical() {
@Override
public boolean runsForever() {
return false;
}
@Override
public boolean stopOnGracefulShutdown() {
return false;
}
@Override
public boolean masterOnly() {
return false;
}
@Override
public boolean startOnThisNode() {
return true;
}
@Override
public boolean isDaemon() {
return false;
}
@Override
public int getInitialDelaySeconds() {
return 0;
}
@Override
public int getPeriodSeconds() {
return 1;
}
@Override
protected Logger getLogger() {
return logger;
}
@Override
public void doRun() {
throw new NullPointerException();
}
};
try {
periodical1.run();
// the uncaught exception from doRun should have been logged
verify(logger, atLeastOnce()).error(anyString(), any(Throwable.class));
} catch (Exception e) {
fail("run() should never propagate an unchecked exception!", e);
}