Home / Class/ BootTestRunIntegrationTests Class — spring-boot Architecture

BootTestRunIntegrationTests Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/run/BootTestRunIntegrationTests.java lines 45–190

@GradleCompatibility(configurationCache = true)
class BootTestRunIntegrationTests {

	@SuppressWarnings("NullAway.Init")
	GradleBuild gradleBuild;

	@TestTemplate
	void basicExecution() throws IOException {
		copyClasspathApplication();
		BuildResult result = this.gradleBuild.build("bootTestRun");
		BuildTask task = result.task(":bootTestRun");
		assertThat(task).isNotNull();
		assertThat(task.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
		assertThat(result.getOutput()).contains("1. " + canonicalPathOf("build/classes/java/test"))
			.contains("2. " + canonicalPathOf("build/resources/test"))
			.contains("3. " + canonicalPathOf("build/classes/java/main"))
			.contains("4. " + canonicalPathOf("build/resources/main"));
	}

	@TestTemplate
	void defaultJvmArgs() throws IOException {
		copyJvmArgsApplication();
		BuildResult result = this.gradleBuild.build("bootTestRun");
		BuildTask task = result.task(":bootTestRun");
		assertThat(task).isNotNull();
		assertThat(task.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
		assertThat(result.getOutput()).contains("-XX:TieredStopAtLevel=1");
	}

	@TestTemplate
	void optimizedLaunchDisabledJvmArgs() throws IOException {
		copyJvmArgsApplication();
		BuildResult result = this.gradleBuild.build("bootTestRun");
		BuildTask task = result.task(":bootTestRun");
		assertThat(task).isNotNull();
		assertThat(task.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
		assertThat(result.getOutput()).doesNotContain("-Xverify:none").doesNotContain("-XX:TieredStopAtLevel=1");
	}

	@TestTemplate
	void applicationPluginJvmArgumentsAreUsed() throws IOException {
		if (this.gradleBuild.isConfigurationCache()) {
			// https://github.com/gradle/gradle/pull/23924
			GradleVersion gradleVersion = GradleVersion.version(this.gradleBuild.getGradleVersion());
			Assumptions.assumeThat(gradleVersion)
				.isLessThan(GradleVersion.version("8.0"))
				.isGreaterThanOrEqualTo(GradleVersion.version("8.1-rc-1"));
		}
		copyJvmArgsApplication();
		BuildResult result = this.gradleBuild.build("bootTestRun");
		BuildTask task = result.task(":bootTestRun");
		assertThat(task).isNotNull();
		assertThat(task.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
		assertThat(result.getOutput()).contains("-Dcom.bar=baz")
			.contains("-Dcom.foo=bar")
			.contains("-XX:TieredStopAtLevel=1");
	}

	@TestTemplate
	void jarTypeFilteringIsAppliedToTheClasspath() throws IOException {
		copyClasspathApplication();
		File flatDirRepository = new File(this.gradleBuild.getProjectDir(), "repository");
		createDependenciesStarterJar(new File(flatDirRepository, "starter.jar"));
		createStandardJar(new File(flatDirRepository, "standard.jar"));
		BuildResult result = this.gradleBuild.build("bootTestRun");
		BuildTask task = result.task(":bootTestRun");
		assertThat(task).isNotNull();
		assertThat(task.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
		assertThat(result.getOutput()).contains("standard.jar").doesNotContain("starter.jar");
	}

	@TestTemplate
	void failsGracefullyWhenNoTestMainMethodIsFound() throws IOException {
		copyApplication("nomain");
		BuildResult result = this.gradleBuild.buildAndFail("bootTestRun");
		BuildTask task = result.task(":bootTestRun");
		assertThat(task).isNotNull();
		assertThat(task.getOutcome()).isEqualTo(TaskOutcome.FAILED);
		if (this.gradleBuild.isConfigurationCache() && this.gradleBuild.gradleVersionIsAtLeast("8.0")) {
			assertThat(result.getOutput())
				.contains("Main class name has not been configured and it could not be resolved from classpath");
		}
		else {
			assertThat(result.getOutput())
				.contains("Main class name has not been configured and it could not be resolved from classpath "
						+ canonicalPathOf("build/classes/java/test"));
		}
	}

	@TestTemplate
	void developmentOnlyDependenciesAreNotOnTheClasspath() throws IOException {
		copyClasspathApplication();
		BuildResult result = this.gradleBuild.build("bootTestRun");
		BuildTask task = result.task(":bootTestRun");
		assertThat(task).isNotNull();
		assertThat(task.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
		assertThat(result.getOutput()).doesNotContain("commons-lang3-3.12.0.jar");
	}

	@TestTemplate
	void testAndDevelopmentOnlyDependenciesAreOnTheClasspath() throws IOException {
		copyClasspathApplication();
		BuildResult result = this.gradleBuild.build("bootTestRun");
		BuildTask task = result.task(":bootTestRun");
		assertThat(task).isNotNull();
		assertThat(task.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
		assertThat(result.getOutput()).contains("commons-lang3-3.12.0.jar");
	}

	private void copyClasspathApplication() throws IOException {
		copyApplication("classpath");
	}

	private void copyJvmArgsApplication() throws IOException {
		copyApplication("jvmargs");
	}

	private void copyApplication(String name) throws IOException {
		File output = new File(this.gradleBuild.getProjectDir(), "src/test/java/com/example/boottestrun/" + name);
		output.mkdirs();
		FileSystemUtils.copyRecursively(new File("src/test/resources/com/example/boottestrun/" + name), output);
	}

	private String canonicalPathOf(String path) throws IOException {
		return new File(this.gradleBuild.getProjectDir(), path).getCanonicalPath();
	}

	private void createStandardJar(File location) throws IOException {
		createJar(location, (attributes) -> {
		});
	}

	private void createDependenciesStarterJar(File location) throws IOException {
		createJar(location, (attributes) -> attributes.putValue("Spring-Boot-Jar-Type", "dependencies-starter"));
	}

	private void createJar(File location, Consumer<Attributes> attributesConfigurer) throws IOException {
		location.getParentFile().mkdirs();
		Manifest manifest = new Manifest();
		Attributes attributes = manifest.getMainAttributes();
		attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
		attributesConfigurer.accept(attributes);
		new JarOutputStream(new FileOutputStream(location), manifest).close();
	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free