### Question:
LogTrackerUtil { public static String getTrackerId() throws LogTrackerException { Http.Context ctx; try { ctx = Http.Context.current(); } catch (RuntimeException e) { ctx = LogTrackerUtil.context.get(); } try { return ctx.args.get("TrackerId").toString(); } catch (Exception e) { throw new LogTrackerException("Error occurred when getting the context", e); } }  static String getTrackerId(); static void setContext(Http.Context ctx); static void clearContext();  }### Answer:
@Test public void should_return_tracker_id() throws Exception { context = mock(Http.Context.class); context.args = args; PowerMockito.when(Http.Context.current()).thenReturn(context); Assert.assertEquals(LogTrackerUtil.getTrackerId(), "123"); }
@Test public void should_return_context_in_thread_local() throws Exception { context = mock(Http.Context.class); context.args = args; ThreadLocal<Http.Context> tlContext = new ThreadLocal<>(); tlContext.set(context); Whitebox.setInternalState(LogTrackerUtil.class, "context", tlContext); PowerMockito.when(Http.Context.current()).thenThrow(RuntimeException.class); Assert.assertEquals(LogTrackerUtil.getTrackerId(), "123"); }
@Test(expected = LogTrackerException.class) public void should_throw_exception_when_trackerId_is_not_available() throws Exception { context = mock(Http.Context.class); context.args = null; ThreadLocal<Http.Context> tlContext = new ThreadLocal<>(); tlContext.set(context); Whitebox.setInternalState(LogTrackerUtil.class, "context", tlContext); PowerMockito.when(Http.Context.current()).thenThrow(RuntimeException.class); LogTrackerUtil.getTrackerId(); }