public void testAuthenticationFailed_AuthenticationException() throws Exception {
   InitialDirContextFactory mockFactory = mock(InitialDirContextFactory.class);
   when(mockFactory.create(Matchers.isA(Hashtable.class)))
       .thenThrow(new AuthenticationException());
   authenticator.initialDirContextFactory = mockFactory;
   assertFalse(authenticator.isAuthenticated("username", "password"));
 }
 @SuppressWarnings({"JNDIResourceOpenedButNotSafelyClosed"})
 public void testNullDirContext() throws Exception {
   InitialDirContextFactory mockFactory = mock(InitialDirContextFactory.class);
   when(mockFactory.create(Matchers.isA(Hashtable.class))).thenReturn(null);
   authenticator.initialDirContextFactory = mockFactory;
   assertFalse(authenticator.isAuthenticated("username", "password"));
 }