Skip to content

Commit

Permalink
Add helper methods to AbstractExtensionTests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Sep 30, 2024
1 parent 407ec4d commit 3767fe1
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ protected AssertProvider<TextAssert> composeFile(ProjectRequest request) {
return () -> new TextAssert(project.getProjectDirectory().resolve("compose.yaml"));
}

protected AssertProvider<TextAssert> applicationProperties(ProjectRequest request) {
ProjectStructure project = generateProject(request);
return () -> new TextAssert(project.getProjectDirectory().resolve("src/main/resources/application.properties"));
}

protected AssertProvider<TextAssert> gitIgnore(ProjectRequest request) {
ProjectStructure project = generateProject(request);
return () -> new TextAssert(project.getProjectDirectory().resolve(".gitignore"));
}

protected AssertProvider<TextAssert> helpDocument(ProjectStructure project) {
return () -> new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
}

protected AssertProvider<TextAssert> helpDocument(ProjectRequest request) {
return helpDocument(generateProject(request));
}

protected ProjectStructure generateProject(ProjectRequest request) {
ProjectGenerationResult result = getInvoker().invokeProjectStructureGeneration(request);
return new ProjectStructure(result.getRootDirectory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package io.spring.start.site.extension.build.gradle;

import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link GradleBuildSystemHelpDocumentCustomizer}.
*
Expand Down Expand Up @@ -63,8 +63,7 @@ private ListAssert<String> assertHelpDocument(String type, String version) {
ProjectRequest request = createProjectRequest("web");
request.setType(type);
request.setBootVersion(version);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines();
return assertThat(helpDocument(request)).lines();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package io.spring.start.site.extension.build.maven;

import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link MavenBuildSystemHelpDocumentCustomizer}.
*
Expand Down Expand Up @@ -61,8 +61,7 @@ private ListAssert<String> assertHelpDocument(String type, String version) {
ProjectRequest request = createProjectRequest("web");
request.setType(type);
request.setBootVersion(version);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines();
return assertThat(helpDocument(request)).lines();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ void kotlinCoroutinesIsAdded() {
request.setLanguage("kotlin");
ProjectStructure project = generateProject(request);
assertThat(project).mavenBuild().hasDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-reactor");
assertThat(project).textFile("HELP.md")
.contains(
"* [Coroutines section of the Spring Framework Documentation](https://docs.spring.io/spring/docs/6.1.8/spring-framework-reference/languages.html#coroutines)");
assertThat(helpDocument(request)).contains(
"* [Coroutines section of the Spring Framework Documentation](https://docs.spring.io/spring/docs/6.1.8/spring-framework-reference/languages.html#coroutines)");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

import io.spring.initializr.generator.io.template.MustacheTemplateRenderer;
import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link DgsCodegenHelpDocumentCustomizer}.
*
Expand Down Expand Up @@ -52,8 +53,7 @@ void gradleBuildAddsLinkToGradleCodegenPlugin() {
private TextAssert assertHelpDocument(String type, String... dependencies) {
ProjectRequest request = createProjectRequest(dependencies);
request.setType(type);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
return assertThat(helpDocument(request));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.spring.initializr.generator.project.ProjectDescription;
import io.spring.initializr.generator.spring.documentation.HelpDocument;
import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.generator.version.Version;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
Expand Down Expand Up @@ -146,8 +145,7 @@ void shouldNotDocumentGradleToolchainLimitationsWhenUsingMaven() {
}

private TextAssert assertHelpDocument(ProjectRequest request) {
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
return assertThat(helpDocument(request));
}

private TextAssert assertHelpDocument(String type, String... dependencies) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package io.spring.start.site.extension.dependency.observability;

import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link ObservabilityHelpDocumentCustomizer}.
*
Expand Down Expand Up @@ -57,8 +57,7 @@ private ListAssert<String> assertHelpDocument(String version, String... dependen
ProjectRequest request = createProjectRequest(dependencies);
request.setType("gradle-build");
request.setBootVersion(version);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines();
return assertThat(helpDocument(request)).lines();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package io.spring.start.site.extension.dependency.okta;

import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link OktaHelpDocumentCustomizer}.
*
Expand All @@ -44,8 +45,7 @@ void oktaSectionWithoutOktaDependencyIsMissing() {
private TextAssert assertHelpDocument(String... dependencies) {
ProjectRequest request = createProjectRequest(dependencies);
request.setBootVersion(SPRING_BOOT_VERSION);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
return assertThat(helpDocument(request));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private ProjectStructure generateProject(String bootVersion, String... dependenc
}

private TextAssert assertThatHelpDocumentOf(ProjectStructure project) {
return new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
return assertThat(helpDocument(project));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void functionBuildSetupInfoSectionAddedForMaven() {
request.setBootVersion(SPRING_BOOT_VERSION);
request.setType("maven-build");
request.setDependencies(Arrays.asList("cloud-function", "azure-support"));
assertThat(generateProject(request)).textFile("HELP.md").contains(AZURE_SECTION_TITLE);
assertThat(helpDocument(request)).contains(AZURE_SECTION_TITLE);
}

@Test
Expand All @@ -50,13 +50,13 @@ void functionBuildSetupInfoSectionAddedForGradle() {
request.setBootVersion(SPRING_BOOT_VERSION);
request.setType("gradle-build");
request.setDependencies(Arrays.asList("cloud-function", "azure-support"));
assertThat(generateProject(request)).textFile("HELP.md").contains(AZURE_SECTION_TITLE);
assertThat(helpDocument(request)).contains(AZURE_SECTION_TITLE);
}

@Test
void functionBuildSetupInfoSectionNotAddedWhenFunctionAndCloudDependenciesAbsent() {
ProjectRequest request = createProjectRequest();
assertThat(generateProject(request)).textFile("HELP.md").doesNotContain(AZURE_SECTION_TITLE);
assertThat(helpDocument(request)).doesNotContain(AZURE_SECTION_TITLE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ private ProjectStructure generateProject(String... dependencies) {

private TextAssert assertHelpDocument(String... dependencyIds) {
ProjectRequest request = createProjectRequest(dependencyIds);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
return assertThat(helpDocument(request));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ private ProjectStructure generateProject(String platformVersion, String... depen
private TextAssert assertHelpDocument(String platformVersion, String... dependencyIds) {
ProjectRequest request = createProjectRequest(dependencyIds);
request.setBootVersion(platformVersion);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
return assertThat(helpDocument(request));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ void gitIgnoreWithoutVaadinDoesNotIgnoreNodeModules() {

@Test
void shouldAddLaunchBrowserProperty() {
assertThat(generateProject(createProjectRequest("vaadin"))).textFile("src/main/resources/application.properties")
.contains("vaadin.launch-browser=true");
assertThat(applicationProperties(createProjectRequest("vaadin"))).lines().contains("vaadin.launch-browser=true");
}

@Test
void shouldNotAddLaunchBrowserPropertyIfVaadinIsNotSelected() {
assertThat(generateProject(createProjectRequest("data-jpa"))).textFile("src/main/resources/application.properties")
.doesNotContain("vaadin.launch-browser=true");
assertThat(applicationProperties(createProjectRequest("data-jpa"))).lines().doesNotContain("vaadin.launch-browser=true");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

import io.spring.initializr.generator.language.kotlin.KotlinLanguage;
import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link InvalidJvmVersionHelpDocumentCustomizer}.
*
Expand Down Expand Up @@ -56,8 +57,7 @@ void warningNotAddedWithCompatibleVersion() {
}

private TextAssert assertHelpDocument(ProjectRequest request) {
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
return assertThat(helpDocument(request));
}

private TextAssert assertHelpDocument(String platformVersion, String jvmVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package io.spring.start.site.extension.description;

import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link InvalidPackageNameHelpDocumentCustomizer}.
*
Expand All @@ -44,8 +45,7 @@ void warningNotAddedWithValidPackageName() {
private TextAssert assertHelpDocument(String packageName) {
ProjectRequest request = createProjectRequest("web");
request.setPackageName(packageName);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md"));
return assertThat(helpDocument(request));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package io.spring.start.site.extension.properties;

import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link DefaultApplicationPropertiesCustomizer}.
*
Expand All @@ -34,12 +34,7 @@ void shouldAddSpringApplicationName() {
ProjectRequest request = createProjectRequest("web");
request.setJavaVersion("21");
request.setName("test");
assertApplicationProperties(request).lines().contains("spring.application.name=test");
}

private TextAssert assertApplicationProperties(ProjectRequest request) {
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("src/main/resources/application.properties"));
assertThat(applicationProperties(request)).lines().contains("spring.application.name=test");
}

}

0 comments on commit 3767fe1

Please sign in to comment.