### Question:
AdministrationController { @RequestMapping(value = "/admin/exit", method = RequestMethod.GET) public String exitAdministrationMode(HttpServletRequest request) { request.getSession().removeAttribute(ADMIN_ATTRIBUTE_NAME); return getRedirectToPrevPage(request); } @Autowired  AdministrationController(ComponentService componentService,
                                    MessageSource messageSource,
                                    BranchService branchService,
                                    PermissionManager permissionManager,
                                    GroupService groupService,
                                    SpamProtectionService spamProtectionService,
                                    UserService userService); @RequestMapping(value = "/admin/enter", method = RequestMethod.GET) String enterAdministrationMode(HttpServletRequest request); @RequestMapping(value = "/admin/exit", method = RequestMethod.GET) String exitAdministrationMode(HttpServletRequest request); @RequestMapping(value = "/admin/edit", method = RequestMethod.POST) @ResponseBody JsonResponse setForumInformation(@Valid @RequestBody ComponentInformation componentInformation,
                                            BindingResult result, Locale locale); @RequestMapping(value = "/branch/edit", method = RequestMethod.POST) @ResponseBody JsonResponse setBranchInformation(@Valid @RequestBody BranchDto branchDto,
                                            BindingResult result, Locale locale); @RequestMapping(value = "/branch/new", method = RequestMethod.POST) @ResponseBody JsonResponse createNewBranch(@Valid @RequestBody BranchDto branchDto, 
                                            BindingResult result, Locale locale); @RequestMapping(value = "/branch/permissions/{branchId}", method = RequestMethod.GET) ModelAndView showBranchPermissions(@PathVariable("branchId") long branchId); @RequestMapping(value = "/branch/permissions/json", method = RequestMethod.POST) @ResponseBody JsonResponse getGroupsForBranchPermission(@RequestBody BranchPermissionDto permissionInfo); @RequestMapping(value = "/branch/permissions/edit", method = RequestMethod.POST) @ResponseBody JsonResponse editBranchPermissions(@RequestBody BranchPermissionDto permissionInfo); @RequestMapping(value = "/group/list", method = RequestMethod.GET) ModelAndView showGroupsWithUsers(); @RequestMapping(value = "/group", method = RequestMethod.POST) @ResponseBody JsonResponse createNewGroup(@Valid @RequestBody GroupAdministrationDto groupDto, BindingResult result, Locale locale); @RequestMapping(value = "/group/{groupId}", method = RequestMethod.PUT) @ResponseBody JsonResponse editGroup(@Valid @RequestBody GroupAdministrationDto groupDto,
                                  BindingResult result,
                                  @PathVariable("groupId") Long groupId,
                                  Locale locale); @RequestMapping(value = "/group/{groupId}", method = RequestMethod.GET) ModelAndView getGroupUsers(@PathVariable("groupId") long groupId,
                                      @RequestParam(value = "page", defaultValue = "1", required = false) int page); @RequestMapping(value = "/ajax/group/{groupId}", method = RequestMethod.GET) @ResponseBody JsonResponse ajaxGetGroupUsers(@PathVariable("groupId") long groupId,
                                          @RequestParam(value = "page", defaultValue = "1", required = false) int page); @RequestMapping(value = "/group/{groupId}", method = RequestMethod.DELETE) @ResponseBody JsonResponse deleteGroup(@PathVariable("groupId") Long groupId); @RequestMapping(value = "/spamprotection", method = RequestMethod.GET) ModelAndView getSpamProtectionPage(); @RequestMapping(value = "/user", params = {"notInGroupId", "pattern"}, method = RequestMethod.GET) @ResponseBody JsonResponse findUserNotInGroup(@RequestParam("notInGroupId") long notInGroupId,
                                           @Valid @ModelAttribute SearchQueryDto searchQueryDto,
                                           BindingResult result);  }### Answer:
@Test public void exitAdminModeShouldRemoveSessionAttributeAndReturnPreviousPageRedirect() { HttpServletRequest request = mock(HttpServletRequest.class); String initialPage = "/topics/2"; when(request.getHeader("Referer")).thenReturn(initialPage); HttpSession session = new MockHttpSession(); when(request.getSession()).thenReturn(session); String resultUrl = administrationController.exitAdministrationMode(request); Object attr = session.getAttribute(AdministrationController.ADMIN_ATTRIBUTE_NAME); assertNull(attr); assertEquals(resultUrl, "redirect:" + initialPage); }