@Test
public void testSyncGroupsMembershipFromPUMA() throws Exception
{

    final Group pumaGroup1 = this.mockery.mock(Group.class, "group1");
    final Group pumaGroup2 = this.mockery.mock(Group.class, "group2");
    
    this.mockery.checking(new Expectations()
    {{
        // PUMAAuthServiceImpl#syncGroupsMembershipFromPUMA
        allowing(xwikiMock).getXWikiPreference(with(any(String.class)), with(any(XWikiContext.class))); will(returnValue(group.getFullName() + "=cn=group,ou=groups,o=xwiki,c=org"
                + "|XWiki.group2=cn=group2,ou=groups,o=xwiki,c=org"));
        allowing(pumaLocatorMock).findGroupsByPrincipal(pumaUserMock, true); will(returnValue(Arrays.asList(pumaGroup1, pumaGroup2)));
        allowing(pumaProfileMock).getIdentifier(pumaGroup1); will(returnValue("cn=group,ou=groups,o=xwiki,c=org"));
        allowing(pumaProfileMock).getIdentifier(pumaGroup2); will(returnValue("cn=group3,ou=groups,o=xwiki,c=org"));
        // AbstractAuthServiceImpl#syncGroupsMembership
        allowing(xwikiMock).getGroupService(getContext()); will(returnValue(xwikiGroupServiceMock));
        allowing(xwikiMock).getXClass(groupClass.getDocumentReference(), getContext()); will(returnValue(groupClass));
        allowing(xwikiGroupServiceMock).getAllGroupsNamesForMember(user.getFullName(), 0, 0, getContext()); will(returnValue(Arrays.<String> asList()));
        // user added to the group
        oneOf(xwikiMock).getDocument(group.getFullName(), getContext()); will(returnValue(group));
        oneOf(xwikiMock).getGroupClass(getContext()); will(returnValue(groupClass));
        oneOf(xwikiMock).saveDocument(group, getContext());
    }});
    this.authService.syncGroupsMembershipFromPUMA(this.user, this.pumaUserMock, this.pumaLocatorMock, this.pumaProfileMock, getContext());
}