### Question:
RadiologyDashboardOrdersTabController { @RequestMapping(method = RequestMethod.GET) protected ModelAndView getRadiologyOrdersTab(HttpServletRequest request, @RequestParam(required = false) String switchTab) { final ModelAndView modelAndView = new ModelAndView(RADIOLOGY_ORDERS_TAB_VIEW); String tabLink = (String) request.getSession() .getAttribute(RadiologyWebConstants.RADIOLOGY_DASHBOARD_TAB_SESSION_ATTRIBUTE); if (StringUtils.isBlank(tabLink) || StringUtils.isNotBlank(switchTab)) { request.getSession() .setAttribute(RadiologyWebConstants.RADIOLOGY_DASHBOARD_TAB_SESSION_ATTRIBUTE, RADIOLOGY_ORDERS_TAB_REQUEST_MAPPING); } else { if (!RADIOLOGY_ORDERS_TAB_REQUEST_MAPPING.equals(tabLink)) { modelAndView.setViewName("redirect:" + tabLink); } } return modelAndView; }   static final String RADIOLOGY_ORDERS_TAB_REQUEST_MAPPING; }### Answer:
@Test public void shouldReturnModelAndViewOfTheRadiologyOrdersTabPageAndSetTabSessionAttributeToRadiologyOrdersTabPageIfNotAlreadySet() throws Exception { MockHttpServletRequest mockRequest = new MockHttpServletRequest(); MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); ModelAndView modelAndView = radiologyDashboardOrdersTabController.getRadiologyOrdersTab(mockRequest, null); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is(RadiologyDashboardOrdersTabController.RADIOLOGY_ORDERS_TAB_VIEW)); assertThat((String) mockSession.getAttribute(RadiologyWebConstants.RADIOLOGY_DASHBOARD_TAB_SESSION_ATTRIBUTE), is(RadiologyDashboardOrdersTabController.RADIOLOGY_ORDERS_TAB_REQUEST_MAPPING)); }
@Test public void shouldRedirectToDashboardTabPageGivenFromTabSessionAttributeIfSwitchTabIsNotSet() throws Exception { MockHttpServletRequest mockRequest = new MockHttpServletRequest(); MockHttpSession mockSession = new MockHttpSession(); mockSession.setAttribute(RadiologyWebConstants.RADIOLOGY_DASHBOARD_TAB_SESSION_ATTRIBUTE, RadiologyDashboardReportsTabController.RADIOLOGY_REPORTS_TAB_REQUEST_MAPPING); mockRequest.setSession(mockSession); ModelAndView modelAndView = radiologyDashboardOrdersTabController.getRadiologyOrdersTab(mockRequest, null); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is("redirect:" + RadiologyDashboardReportsTabController.RADIOLOGY_REPORTS_TAB_REQUEST_MAPPING)); assertThat((String) mockSession.getAttribute(RadiologyWebConstants.RADIOLOGY_DASHBOARD_TAB_SESSION_ATTRIBUTE), is(RadiologyDashboardReportsTabController.RADIOLOGY_REPORTS_TAB_REQUEST_MAPPING)); }
@Test public void shouldNotRedirectToDashboardTabPageGivenFromTabSessionAttributeAndSetTabSessionAttributeToRadiologyOrdersTabPageIfSwitchTabIsSet() throws Exception { MockHttpServletRequest mockRequest = new MockHttpServletRequest(); MockHttpSession mockSession = new MockHttpSession(); mockSession.setAttribute(RadiologyWebConstants.RADIOLOGY_DASHBOARD_TAB_SESSION_ATTRIBUTE, RadiologyDashboardReportsTabController.RADIOLOGY_REPORTS_TAB_REQUEST_MAPPING); mockRequest.setSession(mockSession); ModelAndView modelAndView = radiologyDashboardOrdersTabController.getRadiologyOrdersTab(mockRequest, "true"); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is(RadiologyDashboardOrdersTabController.RADIOLOGY_ORDERS_TAB_VIEW)); assertThat((String) mockSession.getAttribute(RadiologyWebConstants.RADIOLOGY_DASHBOARD_TAB_SESSION_ATTRIBUTE), is(RadiologyDashboardOrdersTabController.RADIOLOGY_ORDERS_TAB_REQUEST_MAPPING)); }