### Question:
LogTrackerCallable implements Callable<T> { @Override public T call() throws Exception { try { LogTrackerUtil.setContext(context); return doCall(); } catch (LogTrackerException e) { Logger.warn("Context transfer failed", e); } catch (Exception e) { Logger.warn("Callable exception occurred", e); } finally { LogTrackerUtil.clearContext(); } return null; } LogTrackerCallable(); @Override T call();  }### Answer:
@Test public void should_call_the_method() throws Exception { PowerMockito.when(logTrackerCallable,"doCall").thenReturn("123"); doCallRealMethod().when(logTrackerCallable).call(); String returnVal = logTrackerCallable.call(); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); LogTrackerUtil.setContext(any(Http.Context.class)); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); LogTrackerUtil.clearContext(); Assert.assertEquals(returnVal, "123"); }
@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(logTrackerCallable).call(); String returnVal = logTrackerCallable.call(); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Logger.warn(anyString(), any(LogTrackerException.class)); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); LogTrackerUtil.clearContext(); Assert.assertNull(returnVal); }
@Test public void should_throw_exception_when_error_occurs_calling_doCall() throws Exception { PowerMockito.when(logTrackerCallable,"doCall").thenThrow(Exception.class); doCallRealMethod().when(logTrackerCallable).call(); String returnVal = logTrackerCallable.call(); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); Logger.warn(anyString(), any(Exception.class)); PowerMockito.verifyStatic(VerificationModeFactory.times(1)); LogTrackerUtil.clearContext(); Assert.assertNull(returnVal); }