Use System.lineSeparator()

See gh-11665
pull/11680/head
Johnny Lim 7 years ago committed by Stephane Nicoll
parent 7002507304
commit d8c83af987

@ -36,8 +36,6 @@ import java.util.TreeSet;
*/ */
class ServiceCapabilitiesReportGenerator { class ServiceCapabilitiesReportGenerator {
private static final String NEW_LINE = System.getProperty("line.separator");
private final InitializrService initializrService; private final InitializrService initializrService;
/** /**
@ -66,29 +64,29 @@ class ServiceCapabilitiesReportGenerator {
private String generateHelp(String url, InitializrServiceMetadata metadata) { private String generateHelp(String url, InitializrServiceMetadata metadata) {
String header = "Capabilities of " + url; String header = "Capabilities of " + url;
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
report.append(repeat("=", header.length()) + NEW_LINE); report.append(repeat("=", header.length()) + System.lineSeparator());
report.append(header + NEW_LINE); report.append(header + System.lineSeparator());
report.append(repeat("=", header.length()) + NEW_LINE); report.append(repeat("=", header.length()) + System.lineSeparator());
report.append(NEW_LINE); report.append(System.lineSeparator());
reportAvailableDependencies(metadata, report); reportAvailableDependencies(metadata, report);
report.append(NEW_LINE); report.append(System.lineSeparator());
reportAvailableProjectTypes(metadata, report); reportAvailableProjectTypes(metadata, report);
report.append(NEW_LINE); report.append(System.lineSeparator());
reportDefaults(report, metadata); reportDefaults(report, metadata);
return report.toString(); return report.toString();
} }
private void reportAvailableDependencies(InitializrServiceMetadata metadata, private void reportAvailableDependencies(InitializrServiceMetadata metadata,
StringBuilder report) { StringBuilder report) {
report.append("Available dependencies:" + NEW_LINE); report.append("Available dependencies:" + System.lineSeparator());
report.append("-----------------------" + NEW_LINE); report.append("-----------------------" + System.lineSeparator());
List<Dependency> dependencies = getSortedDependencies(metadata); List<Dependency> dependencies = getSortedDependencies(metadata);
for (Dependency dependency : dependencies) { for (Dependency dependency : dependencies) {
report.append(dependency.getId() + " - " + dependency.getName()); report.append(dependency.getId() + " - " + dependency.getName());
if (dependency.getDescription() != null) { if (dependency.getDescription() != null) {
report.append(": " + dependency.getDescription()); report.append(": " + dependency.getDescription());
} }
report.append(NEW_LINE); report.append(System.lineSeparator());
} }
} }
@ -100,8 +98,8 @@ class ServiceCapabilitiesReportGenerator {
private void reportAvailableProjectTypes(InitializrServiceMetadata metadata, private void reportAvailableProjectTypes(InitializrServiceMetadata metadata,
StringBuilder report) { StringBuilder report) {
report.append("Available project types:" + NEW_LINE); report.append("Available project types:" + System.lineSeparator());
report.append("------------------------" + NEW_LINE); report.append("------------------------" + System.lineSeparator());
SortedSet<Entry<String, ProjectType>> entries = new TreeSet<>( SortedSet<Entry<String, ProjectType>> entries = new TreeSet<>(
Comparator.comparing(Entry::getKey)); Comparator.comparing(Entry::getKey));
entries.addAll(metadata.getProjectTypes().entrySet()); entries.addAll(metadata.getProjectTypes().entrySet());
@ -114,7 +112,7 @@ class ServiceCapabilitiesReportGenerator {
if (type.isDefaultType()) { if (type.isDefaultType()) {
report.append(" (default)"); report.append(" (default)");
} }
report.append(NEW_LINE); report.append(System.lineSeparator());
} }
} }
@ -134,13 +132,13 @@ class ServiceCapabilitiesReportGenerator {
private void reportDefaults(StringBuilder report, private void reportDefaults(StringBuilder report,
InitializrServiceMetadata metadata) { InitializrServiceMetadata metadata) {
report.append("Defaults:" + NEW_LINE); report.append("Defaults:" + System.lineSeparator());
report.append("---------" + NEW_LINE); report.append("---------" + System.lineSeparator());
List<String> defaultsKeys = new ArrayList<>(metadata.getDefaults().keySet()); List<String> defaultsKeys = new ArrayList<>(metadata.getDefaults().keySet());
Collections.sort(defaultsKeys); Collections.sort(defaultsKeys);
for (String defaultsKey : defaultsKeys) { for (String defaultsKey : defaultsKeys) {
String defaultsValue = metadata.getDefaults().get(defaultsKey); String defaultsValue = metadata.getDefaults().get(defaultsKey);
report.append(defaultsKey + ": " + defaultsValue + NEW_LINE); report.append(defaultsKey + ": " + defaultsValue + System.lineSeparator());
} }
} }

@ -26,8 +26,6 @@ import java.util.Locale;
*/ */
class DescriptionExtractor { class DescriptionExtractor {
private static final String NEW_LINE = System.getProperty("line.separator");
public String getShortDescription(String description) { public String getShortDescription(String description) {
if (description == null) { if (description == null) {
return null; return null;
@ -41,13 +39,13 @@ class DescriptionExtractor {
return removeSpaceBetweenLine(text); return removeSpaceBetweenLine(text);
} }
else { else {
String[] lines = description.split(NEW_LINE); String[] lines = description.split(System.lineSeparator());
return lines[0].trim(); return lines[0].trim();
} }
} }
private String removeSpaceBetweenLine(String text) { private String removeSpaceBetweenLine(String text) {
String[] lines = text.split(NEW_LINE); String[] lines = text.split(System.lineSeparator());
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (String line : lines) { for (String line : lines) {
sb.append(line.trim()).append(" "); sb.append(line.trim()).append(" ");

@ -27,8 +27,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class DescriptionExtractorTests { public class DescriptionExtractorTests {
private static final String NEW_LINE = System.getProperty("line.separator");
private DescriptionExtractor extractor = new DescriptionExtractor(); private DescriptionExtractor extractor = new DescriptionExtractor();
@Test @Test
@ -41,14 +39,14 @@ public class DescriptionExtractorTests {
@Test @Test
public void extractShortDescriptionNewLineBeforeDot() { public void extractShortDescriptionNewLineBeforeDot() {
String description = this.extractor.getShortDescription( String description = this.extractor.getShortDescription(
"My short" + NEW_LINE + "description." + NEW_LINE + "More stuff."); "My short" + System.lineSeparator() + "description." + System.lineSeparator() + "More stuff.");
assertThat(description).isEqualTo("My short description."); assertThat(description).isEqualTo("My short description.");
} }
@Test @Test
public void extractShortDescriptionNewLineBeforeDotWithSpaces() { public void extractShortDescriptionNewLineBeforeDotWithSpaces() {
String description = this.extractor.getShortDescription( String description = this.extractor.getShortDescription(
"My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff."); "My short " + System.lineSeparator() + " description. " + System.lineSeparator() + "More stuff.");
assertThat(description).isEqualTo("My short description."); assertThat(description).isEqualTo("My short description.");
} }
@ -61,7 +59,7 @@ public class DescriptionExtractorTests {
@Test @Test
public void extractShortDescriptionNoDotMultipleLines() { public void extractShortDescriptionNoDotMultipleLines() {
String description = this.extractor String description = this.extractor
.getShortDescription("My short description " + NEW_LINE + " More stuff"); .getShortDescription("My short description " + System.lineSeparator() + " More stuff");
assertThat(description).isEqualTo("My short description"); assertThat(description).isEqualTo("My short description");
} }

@ -42,8 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class ImageBannerTests { public class ImageBannerTests {
private static final String NEW_LINE = System.getProperty("line.separator");
private static final char HIGH_LUMINANCE_CHARACTER = ' '; private static final char HIGH_LUMINANCE_CHARACTER = ' ';
private static final char LOW_LUMINANCE_CHARACTER = '@'; private static final char LOW_LUMINANCE_CHARACTER = '@';
@ -149,7 +147,7 @@ public class ImageBannerTests {
public void printBannerShouldPrintMargin() { public void printBannerShouldPrintMargin() {
AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER);
String banner = printBanner("large.gif"); String banner = printBanner("large.gif");
String[] lines = banner.split(NEW_LINE); String[] lines = banner.split(System.lineSeparator());
for (int i = 2; i < lines.length - 1; i++) { for (int i = 2; i < lines.length - 1; i++) {
assertThat(lines[i]).startsWith(" @"); assertThat(lines[i]).startsWith(" @");
} }
@ -159,7 +157,7 @@ public class ImageBannerTests {
public void printBannerWhenHasMarginPropertyShouldPrintSizedMargin() { public void printBannerWhenHasMarginPropertyShouldPrintSizedMargin() {
AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER);
String banner = printBanner("large.gif", "spring.banner.image.margin=4"); String banner = printBanner("large.gif", "spring.banner.image.margin=4");
String[] lines = banner.split(NEW_LINE); String[] lines = banner.split(System.lineSeparator());
for (int i = 2; i < lines.length - 1; i++) { for (int i = 2; i < lines.length - 1; i++) {
assertThat(lines[i]).startsWith(" @"); assertThat(lines[i]).startsWith(" @");
} }
@ -169,7 +167,7 @@ public class ImageBannerTests {
public void printBannerWhenAnimatesShouldPrintAllFrames() { public void printBannerWhenAnimatesShouldPrintAllFrames() {
AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER); AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER);
String banner = printBanner("animated.gif"); String banner = printBanner("animated.gif");
String[] lines = banner.split(NEW_LINE); String[] lines = banner.split(System.lineSeparator());
int frames = 138; int frames = 138;
int linesPerFrame = 36; int linesPerFrame = 36;
assertThat(banner).contains("\r"); assertThat(banner).contains("\r");
@ -177,12 +175,12 @@ public class ImageBannerTests {
} }
private int getBannerHeight(String banner) { private int getBannerHeight(String banner) {
return banner.split(NEW_LINE).length - 3; return banner.split(System.lineSeparator()).length - 3;
} }
private int getBannerWidth(String banner) { private int getBannerWidth(String banner) {
int width = 0; int width = 0;
for (String line : banner.split(NEW_LINE)) { for (String line : banner.split(System.lineSeparator())) {
width = Math.max(width, line.length()); width = Math.max(width, line.length());
} }
return width; return width;

@ -32,8 +32,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class ExtendedWhitespaceThrowablePatternConverterTests { public class ExtendedWhitespaceThrowablePatternConverterTests {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final ThrowablePatternConverter converter = ExtendedWhitespaceThrowablePatternConverter private final ThrowablePatternConverter converter = ExtendedWhitespaceThrowablePatternConverter
.newInstance(new DefaultConfiguration(), new String[] {}); .newInstance(new DefaultConfiguration(), new String[] {});
@ -50,7 +48,7 @@ public class ExtendedWhitespaceThrowablePatternConverterTests {
LogEvent event = Log4jLogEvent.newBuilder().setThrown(new Exception()).build(); LogEvent event = Log4jLogEvent.newBuilder().setThrown(new Exception()).build();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
this.converter.format(event, builder); this.converter.format(event, builder);
assertThat(builder).startsWith(LINE_SEPARATOR).endsWith(LINE_SEPARATOR); assertThat(builder).startsWith(System.lineSeparator()).endsWith(System.lineSeparator());
} }
} }

@ -31,8 +31,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class WhitespaceThrowablePatternConverterTests { public class WhitespaceThrowablePatternConverterTests {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final ThrowablePatternConverter converter = WhitespaceThrowablePatternConverter private final ThrowablePatternConverter converter = WhitespaceThrowablePatternConverter
.newInstance(new DefaultConfiguration(), new String[] {}); .newInstance(new DefaultConfiguration(), new String[] {});
@ -49,8 +47,8 @@ public class WhitespaceThrowablePatternConverterTests {
LogEvent event = Log4jLogEvent.newBuilder().setThrown(new Exception()).build(); LogEvent event = Log4jLogEvent.newBuilder().setThrown(new Exception()).build();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
this.converter.format(event, builder); this.converter.format(event, builder);
assertThat(builder.toString()).startsWith(LINE_SEPARATOR) assertThat(builder.toString()).startsWith(System.lineSeparator())
.endsWith(LINE_SEPARATOR); .endsWith(System.lineSeparator());
} }
} }

@ -30,8 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class ExtendedWhitespaceThrowableProxyConverterTests { public class ExtendedWhitespaceThrowableProxyConverterTests {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final ExtendedWhitespaceThrowableProxyConverter converter = new ExtendedWhitespaceThrowableProxyConverter(); private final ExtendedWhitespaceThrowableProxyConverter converter = new ExtendedWhitespaceThrowableProxyConverter();
private final LoggingEvent event = new LoggingEvent(); private final LoggingEvent event = new LoggingEvent();
@ -46,7 +44,7 @@ public class ExtendedWhitespaceThrowableProxyConverterTests {
public void withStackTrace() { public void withStackTrace() {
this.event.setThrowableProxy(new ThrowableProxy(new RuntimeException())); this.event.setThrowableProxy(new ThrowableProxy(new RuntimeException()));
String s = this.converter.convert(this.event); String s = this.converter.convert(this.event);
assertThat(s).startsWith(LINE_SEPARATOR).endsWith(LINE_SEPARATOR); assertThat(s).startsWith(System.lineSeparator()).endsWith(System.lineSeparator());
} }
} }

@ -30,8 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class WhitespaceThrowableProxyConverterTests { public class WhitespaceThrowableProxyConverterTests {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final WhitespaceThrowableProxyConverter converter = new WhitespaceThrowableProxyConverter(); private final WhitespaceThrowableProxyConverter converter = new WhitespaceThrowableProxyConverter();
private final LoggingEvent event = new LoggingEvent(); private final LoggingEvent event = new LoggingEvent();
@ -46,7 +44,7 @@ public class WhitespaceThrowableProxyConverterTests {
public void withStackTrace() { public void withStackTrace() {
this.event.setThrowableProxy(new ThrowableProxy(new RuntimeException())); this.event.setThrowableProxy(new ThrowableProxy(new RuntimeException()));
String s = this.converter.convert(this.event); String s = this.converter.convert(this.event);
assertThat(s).startsWith(LINE_SEPARATOR).endsWith(LINE_SEPARATOR); assertThat(s).startsWith(System.lineSeparator()).endsWith(System.lineSeparator());
} }
} }

Loading…
Cancel
Save