WebActionControllerAdvice implements ResponseBodyAdvice<Object> { @SuppressWarnings("unchecked") @Override public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { logit.debug(()->"Processed response from "+WebActionController.class+": " + "\n"+ body); MultiExecuteOutput multiOutput = defaultInterceptor.handleResponse(body); String responseBodyHeader = request.getHeaders().getFirst(Constants.HTTP_RESPONSEBODY_INTERCEPTOR_HEADER.code); if(StringUtils.isBlank(responseBodyHeader)) return multiOutput; ResponseInterceptor<MultiExecuteOutput> interceptor = beanResolver.find(ResponseInterceptor.class, RESPONSE_INTERCEPTOR_BEAN_PREFIX+responseBodyHeader); if(interceptor == null) return multiOutput; interceptor.intercept(multiOutput); return multiOutput; }  @Override boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType); @SuppressWarnings("unchecked") @Override Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, 
			Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response); @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(Throwable.class) @ResponseBody MultiExecuteOutput exception(Throwable pEx); @ResponseStatus(value = HttpStatus.UNPROCESSABLE_ENTITY) @ExceptionHandler(MethodArgumentNotValidException.class) @ResponseBody MultiExecuteOutput exception(MethodArgumentNotValidException vEx);  }
@Test public void testBeforeBodyWrite() { final Object body = new Object(); final MethodParameter returnType = Mockito.mock(MethodParameter.class); final MediaType selectedContentType = MediaType.ALL; final Class<? extends HttpMessageConverter<?>> selectedConverterType = null; final ServerHttpRequest req = new ServletServerHttpRequest(new MockHttpServletRequest()); final ServerHttpResponse res = new ServletServerHttpResponse(new MockHttpServletResponse()); final MultiExecuteOutput expected = new MultiExecuteOutput(sessionid); Mockito.when(this.interceptor.handleResponse(body)).thenReturn(expected); final Object actual = this.testee.beforeBodyWrite(body, returnType, selectedContentType, selectedConverterType, req, res); Mockito.verify(this.interceptor, Mockito.times(1)).handleResponse(body); Assert.assertEquals(expected, actual); }