WebappAuthenticatorRepository { public void addAuthenticator(WebappAuthenticator authenticator) { if (authenticator == null) { throw new IllegalStateException("Authenticator implementation to be added to the webapp " + "authenticator repository cannot be null or empty"); } if (authenticator.getName() == null || authenticator.getName().isEmpty()) { throw new IllegalStateException("Authenticator name cannot be null or empty"); } authenticators.put(authenticator.getName(), authenticator); } WebappAuthenticatorRepository(); void addAuthenticator(WebappAuthenticator authenticator); WebappAuthenticator getAuthenticator(String name); Map<String, WebappAuthenticator> getAuthenticators();  }
@Test public void testAddAuthenticator() { WebappAuthenticatorRepository repository = new WebappAuthenticatorRepository(); WebappAuthenticator addedAuthenticator = new TestWebappAuthenticator(); repository.addAuthenticator(addedAuthenticator); WebappAuthenticator retriedAuthenticator = repository.getAuthenticator(addedAuthenticator.getName()); Assert.assertEquals(addedAuthenticator.getName(), retriedAuthenticator.getName()); }
@Test(expectedExceptions = IllegalStateException.class) public void testAddMalformedAuthenticator() { WebappAuthenticatorRepository repository = new WebappAuthenticatorRepository(); WebappAuthenticator malformedAuthenticator = new MalformedAuthenticator(); repository.addAuthenticator(malformedAuthenticator); }
@Test(expectedExceptions = IllegalStateException.class) public void testAddAuthenticatorWithNull() { WebappAuthenticatorRepository repository = new WebappAuthenticatorRepository(); repository.addAuthenticator(null); }
@Test(expectedExceptions = IllegalStateException.class) public void testAddAuthenticatorWithEmptyString() { WebappAuthenticatorRepository repository = new WebappAuthenticatorRepository(); repository.addAuthenticator(null); }