Date now = new Date();
User user1 = mock(User.class);
User user2 = mock(User.class);
AuthenticationProcessor authProc1 = mock(AuthenticationProcessor.class);
when(authProc1.canHandle(any())).thenAnswer(new Answer<Boolean>() {
public Boolean answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
return (args.length == 1 && args[0] instanceof Date);
}
});
when(authProc1.authenticate(Mockito.<UserAdmin>any(), eq(now))).thenReturn(user1);
AuthenticationProcessor authProc2 = mock(AuthenticationProcessor.class);
when(authProc2.canHandle(anyString())).thenAnswer(new Answer<Boolean>() {
public Boolean answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
return (args.length == 1 && args[0] instanceof String);
}
});
when(authProc2.authenticate(Mockito.<UserAdmin>any(), eq("foo"))).thenReturn(user2);
AuthenticationServiceImpl authService = createAuthenticationService();
registerAuthProcessor(authService, authProc1);
registerAuthProcessor(authService, authProc2);