### Question:
LogTrackerRunnable implements Runnable { @Override public void run() { try { LogTrackerUtil.setContext(context); doRun(); } catch (LogTrackerException e) { Logger.warn("Context transfer failed", e); } catch (Exception e) { Logger.warn("Runnable exception occurred", e); } finally { LogTrackerUtil.clearContext(); } } LogTrackerRunnable(); @Override void run();  }### Answer:
@Test public void should_run_the_method() throws Exception { doCallRealMethod().when(logTrackerRunnable).run(); logTrackerRunnable.run(); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); LogTrackerUtil.setContext(any(Http.Context.class)); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); LogTrackerUtil.clearContext(); }
@Test public void should_throw_log_tracker_exception_when_error_occurs_setting_context() throws Exception { PowerMockito.when(LogTrackerUtil.class,"setContext", any(Http.Context.class)).thenThrow(LogTrackerException.class); doCallRealMethod().when(logTrackerRunnable).run(); logTrackerRunnable.run(); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Logger.warn(anyString(), any(LogTrackerException.class)); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); LogTrackerUtil.clearContext(); }
@Test public void should_throw_exception_when_error_occurs_calling_doCall() throws Exception { PowerMockito.when(logTrackerRunnable,"doRun").thenThrow(Exception.class); doCallRealMethod().when(logTrackerRunnable).run(); logTrackerRunnable.run(); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Logger.warn(anyString(), any(Exception.class)); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); LogTrackerUtil.clearContext(); }