WidgetController { @SuppressWarnings("unchecked") @RequestMapping(method = GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<PagedResources<WidgetConfigResource>> getWidgets( @PathVariable String slug, @PageableDefault Pageable pageable, PagedResourcesAssembler pagedResourcesAssembler) { Dashboard dashboard = dashboardService.load(slug); Page<WidgetConfig> widgetConfigPage = widgetConfigRepository.findAllByDashboardId(dashboard.getId(), pageable); WidgetConfigResourceAssembler assembler = new WidgetConfigResourceAssembler(slug, dashboard.getId()); PagedResources<WidgetConfigResource> pagedResources = pagedResourcesAssembler.toResource(widgetConfigPage, assembler); return new ResponseEntity<>(pagedResources, OK); } @Autowired  WidgetController(
      WidgetConfigService widgetService,
      WidgetConfigRepository widgetConfigRepository,
      DashboardService dashboardService); @RequestMapping(value = "/{widgetId}", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<WidgetConfigResource> getWidget(
      @PathVariable String slug, @PathVariable String widgetId); @RequestMapping( value = "/{widgetId}", method = DELETE, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Void> deleteWidget(@PathVariable String widgetId); @RequestMapping( method = POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<WidgetConfigResource> createWidget(
      @PathVariable String slug, @RequestBody WidgetConfigResource widgetConfigResource); @RequestMapping( value = "/{widgetId}/data", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<SourceDataResource> getData(
      @PathVariable String slug, @PathVariable String widgetId); @SuppressWarnings("unchecked") @RequestMapping(method = GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<PagedResources<WidgetConfigResource>> getWidgets(
      @PathVariable String slug,
      @PageableDefault Pageable pageable,
      PagedResourcesAssembler pagedResourcesAssembler); @RequestMapping(value = "/all", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) Resources<WidgetConfigResource> getAllWidgets(@PathVariable String slug);  }
@Test public void getWidgets() throws Exception { Dashboard dashboard = dashboard(); when(dashboardService.load(any())).thenReturn(dashboard); when(widgetConfigRepository.findAllByDashboardId(any(String.class), any(Pageable.class))) .thenReturn(new PageImpl<>(widgetConfigList(), new PageRequest(0, 1), 1)); MvcResult result = mvc() .perform(get("/api/dashboards/test/widgets")) .andExpect(status().isOk()) .andExpect(containsPagedResources(WidgetConfigResource.class)) .andDo(document("widgets/list")) .andReturn(); PagedResources<WidgetConfigResource> resource = fromPagedResourceJson( result.getResponse().getContentAsString(), WidgetConfigResource.class); assertThat(resource.getContent()).hasSize(1); }