### Question:
DefensiveThreadFactory implements ThreadFactory { @Override public Thread newThread(final Runnable runnable) { Runnable wrapped = new Runnable() { @Override public void run() { try { runnable.run(); } catch (Exception e) { log.error("Error while executing " + Thread.currentThread().getName(), e); } } }; Thread thread = factory.newThread(wrapped); thread.setName(prefix + "-" + thread.getName()); return thread; } DefensiveThreadFactory(String name, Mojo mojo); @Override Thread newThread(final Runnable runnable);  }### Answer:
@Test public void testOnOkThread() { Thread thread = factory.newThread(new Runnable() { @Override public void run() { } }); thread.run(); assertThat(log.error).isNull(); }
@Test public void testOnBadThread() { Thread thread = factory.newThread(new Runnable() { @Override public void run() { throw new NullPointerException(); } }); thread.run(); assertThat(log.error).isNotNull(); assertThat(log.throwable).isExactlyInstanceOf(NullPointerException.class); }