### Question:
GetUserPreferredWidgetsByModule { @RequestMapping(value = "/preferred/{moduleName}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public PreferredWidgetsDto getPreferredWidgets(@PathVariable("moduleName") String moduleName, Authentication authentication, HttpSession session) throws AcmWidgetException, AcmObjectNotFoundException { String userId = authentication.getName(); log.info("Finding widgets for user based on the user preference for user: [{}]", userId); PreferredWidgetsDto result; try { result = userPreferenceService.getPreferredWidgetsByUserAndModule(userId, moduleName); } catch (AcmObjectNotFoundException e) { throw e; } return result; }  @RequestMapping(value = "/preferred/{moduleName}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody PreferredWidgetsDto getPreferredWidgets(@PathVariable("moduleName") String moduleName, Authentication authentication,
            HttpSession session); UserPreferenceService getUserPreferenceService(); void setUserPreferenceService(UserPreferenceService userPreferenceService);  }### Answer:
@Test public void getPreferredWidgets() throws Exception { String userId = "marjan"; String moduleName = "moduleName"; List<String> widgetList = new ArrayList<>(); widgetList.add("newWidget"); PreferredWidgetsDto preferredWidgetsDto = new PreferredWidgetsDto(); preferredWidgetsDto.setPreferredWidgets(widgetList); preferredWidgetsDto.setModuleName(moduleName); expect(mockUserPreferenceService.getPreferredWidgetsByUserAndModule(userId, moduleName)).andReturn(preferredWidgetsDto); expect(mockAuthentication.getName()).andReturn("marjan").atLeastOnce(); replayAll(); MvcResult result = mockMvc.perform( get("/api/v1/plugin/dashboard/widgets/preferred/moduleName") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .session(mockHttpSession) .principal(mockAuthentication)) .andReturn(); verifyAll(); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertTrue(result.getResponse().getContentType().startsWith(MediaType.APPLICATION_JSON_VALUE)); String json = result.getResponse().getContentAsString(); log.info("results: " + json); PreferredWidgetsDto fromJson = new ObjectMapper().readValue(json, PreferredWidgetsDto.class); assertNotNull(fromJson); assertEquals(preferredWidgetsDto.getModuleName(), fromJson.getModuleName()); assertEquals(preferredWidgetsDto.getPreferredWidgets().get(0), fromJson.getPreferredWidgets().get(0)); }