### Question:
AzureUserFetcher { @SuppressWarnings("checkstyle:linelength") public Collection<AadUser> fetchAzureUsers(String accessToken) throws AzureUserFetchException { Collection<AadUser> azureUsers = new ArrayList<>(); for (AzureGroup azureGroup : this.azureAdProperties.getAzureGroups()) { String uri = "https: + azureGroup.getId() + "/members?$select=id,givenName,surname,mail,mailNickname,jobTitle,department&$top=1"; AzureGroupResponse response; do { response = fetchAzureUsersForGroupId(accessToken, uri); azureUsers.addAll(response.getUsers()); uri = response.getOdataNextLink(); } while (uri != null); } return azureUsers; } @Autowired  AzureUserFetcher(AzureApiCaller azureApiCaller, AzureAdProperties azureAdProperties); @SuppressWarnings("checkstyle:linelength") // Deactivated to not cut URL String Collection<AadUser> fetchAzureUsers(String accessToken);  }### Answer:
@Test public void fetchAzureUsers_workingThroughTwoPages() throws IOException, AzureUserFetchException { when(azureAdProperties.getAzureGroups()) .thenReturn( new ArrayList<>( Collections.singletonList( AzureGroup.builder().name("group1").id("groupId").build()))); when(azureApiCaller.callApi(anyString(), any())) .thenReturn( new ByteArrayInputStream( "{\"@odata.context\":\"https: .getBytes())) .thenReturn( new ByteArrayInputStream( "{\"@odata.context\":\"https: .getBytes())); Collection<AadUser> aadUsers = azureUserFetcher.fetchAzureUsers("token"); assertEquals(aadUsers.size(), 2); }
@Test public void fetchAzureUsers_workingThroughOnePage() throws IOException, AzureUserFetchException { when(azureAdProperties.getAzureGroups()) .thenReturn( new ArrayList<>( Collections.singletonList( AzureGroup.builder().name("group1").id("groupId").build()))); when(azureApiCaller.callApi(anyString(), any())) .thenReturn( new ByteArrayInputStream( "{\"@odata.context\":\"https: .getBytes())); Collection<AadUser> aadUsers = azureUserFetcher.fetchAzureUsers("token"); assertEquals(aadUsers.size(), 1); }
@Test public void fetchAzureUsers_returnEmptyListForNoResponse() throws IOException, AzureUserFetchException { when(azureAdProperties.getAzureGroups()) .thenReturn( new ArrayList<>( Collections.singletonList( AzureGroup.builder().name("group1").id("groupId").build()))); when(azureApiCaller.callApi(anyString(), any())) .thenReturn( new ByteArrayInputStream( "{\"@odata.context\":\"https: Collection<AadUser> aadUsers = azureUserFetcher.fetchAzureUsers("token"); assertEquals(aadUsers.size(), 0); }