mirror of
https://gitee.com/dcren/initializr.git
synced 2025-05-06 21:58:08 +08:00
Polish
This commit is contained in:
parent
9ea41f151d
commit
c298a6d021
@ -16,10 +16,7 @@
|
||||
|
||||
package io.spring.initializr.generator.spring.build.gradle;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
@ -47,7 +44,6 @@ import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ -116,18 +112,16 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildDotGradleDotKtsIsContributedWhenGeneratingGradleKtsProject()
|
||||
throws IOException {
|
||||
void buildDotGradleDotKtsIsContributedWhenGeneratingGradleKtsProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage("11"));
|
||||
description.addDependency("acme",
|
||||
new Dependency("com.example", "acme", DependencyScope.COMPILE));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("build.gradle.kts");
|
||||
Path path = projectStructure.resolve("build.gradle.kts");
|
||||
String[] lines = readAllLines(path);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("build.gradle.kts");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle.kts");
|
||||
assertThat(lines).containsExactly("plugins {",
|
||||
" id(\"org.springframework.boot\") version \"2.1.0.RELEASE\"",
|
||||
" id(\"io.spring.dependency-management\") version \"1.0.6.RELEASE\"",
|
||||
@ -142,18 +136,16 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void warPluginIsAppliedWhenBuildingProjectThatUsesWarPackaging() throws IOException {
|
||||
void warPluginIsAppliedWhenBuildingProjectThatUsesWarPackaging() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
description.setPackaging(new WarPackaging());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("build.gradle.kts");
|
||||
try (Stream<String> lines = Files
|
||||
.lines(projectStructure.resolve("build.gradle.kts"))) {
|
||||
assertThat(lines.filter((line) -> line.contains(" war"))).hasSize(1);
|
||||
}
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("build.gradle.kts");
|
||||
assertThat(projectStructure.readAllLines("build.gradle.kts"))
|
||||
.containsOnlyOnce(" war");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -182,12 +174,4 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
" useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
private static String[] readAllLines(Path file) throws IOException {
|
||||
String content = StreamUtils.copyToString(
|
||||
new FileInputStream(new File(file.toString())), StandardCharsets.UTF_8);
|
||||
String[] lines = content.split("\\r?\\n");
|
||||
assertThat(content).endsWith(System.lineSeparator());
|
||||
return lines;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ package io.spring.initializr.generator.spring.build.maven;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.BuildWriter;
|
||||
@ -74,10 +73,9 @@ class MavenProjectGenerationConfigurationTests {
|
||||
void mavenWrapperIsContributedWhenGeneratingMavenProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
List<String> relativePaths = this.projectTester.generate(description)
|
||||
.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("mvnw", "mvnw.cmd",
|
||||
".mvn/wrapper/MavenWrapperDownloader.java",
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("mvnw",
|
||||
"mvnw.cmd", ".mvn/wrapper/MavenWrapperDownloader.java",
|
||||
".mvn/wrapper/maven-wrapper.properties",
|
||||
".mvn/wrapper/maven-wrapper.jar");
|
||||
}
|
||||
@ -86,9 +84,8 @@ class MavenProjectGenerationConfigurationTests {
|
||||
void mavenPomIsContributedWhenGeneratingMavenProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
List<String> relativePaths = this.projectTester.generate(description)
|
||||
.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("pom.xml");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("pom.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -97,8 +94,7 @@ class MavenProjectGenerationConfigurationTests {
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
description.setPackaging(new WarPackaging());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("pom.xml");
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("pom.xml");
|
||||
try (Stream<String> lines = Files.lines(projectStructure.resolve("pom.xml"))) {
|
||||
assertThat(lines
|
||||
.filter((line) -> line.contains(" <packaging>war</packaging>")))
|
||||
|
@ -56,9 +56,9 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
|
||||
@Test
|
||||
void mainClassIsContributed() {
|
||||
List<String> relativePaths = this.projectTester.generate(new ProjectDescription())
|
||||
.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
ProjectStructure projectStructure = this.projectTester
|
||||
.generate(new ProjectDescription());
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/groovy/com/example/demo/DemoApplication.groovy");
|
||||
}
|
||||
|
||||
@ -66,8 +66,7 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
void testClassIsContributed() {
|
||||
ProjectStructure projectStructure = this.projectTester
|
||||
.generate(new ProjectDescription());
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/groovy/com/example/demo/DemoApplicationTests.groovy");
|
||||
List<String> lines = projectStructure.readAllLines(
|
||||
"src/test/groovy/com/example/demo/DemoApplicationTests.groovy");
|
||||
@ -86,8 +85,7 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
description.setPackaging(new WarPackaging());
|
||||
description.setApplicationName("Demo2Application");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/groovy/com/example/demo/ServletInitializer.groovy");
|
||||
List<String> lines = projectStructure.readAllLines(
|
||||
"src/main/groovy/com/example/demo/ServletInitializer.groovy");
|
||||
|
@ -57,9 +57,8 @@ class JavaProjectGenerationConfigurationTests {
|
||||
@Test
|
||||
void mainClassIsContributed() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
List<String> relativePaths = this.projectTester.generate(description)
|
||||
.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/java/com/example/demo/DemoApplication.java");
|
||||
}
|
||||
|
||||
@ -67,8 +66,7 @@ class JavaProjectGenerationConfigurationTests {
|
||||
void testClassIsContributed() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/java/com/example/demo/DemoApplicationTests.java");
|
||||
List<String> lines = projectStructure
|
||||
.readAllLines("src/test/java/com/example/demo/DemoApplicationTests.java");
|
||||
@ -87,8 +85,7 @@ class JavaProjectGenerationConfigurationTests {
|
||||
description.setPackaging(new WarPackaging());
|
||||
description.setApplicationName("MyDemoApplication");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/java/com/example/demo/ServletInitializer.java");
|
||||
List<String> lines = projectStructure
|
||||
.readAllLines("src/main/java/com/example/demo/ServletInitializer.java");
|
||||
@ -107,9 +104,8 @@ class JavaProjectGenerationConfigurationTests {
|
||||
void customPackageNameIsUsedWhenGeneratingProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPackageName("com.example.foo");
|
||||
List<String> relativePaths = this.projectTester.generate(description)
|
||||
.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains(
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains(
|
||||
"src/main/java/com/example/foo/DemoApplication.java",
|
||||
"src/test/java/com/example/foo/DemoApplicationTests.java");
|
||||
}
|
||||
@ -118,9 +114,8 @@ class JavaProjectGenerationConfigurationTests {
|
||||
void customApplicationNameIsUsedWhenGeneratingProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setApplicationName("MyApplication");
|
||||
List<String> relativePaths = this.projectTester.generate(description)
|
||||
.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains(
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains(
|
||||
"src/main/java/com/example/demo/MyApplication.java",
|
||||
"src/test/java/com/example/demo/MyApplicationTests.java");
|
||||
}
|
||||
|
@ -59,9 +59,9 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
|
||||
@Test
|
||||
void mainClassIsContributedWhenGeneratingProject() {
|
||||
List<String> relativePaths = this.projectTester.generate(new ProjectDescription())
|
||||
.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
ProjectStructure projectStructure = this.projectTester
|
||||
.generate(new ProjectDescription());
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/kotlin/com/example/demo/DemoApplication.kt");
|
||||
}
|
||||
|
||||
@ -69,8 +69,7 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
void testClassIsContributed() {
|
||||
ProjectStructure projectStructure = this.projectTester
|
||||
.generate(new ProjectDescription());
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/kotlin/com/example/demo/DemoApplicationTests.kt");
|
||||
List<String> lines = projectStructure
|
||||
.readAllLines("src/test/kotlin/com/example/demo/DemoApplicationTests.kt");
|
||||
@ -89,8 +88,7 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
description.setPackaging(new WarPackaging());
|
||||
description.setApplicationName("KotlinDemoApplication");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/kotlin/com/example/demo/ServletInitializer.kt");
|
||||
List<String> lines = projectStructure
|
||||
.readAllLines("src/main/kotlin/com/example/demo/ServletInitializer.kt");
|
||||
|
@ -23,6 +23,7 @@ import io.spring.initializr.generator.project.ProjectDescription;
|
||||
import io.spring.initializr.generator.spring.scm.git.GitIgnoreCustomizer;
|
||||
import io.spring.initializr.generator.spring.test.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.generator.test.project.ProjectAssetTester;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.metadata.Link;
|
||||
@ -70,9 +71,9 @@ class HelpDocumentProjectGenerationConfigurationTests {
|
||||
this.metadataBuilder.addDependencyGroup("test", dependency);
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.addDependency("example", null);
|
||||
assertThat(
|
||||
this.projectTester.generate(description).getRelativePathsOfProjectFiles())
|
||||
.containsOnly("HELP.md");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.containsOnly("HELP.md");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -18,10 +18,10 @@ package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.io.IndentingWriter;
|
||||
import io.spring.initializr.generator.test.io.TextTestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -84,7 +84,7 @@ class KotlinDslGradleSettingsWriterTests {
|
||||
GradleSettingsWriter writer = new KotlinDslGradleSettingsWriter();
|
||||
StringWriter out = new StringWriter();
|
||||
writer.writeTo(new IndentingWriter(out), build);
|
||||
return Arrays.asList(out.toString().split("\\r?\\n"));
|
||||
return TextTestUtils.readAllLines(out.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,12 +18,12 @@ package io.spring.initializr.generator.project;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
import io.spring.initializr.generator.project.contributor.ProjectContributor;
|
||||
import io.spring.initializr.generator.test.project.ProjectGeneratorTester;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.generator.version.Version;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@ -101,9 +101,9 @@ class ProjectGeneratorTests {
|
||||
Files.createFile(subDir.resolve("Test.src"));
|
||||
});
|
||||
});
|
||||
List<String> relativePaths = tester.generate(new ProjectDescription())
|
||||
.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).containsOnly("test.text", "src/main/test/Test.src");
|
||||
ProjectStructure projectStructure = tester.generate(new ProjectDescription());
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.containsOnly("test.text", "src/main/test/Test.src");
|
||||
}
|
||||
|
||||
private static class TestProjectDescriptionCustomizer
|
||||
|
Loading…
Reference in New Issue
Block a user