when(authenticationManager.authenticate(anyString(), any(Credentials.class))).thenAnswer(
new Answer<Authentication>() {
@Override
public Authentication answer(InvocationOnMock invocation) throws Throwable {
String user = (String) invocation.getArguments()[0];
Password credentials = (Password) invocation.getArguments()[1];
if ("user".equals(user) && credentials.getValue().equals("password")) {
return new Authentication(user, credentials.toString());
}
throw new AuthenticationException("username and password did not match");
}
});
PrivateKeySource keySource = mock(PrivateKeySource.class);