### Question:
ObmSyncAuthenticationPlugin extends CRaSHPlugin<AuthenticationPlugin> implements AuthenticationPlugin<String> { @Override public boolean authenticate(String username, String password) throws IOException { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { return loginClientFactory.create(httpClient) .authenticateAdmin(username, UserPassword.valueOf(password), consoleConfiguration.authoritativeDomain()); } catch (AuthFault e) { return false; } } @Inject @VisibleForTesting  ObmSyncAuthenticationPlugin(LoginClient.Factory loginClientFactory, RemoteConsoleConfiguration consoleConfiguration); @Override boolean authenticate(String username, String password); @Override AuthenticationPlugin<String> getImplementation(); @Override String getName(); @Override Class<String> getCredentialType();  }### Answer:
@Test public void authenticateShouldDelegateThenReturnTrueWhenSuccess() throws Exception { expect(loginClient.authenticateAdmin("username", UserPassword.valueOf("password"), "global.domain")) .andReturn(true); mocks.replay(); boolean authenticated = testee.authenticate("username", "password"); mocks.verify(); assertThat(authenticated).isTrue(); }
@Test public void authenticateShouldDelegateThenReturnFalseWhenFailed() throws Exception { expect(loginClient.authenticateAdmin("username", UserPassword.valueOf("password"), "global.domain")) .andThrow(new AuthFault("error")); mocks.replay(); boolean authenticated = testee.authenticate("username", "password"); mocks.verify(); assertThat(authenticated).isFalse(); }
@Test(expected=IllegalStateException.class) public void authenticateShouldDelegateThenPropagateWhenError() throws Exception { expect(loginClient.authenticateAdmin("username", UserPassword.valueOf("password"), "global.domain")) .andThrow(new IllegalStateException()); mocks.replay(); try { testee.authenticate("username", "password"); } catch (Exception e) { mocks.verify(); throw e; } }