mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-26 13:43:15 +08:00
Generated code should have only one newline at the end
Fixes gh-828
This commit is contained in:
@@ -16,9 +16,12 @@
|
||||
|
||||
package io.spring.initializr.generator.spring.code.groovy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
@@ -33,6 +36,8 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -71,7 +76,7 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
.contains("src/test/groovy/com/example/demo/DemoApplicationTests.groovy");
|
||||
List<String> lines = Files.readAllLines(projectStructure
|
||||
List<String> lines = readAllLines(projectStructure
|
||||
.resolve("src/test/groovy/com/example/demo/DemoApplicationTests.groovy"));
|
||||
assertThat(lines).containsExactly("package com.example.demo", "",
|
||||
"import org.junit.Test", "import org.junit.runner.RunWith",
|
||||
@@ -79,7 +84,7 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
"import org.springframework.test.context.junit4.SpringRunner", "",
|
||||
"@RunWith(SpringRunner)", "@SpringBootTest",
|
||||
"class DemoApplicationTests {", "", " @Test",
|
||||
" void contextLoads() {", " }", "", "}", "");
|
||||
" void contextLoads() {", " }", "", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,7 +97,7 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
.contains("src/main/groovy/com/example/demo/ServletInitializer.groovy");
|
||||
List<String> lines = Files.readAllLines(projectStructure
|
||||
List<String> lines = readAllLines(projectStructure
|
||||
.resolve("src/main/groovy/com/example/demo/ServletInitializer.groovy"));
|
||||
assertThat(lines).containsExactly("package com.example.demo", "",
|
||||
"import org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
@@ -100,7 +105,15 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
"", "class ServletInitializer extends SpringBootServletInitializer {", "",
|
||||
" @Override",
|
||||
" protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {",
|
||||
" application.sources(Demo2Application)", " }", "", "}", "");
|
||||
" application.sources(Demo2Application)", " }", "", "}");
|
||||
}
|
||||
|
||||
private static List<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 Arrays.asList(lines);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
package io.spring.initializr.generator.spring.code.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
@@ -33,6 +36,8 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -72,7 +77,7 @@ class JavaProjectGenerationConfigurationTests {
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
.contains("src/test/java/com/example/demo/DemoApplicationTests.java");
|
||||
List<String> lines = Files.readAllLines(projectStructure
|
||||
List<String> lines = readAllLines(projectStructure
|
||||
.resolve("src/test/java/com/example/demo/DemoApplicationTests.java"));
|
||||
assertThat(lines).containsExactly("package com.example.demo;", "",
|
||||
"import org.junit.Test;", "import org.junit.runner.RunWith;",
|
||||
@@ -80,7 +85,7 @@ class JavaProjectGenerationConfigurationTests {
|
||||
"import org.springframework.test.context.junit4.SpringRunner;", "",
|
||||
"@RunWith(SpringRunner.class)", "@SpringBootTest",
|
||||
"public class DemoApplicationTests {", "", " @Test",
|
||||
" public void contextLoads() {", " }", "", "}", "");
|
||||
" public void contextLoads() {", " }", "", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,7 +98,7 @@ class JavaProjectGenerationConfigurationTests {
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
.contains("src/main/java/com/example/demo/ServletInitializer.java");
|
||||
List<String> lines = Files.readAllLines(projectStructure
|
||||
List<String> lines = readAllLines(projectStructure
|
||||
.resolve("src/main/java/com/example/demo/ServletInitializer.java"));
|
||||
assertThat(lines).containsExactly("package com.example.demo;", "",
|
||||
"import org.springframework.boot.builder.SpringApplicationBuilder;",
|
||||
@@ -103,7 +108,7 @@ class JavaProjectGenerationConfigurationTests {
|
||||
"", " @Override",
|
||||
" protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {",
|
||||
" return application.sources(MyDemoApplication.class);", " }",
|
||||
"", "}", "");
|
||||
"", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,4 +133,12 @@ class JavaProjectGenerationConfigurationTests {
|
||||
"src/test/java/com/example/demo/MyApplicationTests.java");
|
||||
}
|
||||
|
||||
private static List<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 Arrays.asList(lines);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
package io.spring.initializr.generator.spring.code.kotlin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
@@ -33,6 +36,8 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -74,7 +79,7 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
.contains("src/test/kotlin/com/example/demo/DemoApplicationTests.kt");
|
||||
List<String> lines = Files.readAllLines(projectStructure
|
||||
List<String> lines = readAllLines(projectStructure
|
||||
.resolve("src/test/kotlin/com/example/demo/DemoApplicationTests.kt"));
|
||||
assertThat(lines).containsExactly("package com.example.demo", "",
|
||||
"import org.junit.Test", "import org.junit.runner.RunWith",
|
||||
@@ -82,7 +87,7 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
"import org.springframework.test.context.junit4.SpringRunner", "",
|
||||
"@RunWith(SpringRunner::class)", "@SpringBootTest",
|
||||
"class DemoApplicationTests {", "", " @Test",
|
||||
" fun contextLoads() {", " }", "", "}", "");
|
||||
" fun contextLoads() {", " }", "", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +100,7 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths)
|
||||
.contains("src/main/kotlin/com/example/demo/ServletInitializer.kt");
|
||||
List<String> lines = Files.readAllLines(projectStructure
|
||||
List<String> lines = readAllLines(projectStructure
|
||||
.resolve("src/main/kotlin/com/example/demo/ServletInitializer.kt"));
|
||||
assertThat(lines).containsExactly("package com.example.demo", "",
|
||||
"import org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
@@ -103,7 +108,15 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
"", "class ServletInitializer : SpringBootServletInitializer() {", "",
|
||||
" override fun configure(application: SpringApplicationBuilder): SpringApplicationBuilder {",
|
||||
" return application.sources(KotlinDemoApplication::class.java)",
|
||||
" }", "", "}", "");
|
||||
" }", "", "}");
|
||||
}
|
||||
|
||||
private static List<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 Arrays.asList(lines);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,4 +11,3 @@ class DemoApplication {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ class MyProjectApplication {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ class ServletInitializer extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ class DemoApplication {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ class DemoApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ class DemoApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ class MyProjectApplication {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ class MyProjectApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ class ServletInitializer extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ public class DemoApplication {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ public class MyProjectApplication {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ public class ServletInitializer extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ public class DemoApplication {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ public class DemoApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ public class DemoApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ public class MyProjectApplication {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ public class MyProjectApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ public class ServletInitializer extends SpringBootServletInitializer {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,3 @@ class DemoApplication
|
||||
fun main(args: Array<String>) {
|
||||
SpringApplication.run(DemoApplication::class.java, *args)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,3 @@ class MyProjectApplication
|
||||
fun main(args: Array<String>) {
|
||||
SpringApplication.run(MyProjectApplication::class.java, *args)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,4 +10,3 @@ class ServletInitializer : SpringBootServletInitializer() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,3 @@ class DemoApplication
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<DemoApplication>(*args)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ class DemoApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ class DemoApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,3 @@ class MyProjectApplication
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<MyProjectApplication>(*args)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,3 @@ class MyProjectApplicationTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,4 +10,3 @@ class ServletInitializer : SpringBootServletInitializer() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user