### Question:
RequestValidationInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { return isRequestValid(request, response, handler); }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler);  }### Answer:
@Test void preHandle_instanceOf_incorrectFormat() throws IOException { assertTrue(interceptor.preHandle(request, response, null)); verify(errorBuildingService, never()).buildFormatErrorResponse(eq(response), any(MessageError.class)); }
@Test void preHandle_methodValidator_isNotPresent() throws IOException, NoSuchMethodException { Method method = getClass().getDeclaredMethod(METHOD_NAME); when(handler.getMethod()).thenReturn(method); when(methodValidatorController.getMethod(anyString())).thenReturn(defaultMethodValidator); when(defaultMethodValidator.validate(any(), any())).thenReturn(new MessageError()); assertTrue(interceptor.preHandle(request, response, handler)); verify(errorBuildingService, never()).buildFormatErrorResponse(eq(response), any(MessageError.class)); }
@Test void preHandle_methodValidator_hasError() throws IOException, NoSuchMethodException { ArgumentCaptor<MessageError> messageErrorCaptor = ArgumentCaptor.forClass(MessageError.class); Method method = getClass().getDeclaredMethod(METHOD_NAME); when(handler.getMethod()).thenReturn(method); when(methodValidatorController.getMethod(METHOD_NAME)).thenReturn(methodValidator); assertFalse(interceptor.preHandle(request, response, handler)); verify(errorBuildingService, times(1)).buildFormatErrorResponse(eq(response), messageErrorCaptor.capture()); assertEquals(MessageErrorCode.FORMAT_ERROR, messageErrorCaptor.getValue().getTppMessage().getMessageErrorCode()); }