PeerAuth { @VisibleForTesting Iterable<PeerAuthenticator> getPeerAuthenticatorInstances() { return INSTANTIATOR.getInstancesOrDefault(config.getPeerAuthenticators()); } @VisibleForTesting  PeerAuth(HttpServletRequest request); static PeerAuthenticator instantiatePeerAuthenticator(Class<? extends PeerAuthenticator> clazz);  }
@Test public void testGetPeerAuthenticatorInstances_default() throws Exception { when(config.getPeerAuthenticators()).thenReturn(null); List<PeerAuthenticator> peerAuthenticators = Lists.newArrayList(peerAuth.getPeerAuthenticatorInstances()); assertEquals(1, peerAuthenticators.size()); assertTrue(peerAuthenticators.get(0) instanceof EndpointsPeerAuthenticator); }
@Test public void testGetPeerAuthenticatorInstances() throws Exception { when(config.getPeerAuthenticators()).thenReturn( ImmutableList.of(PassPeerAuthenticator.class, FailPeerAuthenticator.class)); List<PeerAuthenticator> peerAuthenticators = Lists.newArrayList(peerAuth.getPeerAuthenticatorInstances()); assertEquals(2, peerAuthenticators.size()); assertTrue(peerAuthenticators.get(0) instanceof PassPeerAuthenticator); assertTrue(peerAuthenticators.get(1) instanceof FailPeerAuthenticator); }
@Test public void testGetPeerAuthenticatorInstances_singleton() throws Exception { when(config.getPeerAuthenticators()).thenReturn(ImmutableList.of(PassPeerAuthenticator.class, FailPeerAuthenticator.class, PassPeerAuthenticator.class)); List<PeerAuthenticator> peerAuthenticators = Lists.newArrayList(peerAuth.getPeerAuthenticatorInstances()); assertEquals(3, peerAuthenticators.size()); assertTrue(peerAuthenticators.get(0) instanceof PassPeerAuthenticator); assertTrue(peerAuthenticators.get(1) instanceof FailPeerAuthenticator); assertTrue(peerAuthenticators.get(2) instanceof PassPeerAuthenticator); assertSame(peerAuthenticators.get(0), peerAuthenticators.get(2)); }
@Test public void testGetPeerAuthenticatorInstances_nonSingleton() throws Exception { when(config.getPeerAuthenticators()).thenReturn(ImmutableList.of(PassPeerAuthenticator.class, FailPeerAuthenticator.class, FailPeerAuthenticator.class)); List<PeerAuthenticator> peerAuthenticators = Lists.newArrayList(peerAuth.getPeerAuthenticatorInstances()); assertEquals(3, peerAuthenticators.size()); assertTrue(peerAuthenticators.get(0) instanceof PassPeerAuthenticator); assertTrue(peerAuthenticators.get(1) instanceof FailPeerAuthenticator); assertTrue(peerAuthenticators.get(2) instanceof FailPeerAuthenticator); assertNotSame(peerAuthenticators.get(1), peerAuthenticators.get(2)); }