// Path: java-modules-context-boot/src/main/java/io/github/tomdw/java/modules/context/boot/api/ModuleContextBooter.java
// public class ModuleContextBooter {
// 
// 	public static void boot() {
// 		ModuleContextRegistry.boot();
// 	}
// 
// 	public static void boot(GenericApplicationContext defaultApplicationContext) {
// 		ModuleContextRegistry.boot(defaultApplicationContext);
// 	}
// 
// 	public static void reset() {
// 		ModuleContextRegistry.reset();
// 	}
// 
// 	public static GenericApplicationContext getContextFor(Module module) {
// 		return ModuleContextRegistry.getContextFor(module);
// 	}
// 
// 	public static void main(String... commandLineArguments) {
// 		ModuleContextBooter.boot();
// 	}
// 
// }
// 
// Path: java-modules-context-boot/src/main/java/io/github/tomdw/java/modules/context/boot/api/ModuleServiceProvider.java
// public class ModuleServiceProvider {
// 
// 	public static <SERVICETYPE> SERVICETYPE provide(Class<SERVICETYPE> servicetypeClass) {
// 		return ModuleContextRegistry.retrieveInstanceFromContext(servicetypeClass);
// 	}
// 
// 	public static <SERVICETYPE> SERVICETYPE provide(Class<SERVICETYPE> servicetypeClass, String serviceName) {
// 		return ModuleContextRegistry.retrieveInstanceFromContext(servicetypeClass, serviceName);
// 	}
// }


import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import io.github.tomdw.java.modules.context.boot.api.ModuleContextBooter;
import io.github.tomdw.java.modules.context.boot.api.ModuleServiceProvider;
package io.github.tomdw.java.modules.spring.boot.starter.tests;





@SpringBootTest(classes = SpringBootTestApplication.class)
public class JavaModulesContextBootStarterTest {

	@Autowired
	private ApplicationContext applicationContext;

	@Test
	public void springBootApplicationContextIsStartedAndDetectsOwnBeans() {
		assertThat(applicationContext).isNotNull();
		assertThat(applicationContext.getBean(DummyTestBean.class)).isNotNull();
	}

	@Test
	public void springBootStarterAutoConfiguresSpringApplicationContextForEveryModuleWithModuleContextAnnotation() {
		String[] expectedModuleNames = {"io.github.tomdw.java.modules.spring.samples.basicapplication.application",
				"io.github.tomdw.java.modules.spring.samples.basicapplication.speaker"};
		List<Module> modulesWithModuleContextAnnotation = ModuleLayer.boot().modules().stream().filter(module -> List.of(expectedModuleNames).contains(module.getName())).collect(Collectors.toList());

		assertThat(modulesWithModuleContextAnnotation.stream().map(Module::getName)).containsExactlyInAnyOrder(expectedModuleNames);

		modulesWithModuleContextAnnotation.forEach(
				module -> {
					GenericApplicationContext context = ModuleContextBooter.getContextFor(module);
					assertThat(context).withFailMessage("A context should have been created for module " + module.getName()).isNotNull();
					assertThat(context.isActive()).withFailMessage("The context should be active for module " + module.getName()).isTrue();
				}
		);
	}

	@Test
	public void moduleServiceProviderLooksForBeansInMainSpringBootContextWhenCallingModuleHasNoModuleContextAnnotation() {
// Path: java-modules-context-boot/src/main/java/io/github/tomdw/java/modules/context/boot/api/ModuleContextBooter.java
// public class ModuleContextBooter {
// 
// 	public static void boot() {
// 		ModuleContextRegistry.boot();
// 	}
// 
// 	public static void boot(GenericApplicationContext defaultApplicationContext) {
// 		ModuleContextRegistry.boot(defaultApplicationContext);
// 	}
// 
// 	public static void reset() {
// 		ModuleContextRegistry.reset();
// 	}
// 
// 	public static GenericApplicationContext getContextFor(Module module) {
// 		return ModuleContextRegistry.getContextFor(module);
// 	}
// 
// 	public static void main(String... commandLineArguments) {
// 		ModuleContextBooter.boot();
// 	}
// 
// }
// 
// Path: java-modules-context-boot/src/main/java/io/github/tomdw/java/modules/context/boot/api/ModuleServiceProvider.java
// public class ModuleServiceProvider {
// 
// 	public static <SERVICETYPE> SERVICETYPE provide(Class<SERVICETYPE> servicetypeClass) {
// 		return ModuleContextRegistry.retrieveInstanceFromContext(servicetypeClass);
// 	}
// 
// 	public static <SERVICETYPE> SERVICETYPE provide(Class<SERVICETYPE> servicetypeClass, String serviceName) {
// 		return ModuleContextRegistry.retrieveInstanceFromContext(servicetypeClass, serviceName);
// 	}
// }


// Path: integration-tests-spring-boot/src/test/java/io/github/tomdw/java/modules/spring/boot/starter/tests/JavaModulesContextBootStarterTest.java
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import io.github.tomdw.java.modules.context.boot.api.ModuleContextBooter;
import io.github.tomdw.java.modules.context.boot.api.ModuleServiceProvider;

package io.github.tomdw.java.modules.spring.boot.starter.tests;





@SpringBootTest(classes = SpringBootTestApplication.class)
public class JavaModulesContextBootStarterTest {

	@Autowired
	private ApplicationContext applicationContext;

	@Test
	public void springBootApplicationContextIsStartedAndDetectsOwnBeans() {
		assertThat(applicationContext).isNotNull();
		assertThat(applicationContext.getBean(DummyTestBean.class)).isNotNull();
	}

	@Test
	public void springBootStarterAutoConfiguresSpringApplicationContextForEveryModuleWithModuleContextAnnotation() {
		String[] expectedModuleNames = {"io.github.tomdw.java.modules.spring.samples.basicapplication.application",
				"io.github.tomdw.java.modules.spring.samples.basicapplication.speaker"};
		List<Module> modulesWithModuleContextAnnotation = ModuleLayer.boot().modules().stream().filter(module -> List.of(expectedModuleNames).contains(module.getName())).collect(Collectors.toList());

		assertThat(modulesWithModuleContextAnnotation.stream().map(Module::getName)).containsExactlyInAnyOrder(expectedModuleNames);

		modulesWithModuleContextAnnotation.forEach(
				module -> {
					GenericApplicationContext context = ModuleContextBooter.getContextFor(module);
					assertThat(context).withFailMessage("A context should have been created for module " + module.getName()).isNotNull();
					assertThat(context.isActive()).withFailMessage("The context should be active for module " + module.getName()).isTrue();
				}
		);
	}

	@Test
	public void moduleServiceProviderLooksForBeansInMainSpringBootContextWhenCallingModuleHasNoModuleContextAnnotation() {
		DummyTestBean providedBean = ModuleServiceProvider.provide(DummyTestBean.class);