Home / Class/ ApplicationHomeTests Class — spring-boot Architecture

ApplicationHomeTests Class — spring-boot Architecture

Architecture documentation for the ApplicationHomeTests class in ApplicationHomeTests.java from the spring-boot codebase.

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/system/ApplicationHomeTests.java lines 40–81

class ApplicationHomeTests {

	@TempDir
	@SuppressWarnings("NullAway.Init")
	File tempDir;

	@Test
	void whenSourceClassIsProvidedThenApplicationHomeReflectsItsLocation() throws Exception {
		File app = new File(this.tempDir, "app");
		ApplicationHome applicationHome = createApplicationHome(app);
		assertThat(applicationHome.getDir()).isEqualTo(app);
	}

	@Test
	void whenSourceClassIsProvidedWithSpaceInItsPathThenApplicationHomeReflectsItsLocation() throws Exception {
		File app = new File(this.tempDir, "app location");
		ApplicationHome applicationHome = createApplicationHome(app);
		assertThat(applicationHome.getDir()).isEqualTo(app);
	}

	private ApplicationHome createApplicationHome(File location) throws Exception {
		File examplePackage = new File(location, "com/example");
		examplePackage.mkdirs();
		FileCopyUtils.copy(
				new ByteArrayInputStream(
						new ByteBuddy().subclass(Object.class).name("com.example.Source").make().getBytes()),
				new FileOutputStream(new File(examplePackage, "Source.class")));
		try (URLClassLoader classLoader = new URLClassLoader(new URL[] { location.toURI().toURL() })) {
			Class<?> sourceClass = classLoader.loadClass("com.example.Source");
			// Separate thread to bypass stack-based unit test detection in
			// ApplicationHome
			ExecutorService executor = Executors.newSingleThreadExecutor();
			try {
				return executor.submit(() -> new ApplicationHome(sourceClass)).get();
			}
			finally {
				executor.shutdown();
			}
		}
	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free