@Test
    void multipleServiceTest() throws Exception {

        List<WebEnvironment> environmentList = Arrays.asList(new WebEnvironmentStub(), new WebEnvironmentStub());

        ServletContext servletContext = mock(ServletContext.class);
        when(servletContext.getInitParameter(EnvironmentLoader.ENVIRONMENT_CLASS_PARAM)).then(args -> null);

        final EnvironmentLoader environmentLoader = spy(EnvironmentLoader.class);
        when(environmentLoader.doLoadWebEnvironmentsFromServiceLoader()).then(args -> environmentList.iterator());

        try {
            environmentLoader.createEnvironment(servletContext);
            fail("Expected ConfigurationException to be thrown");
        } catch (ConfigurationException e) {
            assertThat(e.getMessage(), stringContainsInOrder("zero or exactly one", "shiroEnvironmentClass"));
        }

        verify(servletContext).getInitParameter(EnvironmentLoader.ENVIRONMENT_CLASS_PARAM);
        verify(environmentLoader).doLoadWebEnvironmentsFromServiceLoader();
    }
Tests for {@link EnvironmentLoader} which will use a ServiceLoader.
web/src/test/java/org/apache/shiro/web/env/EnvironmentLoaderServiceTest.java