### Question:
PortalPreferenceController { @RequestMapping(value = {"/admin/preferences", "/admin/preferences/"}, method = RequestMethod.GET) public String viewPreferences(@RequestParam(required = false) final String action, @RequestParam(required = false) String referringPageId,Model model) { model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId); addNavigationMenusToModel(SELECTED_ITEM, model, referringPageId); final Map<String, PortalPreference> preferenceMap = preferenceService.getPreferencesAsMap(); model.addAttribute("preferenceMap", preferenceMap); if (isDeleteOrUpdate(action)) { model.addAttribute("actionresult", action); } return ViewNames.ADMIN_PREFERENCES; }  @RequestMapping(value = {"/admin/preferences", "/admin/preferences/"}, method = RequestMethod.GET) String viewPreferences(@RequestParam(required = false) final String action,
                                  @RequestParam(required = false) String referringPageId,Model model); @RequestMapping(value = "/admin/preferencedetail/edit", method = RequestMethod.GET) String editPreferences(Model model, @RequestParam(required = false) String referringPageId); @RequestMapping(value = "/admin/preferencedetail/update", method = RequestMethod.POST) String updatePreferences(@ModelAttribute("preferenceForm") PortalPreferenceForm form, BindingResult result,
                                    @ModelAttribute(ModelKeys.TOKENCHECK) String sessionToken,
                                    @RequestParam String token,
                                    @RequestParam(required = false) String referringPageId,
                                    ModelMap modelMap,
                                    SessionStatus status); void setPreferenceService(PortalPreferenceService preferenceService);  }### Answer:
@Test public void testViewPreferences() { Model model = new ExtendedModelMap(); Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); expect(service.getPreferencesAsMap()).andReturn(preferenceMap); replay(service); String view = controller.viewPreferences(null,REFERRER_ID, model); assertEquals(ViewNames.ADMIN_PREFERENCES, view); assertEquals(preferenceMap, model.asMap().get("preferenceMap")); assertFalse(model.containsAttribute("actionresult")); assertTrue(model.containsAttribute("topnav")); assertTrue(model.containsAttribute("tabs")); assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID))); verify(service); }
@Test public void testViewPreferences_afterUpdate() { Model model = new ExtendedModelMap(); Map<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>(); expect(service.getPreferencesAsMap()).andReturn(preferenceMap); replay(service); final String action = "update"; String view = controller.viewPreferences(action,REFERRER_ID, model); assertEquals(ViewNames.ADMIN_PREFERENCES, view); assertEquals(preferenceMap, model.asMap().get("preferenceMap")); assertEquals(action, model.asMap().get("actionresult")); assertTrue(model.containsAttribute("topnav")); assertTrue(model.containsAttribute("tabs")); assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID))); verify(service); }