CustomThreadFactory implements ThreadFactory, UncaughtExceptionHandler { public void uncaughtException(Thread thread, Throwable throwable) { logger.error("Uncaught Exception in thread "+ thread.getName(), throwable); } CustomThreadFactory(String threadName, boolean daemon); Thread newThread(Runnable r); void uncaughtException(Thread thread, Throwable throwable);  }
@Test public void testUncaughtException() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InterruptedException{ CustomThreadFactory testClass = new CustomThreadFactory("test", false); Logger mockLogger = TestUtils.mockLogger(testClass.getClass()); makeThreadSafe(mockLogger, true); ExecutorService executor = Executors.newSingleThreadExecutor(testClass); mockLogger.error((String)anyObject(), (Throwable)anyObject()); expectLastCall().once(); replay(mockLogger); executor.execute(new MockThread()); for (int i=0; i < 5; i++) { signalled = true; Thread.sleep(400); } verify(mockLogger); }