### Question:
EmailAddressResolversImpl implements EmailAddressResolvers { @Override public DataFetcher<List<EmailAddress>> getEmailAddressesDataFetcher() { return environment -> { int start = util.getIntArg(environment, "start", 0); int end = util.getIntArg(environment, "end", 10); return emailaddressLocalService.getEmailAddresses(start, end); }; }  @Reference(unbind = "-") void setEmailAddressLocalService(EmailAddressLocalService emailaddressLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<EmailAddress>> getEmailAddressesDataFetcher(); @Override DataFetcher<List<EmailAddress>> getEmailAddressesForEntityDataFetcher(); @Override DataFetcher<CompletableFuture<EmailAddress>> getEmailAddressDataFetcher(); @Override DataFetcher<EmailAddress> createEmailAddressDataFetcher(); @Override DataFetcher<EmailAddress> updateEmailAddressDataFetcher(); @Override DataFetcher<EmailAddress> deleteEmailAddressDataFetcher();  }### Answer:
@Test public void getEmailAddressesDataFetcher_should_return_the_specified_number_of_objects() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("start", 3); arguments.put("end", 3); DataFetchingEnvironment environment = getTestEnvironment(arguments); List<EmailAddress> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { EmailAddress entity = mock(EmailAddress.class); entity.setEmailAddressId(value); availableObjects.add(entity); }); List<EmailAddress> expectedResults = availableObjects.stream() .skip(3) .limit(3) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getEmailAddresses(3, 3)) .thenReturn(expectedResults); List<EmailAddress> results = resolvers.getEmailAddressesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getEmailAddressesDataFetcher_without_args_should_return_10_first_objects() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); List<EmailAddress> availableObjects = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { EmailAddress entity = mock(EmailAddress.class); entity.setEmailAddressId(value); availableObjects.add(entity); }); List<EmailAddress> expectedResults = availableObjects.stream() .skip(0) .limit(10) .collect(Collectors.toList()); useSimpleGraphQLUtil(); when(localService.getEmailAddresses(0, 10)) .thenReturn(expectedResults); List<EmailAddress> results = resolvers.getEmailAddressesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getEmailAddressesDataFetcher_with_big_range_args_should_return_only_available_objects() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("start", 0); arguments.put("end", 100); DataFetchingEnvironment environment = getTestEnvironment(arguments); List<EmailAddress> expectedResults = new ArrayList<>(); IntStream.rangeClosed(1, 20) .forEach(value -> { EmailAddress entity = mock(EmailAddress.class); entity.setEmailAddressId(value); expectedResults.add(entity); }); useSimpleGraphQLUtil(); when(localService.getEmailAddresses(0, 100)) .thenReturn(expectedResults); List<EmailAddress> results = resolvers.getEmailAddressesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }
@Test public void getEmailAddressesDataFetcher_no_objects_available_should_return_empty_list() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("start", 0); arguments.put("end", 100); DataFetchingEnvironment environment = getTestEnvironment(arguments); List<EmailAddress> expectedResults = new ArrayList<>(); useSimpleGraphQLUtil(); when(localService.getEmailAddresses(0, 100)) .thenReturn(expectedResults); List<EmailAddress> results = resolvers.getEmailAddressesDataFetcher() .get(environment); assertNotNull(results); assertEquals(expectedResults, results); }