ApplicationComponent extends SystemComponent { @Override protected ComponentLifecycle<ApplicationComponent> lifecycle() { return new ComponentLifecycle<ApplicationComponent>() { @SuppressWarnings("unchecked") @Override public void start(ApplicationComponent component) { if (component.application == null) { component.application = tryReflection(() -> { component.loader = new ConfigurationLoader(getClass().getClassLoader()); component.originalLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(loader); Class<? extends ApplicationFactory> factoryClass = (Class<? extends ApplicationFactory>) loader.loadClass(factoryClassName); ComponentInjector injector = new ComponentInjector(getAllDependencies()); ApplicationFactory factory = factoryClass.getConstructor().newInstance(); Application<AREQ, ARES> app = factory.create(injector); app.getMiddlewareStack().stream() .map(MiddlewareChain::getMiddleware) .forEach(injector::inject); if (applicationCustomizer != null) { app = applicationCustomizer.apply(app); } app.validate(); return app; }); } } @Override public void stop(ApplicationComponent component) { component.application = null; component.loader = null; if (originalLoader != null) { Thread.currentThread().setContextClassLoader(originalLoader); } } }; } ApplicationComponent(String className); Application getApplication(); ConfigurationLoader getLoader(); String getFactoryClassName(); void setApplicationCustomizer(Function<Application<AREQ,ARES>, Application<AREQ,ARES>> applicationCustomizer); @Override String toString();  }
@Test void validationError() { assertThatThrownBy(() -> { ApplicationComponent component = new ApplicationComponent(TestApplicationFactory.class.getName()); component.lifecycle().start(component); }).isExactlyInstanceOf(MisconfigurationException.class); }