@Test
public void testAuthenticate() throws Exception {

  PAM pam = createNiceMock(PAM.class);
  UnixUser unixUser = createNiceMock(UnixUser.class);
  expect(pam.authenticate(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(unixUser).atLeastOnce();
  expect(unixUser.getGroups()).andReturn(new HashSet<String>(Arrays.asList("group"))).atLeastOnce();
  EasyMock.replay(unixUser);
  EasyMock.replay(pam);
  Authentication authentication = new UsernamePasswordAuthenticationToken("allowedUser", "password");
  Authentication result = authenticationProvider.authenticateViaPam(pam,authentication);
  assertEquals("allowedUser", result.getName());
}