@Test
    void testGetLdapContext() throws NamingException {
        assertThrows(NamingException.class, () -> {
            factory = new JndiLdapContextFactory();
            //garbage URL to test that the context is being created, but fails:
            String brokenHost = UUID.randomUUID().toString();
            factory.setUrl("ldap://" + brokenHost + ":389");
            factory.getLdapContext("foo", "bar");
        });
    }
This is the only test that does not fake the JNDI environment.  It is provided for 100% test coverage.

@throws NamingException thrown because the host is always broken.
core/src/test/java/org/apache/shiro/realm/ldap/JndiLdapContextFactoryTest.java