### Question:
XWikiGroupServiceImpl implements XWikiGroupService, EventListener { @Override public int countAllMatchedMembersNamesForGroup(String group, String filter, XWikiContext xcontext) throws XWikiException { DocumentReference groupReference = this.currentMixedDocumentReferenceResolver.resolve(group); String localGroupReference = this.localWikiEntityReferenceSerializer.serialize(groupReference); Map<String, Object> parameters = new HashMap<>(); StringBuilder statement = new StringBuilder("select count(field.value) ") .append(createMatchGroupMembersWhereClause(localGroupReference, filter, null, parameters)); try { QueryManager queryManager = xcontext.getWiki().getStore().getQueryManager(); Query query = queryManager.createQuery(statement.toString(), Query.HQL); query.setWiki(groupReference.getWikiReference().getName()); for (Map.Entry<String, Object> entry : parameters.entrySet()) { query.bindValue(entry.getKey(), entry.getValue()); } return ((Long) query.execute().get(0)).intValue(); } catch (QueryException ex) { throw new XWikiException(0, 0, ex.getMessage(), ex); } }  @Override synchronized void init(XWiki xwiki, XWikiContext context); @Override synchronized void initCache(XWikiContext context); @Override synchronized void initCache(int iCapacity, XWikiContext context); @Override void flushCache(); @Override @Deprecated Collection<String> listGroupsForUser(String member, XWikiContext context); @Override @Deprecated void addUserToGroup(String username, String database, String group, XWikiContext context); @Override void replaceMemberInAllGroups(DocumentReference memberSourceReference,
        DocumentReference memberTargetReference, XWikiContext context); @Override void removeUserOrGroupFromAllGroups(String memberWiki, String memberSpace, String memberName,
        XWikiContext context); @Override @Deprecated List<String> listMemberForGroup(String group, XWikiContext context); @Override @Deprecated List<String> listAllGroups(XWikiContext context); @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data); @Override List<?> getAllMatchedUsers(Object[][] matchFields, boolean withdetails, int nb, int start, Object[][] order,
        XWikiContext context); @Override List<?> getAllMatchedGroups(Object[][] matchFields, boolean withdetails, int nb, int start, Object[][] order,
        XWikiContext context); @Override int countAllMatchedUsers(Object[][] matchFields, XWikiContext context); @Override int countAllMatchedGroups(Object[][] matchFields, XWikiContext context); @Override Collection<String> getAllGroupsNamesForMember(String member, int nb, int start, XWikiContext context); @Override Collection<DocumentReference> getAllGroupsReferencesForMember(DocumentReference memberReference, int limit,
        int offset, XWikiContext context); @Override Collection<String> getAllMembersNamesForGroup(String group, int nb, int start, XWikiContext context); @Override Collection<String> getAllMatchedMembersNamesForGroup(String group, String matchField, int nb, int start,
        Boolean orderAsc, XWikiContext context); @Override int countAllMatchedMembersNamesForGroup(String group, String filter, XWikiContext xcontext); @Override int countAllGroupsNamesForMember(String member, XWikiContext context); @Override int countAllMembersNamesForGroup(String group, XWikiContext context); static final EntityReference GROUPCLASS_REFERENCE; }### Answer:
@Test public void countAllMatchedMembersNamesForGroup() throws Exception { Query query = mock(Query.class); when(this.oldcore.getQueryManager().createQuery(anyString(), eq(Query.HQL))).thenReturn(query); when(query.execute()).thenReturn(Collections.singletonList(5L)); assertEquals(5, this.groupService.countAllMatchedMembersNamesForGroup(this.group.getFullName(), "foo", this.oldcore.getXWikiContext())); verify(query).setWiki("wiki"); verify(query).bindValue("groupdocname", this.group.getFullName()); verify(query).bindValue("groupclassname", "XWiki.XWikiGroups"); verify(query).bindValue("matchfield", "%foo%"); }