mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
Migrate generator tests to JUnit5
Closes gh-802
This commit is contained in:
parent
4810d8aac2
commit
2816c21631
@ -39,8 +39,28 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit-pioneer</groupId>
|
||||
<artifactId>junit-pioneer</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.spring.initializr.generator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -28,9 +28,9 @@ import io.spring.initializr.test.generator.GradleBuildAssert;
|
||||
import io.spring.initializr.test.generator.PomAssert;
|
||||
import io.spring.initializr.test.generator.ProjectAssert;
|
||||
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@ -43,11 +43,9 @@ import static org.mockito.Mockito.verify;
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ExtendWith(TempDirectory.class)
|
||||
public abstract class AbstractProjectGeneratorTests {
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
protected final ProjectGenerator projectGenerator;
|
||||
|
||||
protected final ApplicationEventPublisher eventPublisher = mock(
|
||||
@ -61,8 +59,8 @@ public abstract class AbstractProjectGeneratorTests {
|
||||
this.projectGenerator = projectGenerator;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
@BeforeEach
|
||||
public void setup(@TempDirectory.TempDir Path folder) {
|
||||
Dependency web = Dependency.withId("web");
|
||||
web.getFacets().add("web");
|
||||
InitializrMetadata metadata = initializeTestMetadataBuilder()
|
||||
@ -73,7 +71,7 @@ public abstract class AbstractProjectGeneratorTests {
|
||||
this.projectGenerator.setEventPublisher(this.eventPublisher);
|
||||
this.projectGenerator
|
||||
.setRequestResolver(new ProjectRequestResolver(new ArrayList<>()));
|
||||
this.projectGenerator.setTmpdir(this.folder.newFolder().getAbsolutePath());
|
||||
this.projectGenerator.setTmpdir(folder.toString());
|
||||
}
|
||||
|
||||
protected InitializrMetadataTestBuilder initializeTestMetadataBuilder() {
|
||||
|
@ -23,8 +23,8 @@ import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.metadata.Type;
|
||||
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.util.TemplateRenderer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ -35,7 +35,7 @@ public class CommandLineHelpGeneratorTests {
|
||||
|
||||
private CommandLineHelpGenerator generator;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
this.generator = new CommandLineHelpGenerator(new TemplateRenderer());
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import io.spring.initializr.test.generator.ProjectAssert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -16,15 +16,17 @@
|
||||
|
||||
package io.spring.initializr.generator;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import io.spring.initializr.metadata.BillOfMaterials;
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.test.generator.ProjectAssert;
|
||||
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.util.VersionProperty;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
@ -33,123 +35,123 @@ import org.springframework.core.io.ClassPathResource;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
Object[] maven = new Object[] { "maven", "pom.xml" };
|
||||
Object[] gradle = new Object[] { "gradle", "build.gradle" };
|
||||
return new Object[] { maven, gradle };
|
||||
public static Stream<Arguments> parameters() {
|
||||
return Stream.of(Arguments.arguments("maven", "pom.xml"),
|
||||
Arguments.arguments("gradle", "build.gradle"));
|
||||
}
|
||||
|
||||
private final String build;
|
||||
|
||||
private final String fileName;
|
||||
|
||||
private final String assertFileName;
|
||||
|
||||
public ProjectGeneratorBuildTests(String build, String fileName) {
|
||||
this.build = build;
|
||||
this.fileName = fileName;
|
||||
this.assertFileName = fileName + ".gen";
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationJarJava(String build, String fileName) {
|
||||
testCurrentGenerationJar("java", build, fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationJarJava() {
|
||||
testCurrentGenerationJar("java");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationJarGroovy(String build, String fileName) {
|
||||
testCurrentGenerationJar("groovy", build, fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationJarGroovy() {
|
||||
testCurrentGenerationJar("groovy");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationJarKotlin(String build, String fileName) {
|
||||
testCurrentGenerationJar("kotlin", build, fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationJarKotlin() {
|
||||
testCurrentGenerationJar("kotlin");
|
||||
}
|
||||
|
||||
private void testCurrentGenerationJar(String language) {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
private void testCurrentGenerationJar(String language, String build,
|
||||
String fileName) {
|
||||
ProjectRequest request = createProjectRequestForType(build);
|
||||
request.setLanguage(language);
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/standard/" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/standard/" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationWarJava() {
|
||||
testCurrentGenerationWar("java");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationWarJava(String build, String fileName) {
|
||||
testCurrentGenerationWar("java", build, fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationWarGroovy() {
|
||||
testCurrentGenerationWar("groovy");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationWarGroovy(String build, String fileName) {
|
||||
testCurrentGenerationWar("groovy", build, fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationWarKotlin() {
|
||||
testCurrentGenerationWar("kotlin");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationWarKotlin(String build, String fileName) {
|
||||
testCurrentGenerationWar("kotlin", build, fileName);
|
||||
}
|
||||
|
||||
private void testCurrentGenerationWar(String language) {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
private void testCurrentGenerationWar(String language, String build,
|
||||
String fileName) {
|
||||
ProjectRequest request = createProjectRequestForType(build, "web");
|
||||
request.setPackaging("war");
|
||||
request.setLanguage(language);
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/standard/war-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/standard/war-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void previousGenerationJarJava() {
|
||||
testPreviousGenerationJar("java");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void previousGenerationJarJava(String build, String fileName) {
|
||||
testPreviousGenerationJar("java", build, fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void previousGenerationJarGroovy() {
|
||||
testPreviousGenerationJar("groovy");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void previousGenerationJarGroovy(String build, String fileName) {
|
||||
testPreviousGenerationJar("groovy", build, fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void previousGenerationJarKotlin() {
|
||||
testPreviousGenerationJar("kotlin");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void previousGenerationJarKotlin(String build, String fileName) {
|
||||
testPreviousGenerationJar("kotlin", build, fileName);
|
||||
}
|
||||
|
||||
private void testPreviousGenerationJar(String language) {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
private void testPreviousGenerationJar(String language, String build,
|
||||
String fileName) {
|
||||
ProjectRequest request = createProjectRequestForType(build);
|
||||
request.setLanguage(language);
|
||||
request.setBootVersion("1.5.18.RELEASE");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/previous/" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/previous/" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinJava11() {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void kotlinJava11(String build, String fileName) {
|
||||
ProjectRequest request = createProjectRequestForType(build);
|
||||
request.setLanguage("kotlin");
|
||||
request.setJavaVersion("11");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + this.build + "/kotlin-java11-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + build + "/kotlin-java11-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void versionOverride() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void versionOverride(String build, String fileName) {
|
||||
ProjectRequest request = createProjectRequestForType(build, "web");
|
||||
request.getBuildProperties().getVersions().put(
|
||||
VersionProperty.of("spring-foo.version", false), () -> "0.1.0.RELEASE");
|
||||
request.getBuildProperties().getVersions()
|
||||
.put(VersionProperty.of("spring-bar.version"), () -> "0.2.0.RELEASE");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + this.build + "/version-override-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + build + "/version-override-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bomWithVersionProperty() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void bomWithVersionProperty(String build, String fileName) {
|
||||
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
||||
foo.setBom("the-bom");
|
||||
BillOfMaterials bom = BillOfMaterials.create("org.acme", "foo-bom", "1.3.3");
|
||||
@ -157,28 +159,31 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("foo", foo).addBom("the-bom", bom).build();
|
||||
applyMetadata(metadata);
|
||||
ProjectRequest request = createProjectRequest("foo");
|
||||
ProjectRequest request = createProjectRequestForType(build, "foo");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + this.build + "/bom-property-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + build + "/bom-property-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileOnlyDependency() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void compileOnlyDependency(String build, String fileName) {
|
||||
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
||||
foo.setScope(Dependency.SCOPE_COMPILE_ONLY);
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("core", "web", "data-jpa")
|
||||
.addDependencyGroup("foo", foo).build();
|
||||
applyMetadata(metadata);
|
||||
ProjectRequest request = createProjectRequest("foo", "web", "data-jpa");
|
||||
ProjectRequest request = createProjectRequestForType(build, "foo", "web",
|
||||
"data-jpa");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource("project/"
|
||||
+ this.build + "/compile-only-dependency-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource("project/"
|
||||
+ build + "/compile-only-dependency-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationProcessorDependency() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void annotationProcessorDependency(String build, String fileName) {
|
||||
Dependency annotationProcessor = Dependency.withId("configuration-processor",
|
||||
"org.springframework.boot", "spring-boot-configuration-processor");
|
||||
annotationProcessor.setScope(Dependency.SCOPE_ANNOTATION_PROCESSOR);
|
||||
@ -187,16 +192,18 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
|
||||
.addDependencyGroup("configuration-processor", annotationProcessor)
|
||||
.build();
|
||||
applyMetadata(metadata);
|
||||
ProjectRequest request = createProjectRequest("configuration-processor", "web",
|
||||
"data-jpa");
|
||||
ProjectRequest request = createProjectRequestForType(build,
|
||||
"configuration-processor", "web", "data-jpa");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName)
|
||||
.equalsTo(new ClassPathResource("project/" + this.build
|
||||
+ "/annotation-processor-dependency-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName)
|
||||
.equalsTo(new ClassPathResource(
|
||||
"project/" + build + "/annotation-processor-dependency-"
|
||||
+ getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bomWithOrdering() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void bomWithOrdering(String build, String fileName) {
|
||||
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
||||
foo.setBom("foo-bom");
|
||||
BillOfMaterials barBom = BillOfMaterials.create("org.acme", "bar-bom", "1.0");
|
||||
@ -213,14 +220,15 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
|
||||
.addDependencyGroup("foo", foo).addBom("foo-bom", fooBom)
|
||||
.addBom("bar-bom", barBom).addBom("biz-bom", bizBom).build();
|
||||
applyMetadata(metadata);
|
||||
ProjectRequest request = createProjectRequest("foo");
|
||||
ProjectRequest request = createProjectRequestForType(build, "foo");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + this.build + "/bom-ordering-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + build + "/bom-ordering-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositories() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void repositories(String build, String fileName) {
|
||||
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
||||
foo.setRepository("foo-repository");
|
||||
Dependency bar = Dependency.withId("bar", "org.acme", "bar");
|
||||
@ -233,30 +241,34 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
|
||||
true)
|
||||
.build();
|
||||
applyMetadata(metadata);
|
||||
ProjectRequest request = createProjectRequest("foo", "bar");
|
||||
ProjectRequest request = createProjectRequestForType(build, "foo", "bar");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + this.build + "/repositories-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + build + "/repositories-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoriesMilestone() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void repositoriesMilestone(String build, String fileName) {
|
||||
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", foo).build();
|
||||
applyMetadata(metadata);
|
||||
ProjectRequest request = createProjectRequest("foo");
|
||||
ProjectRequest request = createProjectRequestForType(build, "foo");
|
||||
request.setBootVersion("2.2.0.M1");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource("project/"
|
||||
+ this.build + "/repositories-milestone-" + this.assertFileName));
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource("project/"
|
||||
+ build + "/repositories-milestone-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectRequest createProjectRequest(String... styles) {
|
||||
public ProjectRequest createProjectRequestForType(String build, String... styles) {
|
||||
ProjectRequest request = super.createProjectRequest(styles);
|
||||
request.setType(this.build + "-project");
|
||||
request.setType(build + "-project");
|
||||
return request;
|
||||
}
|
||||
|
||||
private String getAssertFileName(String fileName) {
|
||||
return fileName + ".gen";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,10 +16,12 @@
|
||||
|
||||
package io.spring.initializr.generator;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import io.spring.initializr.test.generator.ProjectAssert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
@ -28,117 +30,117 @@ import org.springframework.core.io.ClassPathResource;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Object[] parameters() {
|
||||
Object[] java = new Object[] { "java", "java" };
|
||||
Object[] groovy = new Object[] { "groovy", "groovy" };
|
||||
Object[] kotlin = new Object[] { "kotlin", "kt" };
|
||||
return new Object[] { java, groovy, kotlin };
|
||||
public static Stream<Arguments> parameters() {
|
||||
return Stream.of(Arguments.arguments("java", "java"),
|
||||
Arguments.arguments("groovy", "groovy"),
|
||||
Arguments.arguments("kotlin", "kt"));
|
||||
}
|
||||
|
||||
private final String language;
|
||||
|
||||
private final String extension;
|
||||
|
||||
private final String expectedExtension;
|
||||
|
||||
public ProjectGeneratorLanguageTests(String language, String extension) {
|
||||
this.language = language;
|
||||
this.extension = extension;
|
||||
this.expectedExtension = extension + ".gen";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationJar() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationJar(String language, String extension) {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
request.setLanguage(this.language);
|
||||
request.setLanguage(language);
|
||||
generateProject(request).isGenericProject(ProjectAssert.DEFAULT_PACKAGE_NAME,
|
||||
ProjectAssert.DEFAULT_APPLICATION_NAME, this.language, this.extension);
|
||||
ProjectAssert.DEFAULT_APPLICATION_NAME, language, extension);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationWar() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationWar(String language, String extension) {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.setLanguage(this.language);
|
||||
request.setLanguage(language);
|
||||
request.setPackaging("war");
|
||||
generateProject(request).isGenericWarProject(ProjectAssert.DEFAULT_PACKAGE_NAME,
|
||||
ProjectAssert.DEFAULT_APPLICATION_NAME, this.language, this.extension);
|
||||
ProjectAssert.DEFAULT_APPLICATION_NAME, language, extension);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationMainClass() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationMainClass(String language, String extension) {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
request.setLanguage(this.language);
|
||||
request.setLanguage(language);
|
||||
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert("src/main/" + this.language
|
||||
+ "/com/example/demo/DemoApplication." + this.extension)
|
||||
.equalsTo(new ClassPathResource("project/" + this.language
|
||||
+ "/standard/DemoApplication." + this.expectedExtension));
|
||||
project.sourceCodeAssert(
|
||||
"src/main/" + language + "/com/example/demo/DemoApplication." + extension)
|
||||
.equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/standard/DemoApplication."
|
||||
+ getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void previousGenerationMainClass() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void previousGenerationMainClass(String language, String extension) {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
request.setLanguage(this.language);
|
||||
request.setLanguage(language);
|
||||
request.setBootVersion("1.5.18.RELEASE");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert("src/main/" + this.language
|
||||
+ "/com/example/demo/DemoApplication." + this.extension)
|
||||
.equalsTo(new ClassPathResource("project/" + this.language + "/previous/"
|
||||
+ "/DemoApplication." + this.expectedExtension));
|
||||
project.sourceCodeAssert(
|
||||
"src/main/" + language + "/com/example/demo/DemoApplication." + extension)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/previous/"
|
||||
+ "/DemoApplication." + getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationTestClass() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationTestClass(String language, String extension) {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
request.setLanguage(this.language);
|
||||
request.setLanguage(language);
|
||||
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert("src/test/" + this.language
|
||||
+ "/com/example/demo/DemoApplicationTests." + this.extension)
|
||||
.equalsTo(new ClassPathResource("project/" + this.language
|
||||
+ "/standard/DemoApplicationTests." + this.expectedExtension));
|
||||
project.sourceCodeAssert("src/test/" + language
|
||||
+ "/com/example/demo/DemoApplicationTests." + extension)
|
||||
.equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/standard/DemoApplicationTests."
|
||||
+ getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationTestClassWeb() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationTestClassWeb(String language, String extension) {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.setLanguage(this.language);
|
||||
request.setLanguage(language);
|
||||
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert("src/test/" + this.language
|
||||
+ "/com/example/demo/DemoApplicationTests." + this.extension)
|
||||
.equalsTo(new ClassPathResource("project/" + this.language
|
||||
+ "/standard/DemoApplicationTestsWeb." + this.expectedExtension));
|
||||
project.sourceCodeAssert("src/test/" + language
|
||||
+ "/com/example/demo/DemoApplicationTests." + extension)
|
||||
.equalsTo(new ClassPathResource(
|
||||
"project/" + language + "/standard/DemoApplicationTestsWeb."
|
||||
+ getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentGenerationServletInitializer() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void currentGenerationServletInitializer(String language, String extension) {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
request.setLanguage(this.language);
|
||||
request.setLanguage(language);
|
||||
request.setPackaging("war");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert("src/main/" + this.language
|
||||
+ "/com/example/demo/ServletInitializer." + this.extension)
|
||||
.equalsTo(new ClassPathResource("project/" + this.language + "/standard/"
|
||||
+ "ServletInitializer." + this.expectedExtension));
|
||||
project.sourceCodeAssert("src/main/" + language
|
||||
+ "/com/example/demo/ServletInitializer." + extension)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/standard/"
|
||||
+ "ServletInitializer." + getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void previousGenerationServletInitializer() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
public void previousGenerationServletInitializer(String language, String extension) {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
request.setLanguage(this.language);
|
||||
request.setLanguage(language);
|
||||
request.setBootVersion("1.5.18.RELEASE");
|
||||
request.setPackaging("war");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert("src/main/" + this.language
|
||||
+ "/com/example/demo/ServletInitializer." + this.extension)
|
||||
.equalsTo(new ClassPathResource("project/" + this.language + "/previous/"
|
||||
+ "ServletInitializer." + this.expectedExtension));
|
||||
project.sourceCodeAssert("src/main/" + language
|
||||
+ "/com/example/demo/ServletInitializer." + extension)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/previous/"
|
||||
+ "ServletInitializer." + getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
private String getExpectedExtension(String extension) {
|
||||
return extension + ".gen";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,14 +24,13 @@ import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.test.generator.ProjectAssert;
|
||||
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.util.VersionProperty;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
@ -42,9 +41,6 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
*/
|
||||
public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Override
|
||||
protected InitializrMetadataTestBuilder initializeTestMetadataBuilder() {
|
||||
return InitializrMetadataTestBuilder.withBasicDefaults();
|
||||
@ -786,18 +782,18 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
public void invalidProjectTypeMavenPom() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.setType("gradle-build");
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("gradle-build");
|
||||
this.projectGenerator.generateMavenPom(request);
|
||||
assertThatExceptionOfType(InvalidProjectRequestException.class)
|
||||
.isThrownBy(() -> this.projectGenerator.generateMavenPom(request))
|
||||
.withMessageContaining("gradle-build");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidProjectTypeGradleBuild() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.setType("maven-build");
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("maven-build");
|
||||
this.projectGenerator.generateGradleBuild(request);
|
||||
assertThatExceptionOfType(InvalidProjectRequestException.class)
|
||||
.isThrownBy(() -> this.projectGenerator.generateGradleBuild(request))
|
||||
.withMessageContaining("maven-build");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -860,9 +856,9 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.setType("maven-project");
|
||||
request.setBootVersion("1.2.3.M4");
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("1.2.3.M4");
|
||||
this.projectGenerator.generateMavenPom(request);
|
||||
assertThatExceptionOfType(InvalidProjectRequestException.class)
|
||||
.isThrownBy(() -> this.projectGenerator.generateMavenPom(request))
|
||||
.withMessageContaining("1.2.3.M4");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -24,8 +24,8 @@ import java.util.Map;
|
||||
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
|
||||
@ -45,7 +45,7 @@ public class ProjectRequestResolverTests {
|
||||
|
||||
final GenericProjectRequestPostProcessor processor = new GenericProjectRequestPostProcessor();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.postProcessors.add(this.processor);
|
||||
}
|
||||
|
@ -24,20 +24,16 @@ import io.spring.initializr.metadata.Dependency.Mapping;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.metadata.InitializrMetadataBuilder;
|
||||
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ProjectRequestTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.build();
|
||||
|
||||
@ -115,11 +111,9 @@ public class ProjectRequestTests {
|
||||
.addDependencyGroup("code", "org.foo:bar").build();
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.getStyle().addAll(Arrays.asList("org.foo:bar", "foo-bar"));
|
||||
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("foo-bar");
|
||||
request.resolve(this.metadata);
|
||||
assertThat(request.getResolvedDependencies()).hasSize(1);
|
||||
assertThatExceptionOfType(InvalidProjectRequestException.class)
|
||||
.isThrownBy(() -> request.resolve(this.metadata))
|
||||
.withMessageContaining("foo-bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -128,11 +122,9 @@ public class ProjectRequestTests {
|
||||
.addDependencyGroup("code", "org.foo:bar").build();
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.getStyle().add("org.foo:acme"); // does not exist
|
||||
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("org.foo:acme");
|
||||
request.resolve(this.metadata);
|
||||
assertThat(request.getResolvedDependencies()).hasSize(1);
|
||||
assertThatExceptionOfType(InvalidProjectRequestException.class)
|
||||
.isThrownBy(() -> request.resolve(this.metadata))
|
||||
.withMessageContaining("org.foo:acme");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -156,11 +148,10 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.getStyle().add("org.foo:bar");
|
||||
request.setBootVersion("0.9.9.RELEASE");
|
||||
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("org.foo:bar");
|
||||
this.thrown.expectMessage("0.9.9.RELEASE");
|
||||
request.resolve(metadata);
|
||||
assertThatExceptionOfType(InvalidProjectRequestException.class)
|
||||
.isThrownBy(() -> request.resolve(metadata))
|
||||
.withMessageContaining("org.foo:bar")
|
||||
.withMessageContaining("0.9.9.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -210,10 +201,9 @@ public class ProjectRequestTests {
|
||||
public void resolveUnknownType() {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.setType("foo-project");
|
||||
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("foo-project");
|
||||
request.resolve(this.metadata);
|
||||
assertThatExceptionOfType(InvalidProjectRequestException.class)
|
||||
.isThrownBy(() -> request.resolve(this.metadata))
|
||||
.withMessageContaining("foo-project");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -21,20 +21,16 @@ import java.util.Arrays;
|
||||
import io.spring.initializr.metadata.BillOfMaterials.Mapping;
|
||||
import io.spring.initializr.util.Version;
|
||||
import io.spring.initializr.util.VersionParser;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class BillOfMaterialsTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void resolveSimpleBom() {
|
||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
|
||||
@ -126,10 +122,9 @@ public class BillOfMaterialsTests {
|
||||
bom.getMappings().add(Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0"));
|
||||
bom.getMappings().add(Mapping.create("[1.3.0.M1, 1.4.0.M1)", "1.2.0"));
|
||||
bom.validate();
|
||||
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("1.4.1.RELEASE");
|
||||
bom.resolve(Version.parse("1.4.1.RELEASE"));
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> bom.resolve(Version.parse("1.4.1.RELEASE")))
|
||||
.withMessageContaining("1.4.1.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -16,11 +16,10 @@
|
||||
|
||||
package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link DependenciesCapability}.
|
||||
@ -29,9 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class DependenciesCapabilityTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void indexedDependencies() {
|
||||
Dependency dependency = Dependency.withId("first");
|
||||
@ -51,10 +47,8 @@ public class DependenciesCapabilityTests {
|
||||
Dependency dependency2 = Dependency.withId("conflict");
|
||||
DependenciesCapability capability = createDependenciesCapability("foo",
|
||||
dependency, dependency2);
|
||||
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("conflict");
|
||||
capability.validate();
|
||||
assertThatIllegalArgumentException().isThrownBy(capability::validate)
|
||||
.withMessageContaining("conflict");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -65,7 +59,6 @@ public class DependenciesCapabilityTests {
|
||||
DependenciesCapability capability = createDependenciesCapability("foo",
|
||||
dependency);
|
||||
capability.validate();
|
||||
|
||||
assertThat(capability.get("first")).isSameAs(dependency);
|
||||
assertThat(capability.get("alias1")).isSameAs(dependency);
|
||||
assertThat(capability.get("alias2")).isSameAs(dependency);
|
||||
@ -81,10 +74,8 @@ public class DependenciesCapabilityTests {
|
||||
DependenciesCapability capability = new DependenciesCapability();
|
||||
capability.getContent().add(createDependencyGroup("foo", dependency));
|
||||
capability.getContent().add(createDependencyGroup("bar", dependency2));
|
||||
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("alias2");
|
||||
capability.validate();
|
||||
assertThatIllegalArgumentException().isThrownBy(capability::validate)
|
||||
.withMessageContaining("alias2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -20,11 +20,11 @@ import java.util.Arrays;
|
||||
|
||||
import io.spring.initializr.util.Version;
|
||||
import io.spring.initializr.util.VersionParser;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link Dependency}.
|
||||
@ -33,9 +33,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class DependencyTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createRootSpringBootStarter() {
|
||||
Dependency d = new Dependency();
|
||||
@ -95,59 +92,53 @@ public class DependencyTests {
|
||||
|
||||
@Test
|
||||
public void invalidDependency() {
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
new Dependency().resolve();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(() -> new Dependency().resolve());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidDependencyScope() {
|
||||
Dependency dependency = Dependency.withId("web");
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(() -> dependency.setScope("whatever"));
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
dependency.setScope("whatever");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidSpringBootRange() {
|
||||
Dependency dependency = Dependency.withId("web");
|
||||
dependency.setVersionRange("A.B.C");
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("A.B.C");
|
||||
dependency.resolve();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(dependency::resolve).withMessageContaining("A.B.C");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidIdFormatTooManyColons() {
|
||||
Dependency dependency = Dependency.withId("org.foo:bar:1.0:test:external");
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
dependency.resolve();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(dependency::resolve);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidLink() {
|
||||
Dependency dependency = Dependency.withId("foo");
|
||||
dependency.getLinks().add(Link.create(null, "https://example.com"));
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
dependency.resolve();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(dependency::resolve);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateIdWithNoGroupId() {
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId("bar");
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
dependency.generateId();
|
||||
assertThatIllegalArgumentException().isThrownBy(dependency::generateId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateIdWithNoArtifactId() {
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setGroupId("foo");
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
dependency.generateId();
|
||||
assertThatIllegalArgumentException().isThrownBy(dependency::generateId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -163,9 +154,8 @@ public class DependencyTests {
|
||||
Dependency dependency = Dependency.withId("web");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("foo-bar", null, null, "0.1.0.RELEASE"));
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("foo-bar");
|
||||
dependency.resolve();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(dependency::resolve).withMessageContaining("foo-bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -18,7 +18,7 @@ package io.spring.initializr.metadata;
|
||||
|
||||
import io.spring.initializr.metadata.InitializrConfiguration.Env.Kotlin;
|
||||
import io.spring.initializr.util.Version;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -20,7 +20,7 @@ import java.net.URL;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
|
@ -23,20 +23,16 @@ import io.spring.initializr.metadata.BillOfMaterials.Mapping;
|
||||
import io.spring.initializr.metadata.InitializrConfiguration.Env.Kotlin;
|
||||
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.util.Version;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class InitializrMetadataTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void invalidBom() {
|
||||
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
||||
@ -44,11 +40,9 @@ public class InitializrMetadataTests {
|
||||
InitializrMetadataTestBuilder builder = InitializrMetadataTestBuilder
|
||||
.withDefaults().addBom("my-bom", "org.acme", "foo", "1.2.3")
|
||||
.addDependencyGroup("test", foo);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("foo-bom");
|
||||
this.thrown.expectMessage("my-bom");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build).withMessageContaining("foo-bom")
|
||||
.withMessageContaining("my-bom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -59,11 +53,9 @@ public class InitializrMetadataTests {
|
||||
.withDefaults()
|
||||
.addRepository("my-repo", "repo", "http://example.com/repo", true)
|
||||
.addDependencyGroup("test", foo);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("foo-repo");
|
||||
this.thrown.expectMessage("my-repo");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build).withMessageContaining("foo-repo")
|
||||
.withMessageContaining("my-repo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -72,11 +64,9 @@ public class InitializrMetadataTests {
|
||||
|
||||
InitializrMetadataTestBuilder builder = InitializrMetadataTestBuilder
|
||||
.withDefaults().addBom("foo-bom", bom);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("No version");
|
||||
this.thrown.expectMessage("foo-bom");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build).withMessageContaining("No version")
|
||||
.withMessageContaining("foo-bom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -87,11 +77,10 @@ public class InitializrMetadataTests {
|
||||
|
||||
InitializrMetadataTestBuilder builder = InitializrMetadataTestBuilder
|
||||
.withDefaults().addBom("foo-bom", bom);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("invalid repository id foo-repo");
|
||||
this.thrown.expectMessage("foo-bom");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build)
|
||||
.withMessageContaining("invalid repository id foo-repo")
|
||||
.withMessageContaining("foo-bom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -104,11 +93,10 @@ public class InitializrMetadataTests {
|
||||
|
||||
InitializrMetadataTestBuilder builder = InitializrMetadataTestBuilder
|
||||
.withDefaults().addBom("foo-bom", bom).addBom("bar-bom", barBom);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("invalid additional bom");
|
||||
this.thrown.expectMessage("biz-bom");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build)
|
||||
.withMessageContaining("invalid additional bom")
|
||||
.withMessageContaining("biz-bom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -119,11 +107,9 @@ public class InitializrMetadataTests {
|
||||
|
||||
InitializrMetadataTestBuilder builder = InitializrMetadataTestBuilder
|
||||
.withDefaults().addBom("foo-bom", bom);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("FOO_BAR");
|
||||
this.thrown.expectMessage("foo-bom");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build).withMessageContaining("FOO_BAR")
|
||||
.withMessageContaining("foo-bom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -136,12 +122,10 @@ public class InitializrMetadataTests {
|
||||
|
||||
InitializrMetadataTestBuilder builder = InitializrMetadataTestBuilder
|
||||
.withDefaults().addBom("foo-bom", bom);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("invalid repository id foo-repo");
|
||||
this.thrown.expectMessage("1.3.0.M2");
|
||||
this.thrown.expectMessage("foo-bom");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build)
|
||||
.withMessageContaining("invalid repository id foo-repo")
|
||||
.withMessageContaining("1.3.0.M2").withMessageContaining("foo-bom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -154,12 +138,10 @@ public class InitializrMetadataTests {
|
||||
|
||||
InitializrMetadataTestBuilder builder = InitializrMetadataTestBuilder
|
||||
.withDefaults().addBom("foo-bom", bom);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage("invalid additional bom");
|
||||
this.thrown.expectMessage("1.3.0.M2");
|
||||
this.thrown.expectMessage("bar-bom");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build)
|
||||
.withMessageContaining("invalid additional bom")
|
||||
.withMessageContaining("1.3.0.M2").withMessageContaining("bar-bom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -205,11 +187,9 @@ public class InitializrMetadataTests {
|
||||
public void invalidParentMissingVersion() {
|
||||
InitializrMetadataTestBuilder builder = InitializrMetadataTestBuilder
|
||||
.withDefaults().setMavenParent("org.foo", "foo-parent", null, false);
|
||||
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
this.thrown.expectMessage(
|
||||
"Custom maven pom requires groupId, artifactId and version");
|
||||
builder.build();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(builder::build).withMessageContaining(
|
||||
"Custom maven pom requires groupId, artifactId and version");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -21,11 +21,11 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link Link}.
|
||||
@ -34,22 +34,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class LinkTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void resolveInvalidLinkNoRel() {
|
||||
Link link = new Link();
|
||||
link.setHref("https://example.com");
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
link.resolve();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(link::resolve);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveInvalidLinkNoHref() {
|
||||
Link link = Link.create("reference", null, "foo doc");
|
||||
this.thrown.expect(InvalidInitializrMetadataException.class);
|
||||
link.resolve();
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
|
||||
.isThrownBy(link::resolve);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -94,10 +91,9 @@ public class LinkTests {
|
||||
public void expandLinkMissingVariable() {
|
||||
Link link = Link.create("reference", "https://example.com/{a}/2/{b}");
|
||||
link.resolve();
|
||||
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("missing value for 'b'");
|
||||
link.expand(Collections.singletonMap("a", "test"));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> link.expand(Collections.singletonMap("a", "test")))
|
||||
.withMessageContaining("missing value for 'b'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -30,7 +30,7 @@ import org.custommonkey.xmlunit.SimpleNamespaceContext;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.custommonkey.xmlunit.XpathEngine;
|
||||
import org.custommonkey.xmlunit.exceptions.XpathException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
@ -274,7 +274,7 @@ public class PomAssert {
|
||||
|
||||
public PomAssert hasNoRepository() {
|
||||
try {
|
||||
Assert.assertEquals(0, this.eng
|
||||
Assertions.assertEquals(0, this.eng
|
||||
.getMatchingNodes(createRootNodeXPath("repositories"), this.doc)
|
||||
.getLength());
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package io.spring.initializr.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -20,11 +20,10 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link VersionParser}.
|
||||
@ -33,9 +32,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class VersionParserTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private VersionParser parser = new VersionParser(Collections.emptyList());
|
||||
|
||||
@Test
|
||||
@ -58,8 +54,8 @@ public class VersionParserTests {
|
||||
|
||||
@Test
|
||||
public void parseInvalidVersion() {
|
||||
this.thrown.expect(InvalidVersionException.class);
|
||||
this.parser.parse("foo");
|
||||
assertThatExceptionOfType(InvalidVersionException.class)
|
||||
.isThrownBy(() -> this.parser.parse("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -128,8 +124,8 @@ public class VersionParserTests {
|
||||
|
||||
@Test
|
||||
public void invalidRange() {
|
||||
this.thrown.expect(InvalidVersionException.class);
|
||||
this.parser.parseRange("foo-bar");
|
||||
assertThatExceptionOfType(InvalidVersionException.class)
|
||||
.isThrownBy(() -> this.parser.parseRange("foo-bar"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,11 +16,10 @@
|
||||
|
||||
package io.spring.initializr.util;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link VersionProperty}.
|
||||
@ -29,9 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class VersionPropertyTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testStandardProperty() {
|
||||
assertThat(VersionProperty.of("spring-boot.version").toStandardFormat())
|
||||
@ -58,16 +54,15 @@ public class VersionPropertyTests {
|
||||
|
||||
@Test
|
||||
public void testInvalidPropertyUpperCase() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("upper case");
|
||||
VersionProperty.of("Spring-boot.version");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> VersionProperty.of("Spring-boot.version"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidPropertyIllegalCharacter() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Unsupported character");
|
||||
VersionProperty.of("spring-boot_version");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> VersionProperty.of("spring-boot_version"))
|
||||
.withMessageContaining("Unsupported character");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,9 +20,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ -31,9 +29,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class VersionRangeTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void simpleStartingRange() {
|
||||
assertThat(new VersionRange(Version.parse("1.3.0.RELEASE")).toString())
|
||||
|
@ -18,7 +18,7 @@ package io.spring.initializr.util;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
8
pom.xml
8
pom.xml
@ -82,7 +82,11 @@
|
||||
<version>0.7.0.BUILD-SNAPSHOT</version>
|
||||
<type>test-jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit-pioneer</groupId>
|
||||
<artifactId>junit-pioneer</artifactId>
|
||||
<version>0.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
@ -232,7 +236,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.20.1</version>
|
||||
<version>2.22.1</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Tests.java</include>
|
||||
|
Loading…
Reference in New Issue
Block a user