### Question:
AuditHandlerInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { String uri = request.getRequestURI(); String requestURI = sanitized ? logSanitizer.sanitize(uri) : uri; MDC.put("operation", request.getMethod() + " " + requestURI); String correlationId = request.getHeader(RequestHeaders.CORRELATION_ID); if (correlationId != null) { MDC.put("correlationId", correlationId); } String bankCode = request.getHeader(RequestHeaders.X_GTW_BANK_CODE); if (bankCode != null) { MDC.put("bankCode", bankCode); } String aspspId = request.getHeader(RequestHeaders.X_GTW_ASPSP_ID); if (aspspId != null) { MDC.put("aspspId", aspspId); } return true; } AuditHandlerInterceptor();  AuditHandlerInterceptor(boolean sanitized); @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler); @Override void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex);  }### Answer:
@Test void preHandleSanitized() { AuditHandlerInterceptor interceptor = new AuditHandlerInterceptor(true); HttpServletResponse response = mock(HttpServletResponse.class); doReturn(URI).when(request).getRequestURI(); doReturn(METHOD).when(request).getMethod(); interceptor.preHandle(request, response, new Object()); assertThat(MDC.get(OPERATION)).isEqualTo(METHOD + " /v1/accountstransactions"); }
@Test void preHandleNotSanitized() { HttpServletResponse response = mock(HttpServletResponse.class); doReturn(URI).when(request).getRequestURI(); doReturn(METHOD).when(request).getMethod(); interceptor.preHandle(request, response, new Object()); assertThat(MDC.get(OPERATION)).isEqualTo(METHOD + " " + URI); }
@Test void preHandle() { String uri = "/request/uri"; String method = "GET"; String correlationId = "correlation-id"; String bankCode = "bank-code"; String aspsId = "aspsp-id"; doReturn(uri).when(request).getRequestURI(); doReturn(method).when(request).getMethod(); doReturn(correlationId).when(request).getHeader(RequestHeaders.CORRELATION_ID); doReturn(bankCode).when(request).getHeader(RequestHeaders.X_GTW_BANK_CODE); doReturn(aspsId).when(request).getHeader(RequestHeaders.X_GTW_ASPSP_ID); boolean preHandle = interceptor.preHandle(request, null, null); assertThat(preHandle).isTrue(); assertThat(MDC.get("operation")).isEqualTo(method + " " + uri); assertThat(MDC.get("correlationId")).isEqualTo(correlationId); assertThat(MDC.get("bankCode")).isEqualTo(bankCode); assertThat(MDC.get("aspspId")).isEqualTo(aspsId); }