### Question:
GroupsServiceImpl extends BaseApiService<CloudIdentity> implements GroupsService { @Override public Iterable<Group> listGroups(String groupNamespace) throws IOException { return new SearchGroupsIterable(groupNamespace); } private  GroupsServiceImpl(Builder builder); @Override ListenableFuture<Operation> createGroup(Group group); @Override ListenableFuture<Group> getGroup(String groupId); @Override ListenableFuture<Operation> deleteGroup(String groupId); @Override ListenableFuture<Operation> createMembership(String groupId, Membership member); @Override ListenableFuture<Membership> getMembership(String memberId); @Override ListenableFuture<Operation> deleteMembership(String memberId); @Override Iterable<Group> listGroups(String groupNamespace); @Override Iterable<Membership> listMembers(String groupId); static GroupsServiceImpl fromConfiguration(CredentialFactory credentialFactory);  }### Answer:
@Test public void testListGroups() throws Exception { String namespace = "ns"; String query = "parent == 'ns' && 'system/groups/external' in labels"; Groups.Search search1 = mock(Groups.Search.class); Group group1 = new Group().setName("groups/g1"); SearchGroupsResponse page1 = new SearchGroupsResponse() .setGroups(Collections.singletonList(group1)) .setNextPageToken("nextToken"); when(search1.execute()).thenReturn(page1); Groups.Search search2 = mock(Groups.Search.class); Group group2 = new Group().setName("groups/g2"); SearchGroupsResponse page2 = new SearchGroupsResponse() .setGroups(Collections.singletonList(group2)) .setNextPageToken(null); when(search2.execute()).thenReturn(page2); when(groups.search()).thenReturn(search1, search2); ImmutableList<Group> expected = ImmutableList.of(group1, group2); assertTrue(Iterables.elementsEqual(expected, groupsService.listGroups(namespace))); verify(search1).setQuery(query); verify(search1).setPageToken(null); verify(search2).setQuery(query); verify(search2).setPageToken("nextToken"); }