DefaultRepoInitFactory { static <T> @Nullable Class<? extends T> loadClazz(final @NotNull ClassLoader classLoader, final @NotNull Class<T> iface, final @NotNull String clazzName) { try { Class<?> clazz = classLoader.loadClass(clazzName); if (iface.isAssignableFrom(clazz)) { return clazz.asSubclass(iface); } else { Throwable e = new IllegalStateException(); LOGGER.warn(MessageFormat.format( "class from classLoader argument does not implement {0} from oakpal classLoader: {1}", iface.getSimpleName(), clazzName), e); } } catch (Exception e) { LOGGER.warn(MessageFormat.format( "Failed to load the class from the provided classLoader: {0}", clazzName), e); } return null; } DefaultRepoInitFactory(final @Nullable Class<? extends RepoInitParser> parserClazz); static DefaultRepoInitFactory newFactoryInstance(final @NotNull ClassLoader parserCl); static OakMachine.RepoInitProcessor newDefaultRepoInitProcessor(
            final @NotNull ClassLoader defaultClassLoader); static OakMachine.RepoInitProcessor bindParser(final @NotNull RepoInitParser parser);  }
@Test public void testLoadClazz() { final Class<? extends RepoInitParser> parserClazz = DefaultRepoInitFactory.loadClazz(getClass().getClassLoader(), RepoInitParser.class, ParserType.class.getName()); assertEquals("expect parser class", ParserType.class, parserClazz); final Class<? extends RepoInitParser> wrongConstructorClazz = DefaultRepoInitFactory.loadClazz(getClass().getClassLoader(), RepoInitParser.class, ParserTypeWrongConstructor.class.getName()); assertEquals("expect parser class", ParserTypeWrongConstructor.class, wrongConstructorClazz); final Class<? extends RepoInitParser> nullClazz = DefaultRepoInitFactory.loadClazz(getClass().getClassLoader(), RepoInitParser.class, NeitherType.class.getName()); assertNull("expect null type", nullClazz); final Class<? extends RepoInitParser> nonExistingClazz = DefaultRepoInitFactory.loadClazz(getClass().getClassLoader(), RepoInitParser.class, ParserType.class.getName() + "NonExisting"); assertNull("expect nonExistingClazz type", nonExistingClazz); }