Tracer { public static boolean isTracingEnabled() { ApplicationContext context = ApplicationContext.getCurrent(); if (context == null) { throw new IllegalStateException("ApplicationContext is not initialized yet. "); } return Boolean.parseBoolean(context.getQueryParameters().getFirst("tracing")); }  static boolean isTracingEnabled(); static void trace(String message); static void trace(String format, Object... args); static void addTraceHeaders(GenericContainerResponse response);  }
@Test public void tracingIsDisabledByDefault() throws Exception { when(applicationContext.getQueryParameters()).thenReturn(new MultivaluedHashMap<>()); assertFalse(Tracer.isTracingEnabled()); }
@Test public void enablesTracingByQueryParameter() throws Exception { enableTracing(); assertTrue(Tracer.isTracingEnabled()); }
@Test public void throwsExceptionWhenThreadLocalApplicationContextIsNotSet() throws Exception { ApplicationContext.setCurrent(null); thrown.expect(IllegalStateException.class); Tracer.isTracingEnabled(); }