### Question:
CatalogIdentifierDatasource extends SlingSafeMethodsServlet { @Override protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException { DataSource ds; if (catalogIdentifierService == null) { ds = EmptyDataSource.instance(); } else { ds = buildValuesList(request.getResourceResolver()); } request.setAttribute(DataSource.class.getName(), ds); }    }### Answer:
@Test public void testDoGetWithData() throws ServletException, IOException { List<String> testResourceProperties = Arrays.asList("key1:value1", "key1:value2", "key2:value3", "key2:value4"); classUnderTest.doGet(mockRequest, mockResponse); DataSource result = (DataSource) mockRequest.getAttribute(DataSource.class.getName()); List<Resource> elementsInDatsource = new ArrayList<>(); result.iterator().forEachRemaining(resourceToCheck -> { elementsInDatsource.add(resourceToCheck); }); Assert.assertEquals("The datasource contains the correct number of elements", testResourceProperties.size(), elementsInDatsource .size()); }
@Test public void testDoGetWithNoProviders() throws ServletException, IOException { Mockito.when(mockCatalogIdentifierService.getCatalogIdentifiersForAllCommerceProviders()).thenReturn(new HashMap<>()); classUnderTest.doGet(mockRequest, mockResponse); DataSource result = (DataSource) mockRequest.getAttribute(DataSource.class.getName()); List<Resource> elementsInDatsource = new ArrayList<>(); result.iterator().forEachRemaining(resourceToCheck -> { elementsInDatsource.add(resourceToCheck); }); Assert.assertEquals("The datasource contains no elements", 0, elementsInDatsource.size()); }
@Test public void testDoGetWithNoAvailableService() throws ServletException, IOException { CatalogIdentifierDatasource datasourceToTest = new CatalogIdentifierDatasource(); datasourceToTest.doGet(mockRequest, mockResponse); DataSource result = (DataSource) mockRequest.getAttribute(DataSource.class.getName()); List<Resource> elementsInDatsource = new ArrayList<>(); result.iterator().forEachRemaining(resourceToCheck -> { elementsInDatsource.add(resourceToCheck); }); Assert.assertEquals("The datasource contains no elements when the CatalogIdentifierService reference is not satisfied", 0, elementsInDatsource.size()); }