ContactAccessor { public ContactGroupIds getGroupContactIds(ContentResolver resolver, ContactGroup group) { if (group.isEveryBody()) return null; final ContactGroupIds contactIds = new ContactGroupIds(); Cursor c = resolver.query( Data.CONTENT_URI, new String[]{ GroupMembership.CONTACT_ID, GroupMembership.RAW_CONTACT_ID, GroupMembership.GROUP_ROW_ID }, GroupMembership.GROUP_ROW_ID + " = ? AND " + GroupMembership.MIMETYPE + " = ?", new String[]{String.valueOf(group._id), GroupMembership.CONTENT_ITEM_TYPE}, null); while (c != null && c.moveToNext()) { contactIds.add(c.getLong(0), c.getLong(1)); } if (c != null) c.close(); return contactIds; }  Map<Integer, Group> getGroups(ContentResolver resolver, Resources resources); ContactGroupIds getGroupContactIds(ContentResolver resolver, ContactGroup group);  }
@Test public void shouldGetGroupContactIdsEmpty() throws Exception { ContactGroupIds ids = accessor.getGroupContactIds(resolver, new ContactGroup(1)); assertThat(ids.isEmpty()).isTrue(); verify(resolver).query( eq(ContactsContract.Data.CONTENT_URI), eq(new String[]{ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID, ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID, ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID}), eq(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " = ? AND " + ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + " = ?"), eq(new String[]{String.valueOf(1), ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE}), any(String.class) ); }
@Test public void shouldGetGroupContactIdsFromResolver() throws Exception { MatrixCursor cursor = new MatrixCursor( new String[] { ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID, ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID, ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID }); cursor.addRow(new Object[] { 123L, 256L, 789L }); when(resolver.query( eq(ContactsContract.Data.CONTENT_URI), any(String[].class), any(String.class), any(String[].class), any(String.class)) ).thenReturn(cursor); ContactGroupIds ids = accessor.getGroupContactIds(resolver, new ContactGroup(1)); assertThat(ids.getIds().contains(123L)); assertThat(ids.getRawIds().contains(256L)); }