### Question:
GraphqlClientDataSourceServlet extends SlingSafeMethodsServlet { List<Resource> getGraphqlClients(@Nonnull SlingHttpServletRequest request) { ResourceResolver resolver = request.getResourceResolver(); List<Resource> graphqlClients = new ArrayList<>(); final Config cfg = new Config(request.getResource().getChild(Config.DATASOURCE)); boolean showEmptyOption = false; if (cfg != null) { ExpressionHelper expressionHelper = new ExpressionHelper(expressionResolver, request); showEmptyOption = expressionHelper.getBoolean(cfg.get("showEmptyOption")); } if (showEmptyOption) { graphqlClients.add(new GraphqlClientResource(i18n.get("Inherit", "Inherit property"), StringUtils.EMPTY, resolver)); } for (String identifier : identifiers) { graphqlClients.add(new GraphqlClientResource(identifier, identifier, resolver)); } return graphqlClients; }   final static String RESOURCE_TYPE; }### Answer:
@Test public void testGetGraphqlClients() throws IOException, InvalidSyntaxException { I18n i18n = mock(I18n.class); Mockito.doReturn("inherit-translated").when(i18n).get(eq("Inherit"), any()); Whitebox.setInternalState(servlet, "i18n", i18n); Set<String> identifiers = new HashSet<>(); identifiers.add("my-identifier"); Whitebox.setInternalState(servlet, "identifiers", identifiers); Resource mockResource = Mockito.mock(Resource.class); Map<String, Object> datasourceProps = new HashMap<String, Object>(); datasourceProps.put("showEmptyOption", true); Resource datasourceDefinition = new MockResource("/some/random/path", datasourceProps, context.resourceResolver()); Mockito.when(mockResource.getChild(Config.DATASOURCE)).thenReturn(datasourceDefinition); Mockito.when(mockExpressionResolver.resolve(Mockito.any(String.class), Mockito.any(Locale.class), Mockito.any(Class.class), Mockito .any(SlingHttpServletRequest.class))).thenReturn(true); context.request().setResource(mockResource); List<Resource> resources = servlet.getGraphqlClients(context.request()); Assert.assertEquals(2, resources.size()); GraphqlClientDataSourceServlet.GraphqlClientResource inherit = (GraphqlClientDataSourceServlet.GraphqlClientResource) resources.get( 0); Assert.assertEquals("inherit-translated", inherit.getText()); Assert.assertEquals("", inherit.getValue()); Assert.assertFalse(inherit.getSelected()); GraphqlClientDataSourceServlet.GraphqlClientResource client = (GraphqlClientDataSourceServlet.GraphqlClientResource) resources.get( 1); Assert.assertEquals("my-identifier", client.getText()); Assert.assertEquals("my-identifier", client.getValue()); Assert.assertFalse(client.getSelected()); }
@Test public void testGetGraphqlClientsNoEmptyOption() throws IOException, InvalidSyntaxException { I18n i18n = mock(I18n.class); Mockito.doReturn("inherit-translated").when(i18n).get(eq("Inherit"), any()); Whitebox.setInternalState(servlet, "i18n", i18n); Set<String> identifiers = new HashSet<>(); identifiers.add("my-identifier"); Whitebox.setInternalState(servlet, "identifiers", identifiers); Resource mockResource = Mockito.mock(Resource.class); Map<String, Object> datasourceProps = new HashMap<String, Object>(); datasourceProps.put("showEmptyOption", false); Resource datasourceDefinition = new MockResource("/some/random/path", datasourceProps, context.resourceResolver()); Mockito.when(mockResource.getChild(Config.DATASOURCE)).thenReturn(datasourceDefinition); context.request().setResource(mockResource); List<Resource> resources = servlet.getGraphqlClients(context.request()); Assert.assertEquals(1, resources.size()); GraphqlClientDataSourceServlet.GraphqlClientResource client = (GraphqlClientDataSourceServlet.GraphqlClientResource) resources.get( 0); Assert.assertEquals("my-identifier", client.getText()); Assert.assertEquals("my-identifier", client.getValue()); Assert.assertFalse(client.getSelected()); }