### Question:
SigningBasketLoggingInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { Map<String, String> pathVariables = pathParameterExtractor.extractParameters(request); String basketId = Optional.ofNullable(pathVariables) .map(pv -> pv.get("basketId")) .orElse(NOT_EXIST_IN_URI); TppLogger.logRequest(request) .withTpp(tppService.getTppInfo()) .withRequestUri() .withParam("Basket ID", basketId) .perform(); return true; }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler); @Override void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex);  }### Answer:
@Test void preHandle_success() { when(pathParameterExtractor.extractParameters(any(HttpServletRequest.class))).thenReturn(Collections.emptyMap()); when(request.getRemoteAddr()).thenReturn(TPP_IP); when(request.getRequestURI()).thenReturn(REQUEST_URI); interceptor.preHandle(request, response, null); verify(pathParameterExtractor).extractParameters(any(HttpServletRequest.class)); verify(tppService).getTppInfo(); verify(request).getRemoteAddr(); verify(request).getRequestURI(); }
@Test void preHandle_pathVariableIsNull() { when(pathParameterExtractor.extractParameters(any(HttpServletRequest.class))).thenReturn(null); when(tppService.getTppInfo()).thenReturn(jsonReader.getObjectFromFile(TPP_INFO_JSON, TppInfo.class)); when(request.getRemoteAddr()).thenReturn(TPP_IP); when(request.getRequestURI()).thenReturn(REQUEST_URI); interceptor.preHandle(request, response, null); verify(pathParameterExtractor).extractParameters(any(HttpServletRequest.class)); verify(tppService).getTppInfo(); verify(request).getRemoteAddr(); verify(request).getRequestURI(); }