Auth { @VisibleForTesting Iterable<Authenticator> getAuthenticatorInstances() { return INSTANTIATOR.getInstancesOrDefault(config.getAuthenticators()); } @VisibleForTesting  Auth(HttpServletRequest request); static Authenticator instantiateAuthenticator(Class<? extends Authenticator> clazz);  }
@Test public void testGetAuthenticatorInstances_default() throws Exception { when(config.getAuthenticators()).thenReturn(null); List<Authenticator> authenticators = Lists.newArrayList(auth.getAuthenticatorInstances()); assertEquals(1, authenticators.size()); assertTrue(authenticators.get(0) instanceof EndpointsAuthenticator); }
@Test public void testGetAuthenticatorInstances() throws Exception { when(config.getAuthenticators()).thenReturn( ImmutableList.of(PassAuthenticator.class, FailAuthenticator.class)); List<Authenticator> authenticators = Lists.newArrayList(auth.getAuthenticatorInstances()); assertEquals(2, authenticators.size()); assertTrue(authenticators.get(0) instanceof PassAuthenticator); assertTrue(authenticators.get(1) instanceof FailAuthenticator); }
@Test public void testGetAuthenticatorInstances_singleton() throws Exception { when(config.getAuthenticators()).thenReturn(ImmutableList.of(PassAuthenticator.class, FailAuthenticator.class, PassAuthenticator.class)); List<Authenticator> authenticators = Lists.newArrayList(auth.getAuthenticatorInstances()); assertEquals(3, authenticators.size()); assertTrue(authenticators.get(0) instanceof PassAuthenticator); assertTrue(authenticators.get(1) instanceof FailAuthenticator); assertTrue(authenticators.get(2) instanceof PassAuthenticator); assertSame(authenticators.get(0), authenticators.get(2)); }
@Test public void testGetAuthenticatorInstances_nonSingleton() throws Exception { when(config.getAuthenticators()).thenReturn(ImmutableList.of(PassAuthenticator.class, FailAuthenticator.class, FailAuthenticator.class)); List<Authenticator> authenticators = Lists.newArrayList(auth.getAuthenticatorInstances()); assertEquals(3, authenticators.size()); assertTrue(authenticators.get(0) instanceof PassAuthenticator); assertTrue(authenticators.get(1) instanceof FailAuthenticator); assertTrue(authenticators.get(2) instanceof FailAuthenticator); assertNotSame(authenticators.get(1), authenticators.get(2)); }