### Question:
CommonModelHandlerInterceptor extends HandlerInterceptorAdapter { @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (modelAndView != null) { ModelMap map = modelAndView.getModelMap(); map.addAttribute(ModelKeys.PORTAL_SETTINGS, preferenceService.getPreferencesAsMap()); map.addAttribute(ModelKeys.STATIC_CONTENT_CACHE, staticContentFetcherService); } super.postHandle(request, response, handler, modelAndView); } @Autowired  CommonModelHandlerInterceptor(PortalPreferenceService preferenceService, StaticContentFetcherService staticContentFetcherService); @Override void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView);  }### Answer:
@SuppressWarnings("unchecked") @Test public void testPostHandle() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); Object handler = null; ModelAndView modelAndView = new ModelAndView(); Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); expect(portalPreferenceService.getPreferencesAsMap()).andReturn(preferenceMap); replay(portalPreferenceService); interceptor.postHandle(request, response, handler, modelAndView); verify(portalPreferenceService); Map<String, Object> modelMap = modelAndView.getModelMap(); assertThat((Map<String, PortalPreference>) modelMap.get(ModelKeys.PORTAL_SETTINGS), sameInstance(preferenceMap)); assertThat((StaticContentFetcherService) modelMap.get(ModelKeys.STATIC_CONTENT_CACHE), sameInstance(staticContentFetcherService)); }
@Test public void testPostHandle_noModelAndView() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); Object handler = null; ModelAndView modelAndView = null; interceptor.postHandle(request, response, handler, modelAndView); assertThat(modelAndView, is(nullValue(ModelAndView.class))); }