@Test public void testAdapterReturnTrueWhenExceptionIsThrown() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { throw new Exception("FATAL!"); } }).when(request).getMethod(); boolean result = interceptorAdapter.preHandle(request, null, handlerMethod); Assert.assertTrue("Adapter should return true.", result); }
@Test public void testAdapterSetRequestNameCorrectly() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); when(request.getMethod()).thenReturn(HttpMethods.GET); interceptorAdapter.preHandle(request, null, handlerMethod); String requestName = ThreadContext.getRequestTelemetryContext().getHttpRequestTelemetry().getName(); String expectedRequestName = String.format("%s %s/%s", HttpMethods.GET, DEFAULT_CONTROLLER_NAME, DEFAULT_ACTION_NAME); Assert.assertEquals(expectedRequestName, requestName); }
@Test public void testAdapterReturnTrueWhenContextNull() throws Exception { ThreadContext.setRequestTelemetryContext(null); boolean result = interceptorAdapter.preHandle(null, null, handlerMethod); Assert.assertTrue("Adapter should return true.", result); } }