GitLabAuthenticator implements Authenticator<GitLabCredentials, Principal> { @Override public Optional<Principal> authenticate(GitLabCredentials credentials) throws AuthenticationException { if(password.contentEquals(credentials.getPassword())) { return Optional.of(credentials::getService); } else { return Optional.absent(); } } GitLabAuthenticator(@NonNull String password); @Override Optional<Principal> authenticate(GitLabCredentials credentials);  }
@Test public void authenticateWithBadCredentialsShouldReturnAnAbsentPrincipal() throws Exception { Optional<Principal> principalOptional = gitLabAuthenticator.authenticate( new GitLabCredentials("bad-svc", "bad-pwd")); assertThat(principalOptional.isPresent()).isFalse(); }
@Test public void authenticateWithGoodCredentialsShouldReturnAPrincipal() throws Exception { Optional<Principal> principalOptional = gitLabAuthenticator.authenticate( new GitLabCredentials("good-svc", password)); assertThat(principalOptional.isPresent()).isTrue(); assertThat(principalOptional.get().getName()).isEqualTo("good-svc"); }