public static <T> Iterator<Class<T>> classIterator(Class<T> expectedType, String factoryId, ClassLoader classLoader) {
        Set<ServiceDefinition> serviceDefinitions = getServiceDefinitions(factoryId, classLoader);
        return new ClassIterator<>(serviceDefinitions, expectedType);
    }
@Test
    public void testClassIteratorInTomcat_whenClassesInBothLibs()
            throws Exception {
        ClassLoader launchClassLoader = this.getClass().getClassLoader();
        ClassLoader webappClassLoader;
        // setup embedded tomcat
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(13256); // 8080 may be used by some other tests
        Context ctx = tomcat.addContext("", null);
        // Map target/classes as WEB-INF/classes, so webapp classloader
        // will locate compiled production classes in the webapp classpath.
        // The purpose of this setup is to make project classes available
        // to both launch classloader and webapplication classloader,
        // modeling a Tomcat deployment in which Hazelcast JARs are deployed
        // in both tomcat/lib and webapp/lib
        File webInfClasses = new File("target/classes");
        WebResourceRoot resources = new StandardRoot(ctx);
        resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
                webInfClasses.getAbsolutePath(), "/"));
        ctx.setResources(resources);

        TestServiceLoaderServlet testServlet = new TestServiceLoaderServlet();
        Wrapper wrapper = tomcat.addServlet("", "testServlet", testServlet);
        wrapper.setLoadOnStartup(1);
        ctx.addServletMappingDecoded("/", "testServlet");

        tomcat.start();
        try {
            assertTrueEventually(() -> assertTrue(testServlet.isInitDone()));
            assertNull("No failure is expected from servlet init() method", testServlet.failure());

            webappClassLoader = testServlet.getWebappClassLoader();

            assertNotEquals(launchClassLoader, webappClassLoader);
            Iterator<? extends Class<?>> iterator
                    = ServiceLoader.classIterator(DataSerializerHook.class, "com.hazelcast.DataSerializerHook",
                    webappClassLoader);
            assertTrue(iterator.hasNext());
            while (iterator.hasNext()) {
                Class<?> klass = iterator.next();
                assertEquals(launchClassLoader, klass.getClassLoader());
            }
        } finally {
            tomcat.stop();
        }
    }