From 5d7460a0f57bde123d8b4fd2b0c07363e7903902 Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Thu, 6 Jan 2022 10:32:33 +0100 Subject: [PATCH] Fix eol in MainApp --- src/main/java/tech/jhipster/lite/JHLiteApp.java | 15 ++++++++------- .../server/springboot/core/MainApp.java.mustache | 15 ++++++++------- .../springboot/core/MainAppIT.java.mustache | 11 ++++++----- src/test/java/tech/jhipster/lite/JHLiteAppIT.java | 11 ++++++----- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/JHLiteApp.java b/src/main/java/tech/jhipster/lite/JHLiteApp.java index 9dbe04a571d..04634c88158 100644 --- a/src/main/java/tech/jhipster/lite/JHLiteApp.java +++ b/src/main/java/tech/jhipster/lite/JHLiteApp.java @@ -17,6 +17,7 @@ public class JHLiteApp { private static final Logger log = LoggerFactory.getLogger(JHLiteApp.class); private static final String SEPARATOR = "----------------------------------------------------------"; + protected static final String LF = "\n"; public static void main(String[] args) { SpringApplication app = new SpringApplication(JHLiteApp.class); @@ -31,9 +32,9 @@ private static void logApplicationStartup(Environment env) { String hostAddress = getHostAddress(); String welcomeMessage = new StringBuilder() - .append("\n") + .append(LF) .append(SEPARATOR) - .append("\n") + .append(LF) .append(applicationRunning(env.getProperty("spring.application.name"))) .append(accessUrlLocal(protocol, serverPort, contextPath)) .append(accessUrlExternal(protocol, hostAddress, serverPort, contextPath)) @@ -46,32 +47,32 @@ private static void logApplicationStartup(Environment env) { } public static String applicationRunning(String value) { - return String.format(" Application '%s' is running!", value) + "\n"; + return String.format(" Application '%s' is running!", value) + LF; } public static String accessUrlLocal(String protocol, String serverPort, String contextPath) { if (StringUtils.isBlank(serverPort)) { return ""; } - return String.format(" Local: \t%s://localhost:%s%sswagger-ui.html", protocol, serverPort, contextPath) + "\n"; + return String.format(" Local: \t%s://localhost:%s%sswagger-ui.html", protocol, serverPort, contextPath) + LF; } public static String accessUrlExternal(String protocol, String hostAddress, String serverPort, String contextPath) { if (StringUtils.isBlank(serverPort)) { return ""; } - return String.format(" External: \t%s://%s:%s%sswagger-ui.html", protocol, hostAddress, serverPort, contextPath) + "\n"; + return String.format(" External: \t%s://%s:%s%sswagger-ui.html", protocol, hostAddress, serverPort, contextPath) + LF; } public static String profile(String profiles) { - return String.format(" Profile(s): \t%s", profiles) + "\n"; + return String.format(" Profile(s): \t%s", profiles) + LF; } public static String configServer(String configServerStatus) { if (StringUtils.isBlank(configServerStatus)) { return ""; } - return "\n" + String.format(" Config Server: %s", configServerStatus) + "\n" + SEPARATOR + "\n"; + return LF + String.format(" Config Server: %s", configServerStatus) + LF + SEPARATOR + LF; } public static String getProtocol(String value) { diff --git a/src/main/resources/generator/server/springboot/core/MainApp.java.mustache b/src/main/resources/generator/server/springboot/core/MainApp.java.mustache index 292e112a4ec..6812806f1a3 100644 --- a/src/main/resources/generator/server/springboot/core/MainApp.java.mustache +++ b/src/main/resources/generator/server/springboot/core/MainApp.java.mustache @@ -17,6 +17,7 @@ public class {{mainClass}}App { private static final Logger log = LoggerFactory.getLogger({{mainClass}}App.class); private static final String SEPARATOR = "----------------------------------------------------------"; + protected static final String LF = "\n"; public static void main(String[] args) { SpringApplication app = new SpringApplication({{mainClass}}App.class); @@ -31,9 +32,9 @@ public class {{mainClass}}App { String hostAddress = getHostAddress(); String welcomeMessage = new StringBuilder() - .append("\n") + .append(LF) .append(SEPARATOR) - .append("\n") + .append(LF) .append(applicationRunning(env.getProperty("spring.application.name"))) .append(accessUrlLocal(protocol, serverPort, contextPath)) .append(accessUrlExternal(protocol, hostAddress, serverPort, contextPath)) @@ -46,32 +47,32 @@ public class {{mainClass}}App { } public static String applicationRunning(String value) { - return String.format(" Application '%s' is running!", value) + "\n"; + return String.format(" Application '%s' is running!", value) + LF; } public static String accessUrlLocal(String protocol, String serverPort, String contextPath) { if (StringUtils.isBlank(serverPort)) { return ""; } - return String.format(" Local: \t%s://localhost:%s%s", protocol, serverPort, contextPath) + "\n"; + return String.format(" Local: \t%s://localhost:%s%s", protocol, serverPort, contextPath) + LF; } public static String accessUrlExternal(String protocol, String hostAddress, String serverPort, String contextPath) { if (StringUtils.isBlank(serverPort)) { return ""; } - return String.format(" External: \t%s://%s:%s%s", protocol, hostAddress, serverPort, contextPath) + "\n"; + return String.format(" External: \t%s://%s:%s%s", protocol, hostAddress, serverPort, contextPath) + LF; } public static String profile(String profiles) { - return String.format(" Profile(s): \t%s", profiles) + "\n"; + return String.format(" Profile(s): \t%s", profiles) + LF; } public static String configServer(String configServerStatus) { if (StringUtils.isBlank(configServerStatus)) { return ""; } - return "\n" + String.format(" Config Server: %s", configServerStatus) + "\n" + SEPARATOR + "\n"; + return LF + String.format(" Config Server: %s", configServerStatus) + LF + SEPARATOR + LF; } public static String getProtocol(String value) { diff --git a/src/main/resources/generator/server/springboot/core/MainAppIT.java.mustache b/src/main/resources/generator/server/springboot/core/MainAppIT.java.mustache index 8a88453db83..3e2c7c4bbaa 100644 --- a/src/main/resources/generator/server/springboot/core/MainAppIT.java.mustache +++ b/src/main/resources/generator/server/springboot/core/MainAppIT.java.mustache @@ -2,6 +2,7 @@ package {{packageName}}; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; +import static {{packageName}}.{{mainClass}}App.LF; import java.net.InetAddress; import java.net.UnknownHostException; @@ -20,7 +21,7 @@ class {{mainClass}}AppIT { @Test void shouldApplicationRunning() { String result = {{mainClass}}App.applicationRunning("jhlite"); - assertThat(result).isEqualTo(" Application 'jhlite' is running!\n"); + assertThat(result).isEqualTo(" Application 'jhlite' is running!" + LF); } @Test @@ -32,13 +33,13 @@ class {{mainClass}}AppIT { @Test void shouldAccessUrlLocalWithoutContextPath() { String result = {{mainClass}}App.accessUrlLocal("http", "8080", "/"); - assertThat(result).isEqualTo(" Local: \thttp://localhost:8080/\n"); + assertThat(result).isEqualTo(" Local: \thttp://localhost:8080/" + LF); } @Test void shouldAccessUrlLocalWithContextPath() { String result = {{mainClass}}App.accessUrlLocal("http", "8080", "/lite/"); - assertThat(result).isEqualTo(" Local: \thttp://localhost:8080/lite/\n"); + assertThat(result).isEqualTo(" Local: \thttp://localhost:8080/lite/" + LF); } @Test @@ -50,13 +51,13 @@ class {{mainClass}}AppIT { @Test void shouldAccessUrlExternalWithoutContextPath() { String result = {{mainClass}}App.accessUrlExternal("http", "127.0.1.1", "8080", "/"); - assertThat(result).isEqualTo(" External: \thttp://127.0.1.1:8080/\n"); + assertThat(result).isEqualTo(" External: \thttp://127.0.1.1:8080/" + LF); } @Test void shouldAccessUrlExternalWithContextPath() { String result = {{mainClass}}App.accessUrlExternal("http", "127.0.1.1", "8080", "/lite/"); - assertThat(result).isEqualTo(" External: \thttp://127.0.1.1:8080/lite/\n"); + assertThat(result).isEqualTo(" External: \thttp://127.0.1.1:8080/lite/" + LF); } @Test diff --git a/src/test/java/tech/jhipster/lite/JHLiteAppIT.java b/src/test/java/tech/jhipster/lite/JHLiteAppIT.java index 95700c89dc7..ff45fa31be3 100644 --- a/src/test/java/tech/jhipster/lite/JHLiteAppIT.java +++ b/src/test/java/tech/jhipster/lite/JHLiteAppIT.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; +import static tech.jhipster.lite.JHLiteApp.LF; import java.net.InetAddress; import java.net.UnknownHostException; @@ -20,7 +21,7 @@ void shouldMain() { @Test void shouldApplicationRunning() { String result = JHLiteApp.applicationRunning("jhlite"); - assertThat(result).isEqualTo(" Application 'jhlite' is running!\n"); + assertThat(result).isEqualTo(" Application 'jhlite' is running!" + LF); } @Test @@ -32,13 +33,13 @@ void shouldAccessUrlLocalWithoutServerPort() { @Test void shouldAccessUrlLocalWithoutContextPath() { String result = JHLiteApp.accessUrlLocal("http", "8080", "/"); - assertThat(result).isEqualTo(" Local: \thttp://localhost:8080/swagger-ui.html\n"); + assertThat(result).isEqualTo(" Local: \thttp://localhost:8080/swagger-ui.html" + LF); } @Test void shouldAccessUrlLocalWithContextPath() { String result = JHLiteApp.accessUrlLocal("http", "8080", "/lite/"); - assertThat(result).isEqualTo(" Local: \thttp://localhost:8080/lite/swagger-ui.html\n"); + assertThat(result).isEqualTo(" Local: \thttp://localhost:8080/lite/swagger-ui.html" + LF); } @Test @@ -50,13 +51,13 @@ void shouldAccessUrlExternalWithoutServerPort() { @Test void shouldAccessUrlExternalWithoutContextPath() { String result = JHLiteApp.accessUrlExternal("http", "127.0.1.1", "8080", "/"); - assertThat(result).isEqualTo(" External: \thttp://127.0.1.1:8080/swagger-ui.html\n"); + assertThat(result).isEqualTo(" External: \thttp://127.0.1.1:8080/swagger-ui.html" + LF); } @Test void shouldAccessUrlExternalWithContextPath() { String result = JHLiteApp.accessUrlExternal("http", "127.0.1.1", "8080", "/lite/"); - assertThat(result).isEqualTo(" External: \thttp://127.0.1.1:8080/lite/swagger-ui.html\n"); + assertThat(result).isEqualTo(" External: \thttp://127.0.1.1:8080/lite/swagger-ui.html" + LF); } @Test