SpanCustomizingHandlerInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) { Object span = request.getAttribute(SpanCustomizer.class.getName()); if (span instanceof SpanCustomizer) { setHttpRouteAttribute(request); handlerParser.preHandle(request, o, (SpanCustomizer) span); } return true; } SpanCustomizingHandlerInterceptor(); @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o); @Override void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
    ModelAndView modelAndView); @Override void afterCompletion(HttpServletRequest request, HttpServletResponse response,
    Object handler, Exception ex);  }
@Test public void preHandle_parsesAndAddsHttpRouteAttribute() { when(request.getAttribute("brave.SpanCustomizer")).thenReturn(span); when(request.getAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE)).thenReturn("/items/{itemId}"); interceptor.preHandle(request, response, controller); verify(request).getAttribute("brave.SpanCustomizer"); verify(request).getAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE); verify(request).setAttribute("http.route", "/items/{itemId}"); verify(parser).preHandle(request, controller, span); verifyNoMoreInteractions(request, response, parser, span); }
@Test public void preHandle_parsesAndAddsHttpRouteAttribute_coercesNullToEmpty() { when(request.getAttribute("brave.SpanCustomizer")).thenReturn(span); interceptor.preHandle(request, response, controller); verify(request).getAttribute("brave.SpanCustomizer"); verify(request).getAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE); verify(request).setAttribute("http.route", ""); verify(parser).preHandle(request, controller, span); verifyNoMoreInteractions(request, response, parser, span); }
@Test public void preHandle_nothingWhenNoSpanAttribute() { interceptor.preHandle(request, response, controller); verify(request).getAttribute("brave.SpanCustomizer"); verifyNoMoreInteractions(request, request, parser, span); }