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 {
private static final String NEW_LINE = System.getProperty("line.separator");
private final InitializrService initializrService;
/**
@ -66,29 +64,29 @@ class ServiceCapabilitiesReportGenerator {
private String generateHelp(String url, InitializrServiceMetadata metadata) {
String header = "Capabilities of " + url;
StringBuilder report = new StringBuilder();
report.append(repeat("=", header.length()) + NEW_LINE);
report.append(header + NEW_LINE);
report.append(repeat("=", header.length()) + NEW_LINE);
report.append(NEW_LINE);
report.append(repeat("=", header.length()) + System.lineSeparator());
report.append(header + System.lineSeparator());
report.append(repeat("=", header.length()) + System.lineSeparator());
report.append(System.lineSeparator());
reportAvailableDependencies(metadata, report);
report.append(NEW_LINE);
report.append(System.lineSeparator());
reportAvailableProjectTypes(metadata, report);
report.append(NEW_LINE);
report.append(System.lineSeparator());
reportDefaults(report, metadata);
return report.toString();
}
private void reportAvailableDependencies(InitializrServiceMetadata metadata,
StringBuilder report) {
report.append("Available dependencies:" + NEW_LINE);
report.append("-----------------------" + NEW_LINE);
report.append("Available dependencies:" + System.lineSeparator());
report.append("-----------------------" + System.lineSeparator());
List<Dependency> dependencies = getSortedDependencies(metadata);
for (Dependency dependency : dependencies) {
report.append(dependency.getId() + " - " + dependency.getName());
if (dependency.getDescription() != null) {
report.append(": " + dependency.getDescription());
}
report.append(NEW_LINE);
report.append(System.lineSeparator());
}
}
@ -100,8 +98,8 @@ class ServiceCapabilitiesReportGenerator {
private void reportAvailableProjectTypes(InitializrServiceMetadata metadata,
StringBuilder report) {
report.append("Available project types:" + NEW_LINE);
report.append("------------------------" + NEW_LINE);
report.append("Available project types:" + System.lineSeparator());
report.append("------------------------" + System.lineSeparator());
SortedSet<Entry<String, ProjectType>> entries = new TreeSet<>(
Comparator.comparing(Entry::getKey));
entries.addAll(metadata.getProjectTypes().entrySet());
@ -114,7 +112,7 @@ class ServiceCapabilitiesReportGenerator {
if (type.isDefaultType()) {
report.append(" (default)");
}
report.append(NEW_LINE);
report.append(System.lineSeparator());
}
}
@ -134,13 +132,13 @@ class ServiceCapabilitiesReportGenerator {
private void reportDefaults(StringBuilder report,
InitializrServiceMetadata metadata) {
report.append("Defaults:" + NEW_LINE);
report.append("---------" + NEW_LINE);
report.append("Defaults:" + System.lineSeparator());
report.append("---------" + System.lineSeparator());
List<String> defaultsKeys = new ArrayList<>(metadata.getDefaults().keySet());
Collections.sort(defaultsKeys);
for (String defaultsKey : defaultsKeys) {
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 {
private static final String NEW_LINE = System.getProperty("line.separator");
public String getShortDescription(String description) {
if (description == null) {
return null;
@ -41,13 +39,13 @@ class DescriptionExtractor {
return removeSpaceBetweenLine(text);
}
else {
String[] lines = description.split(NEW_LINE);
String[] lines = description.split(System.lineSeparator());
return lines[0].trim();
}
}
private String removeSpaceBetweenLine(String text) {
String[] lines = text.split(NEW_LINE);
String[] lines = text.split(System.lineSeparator());
StringBuilder sb = new StringBuilder();
for (String line : lines) {
sb.append(line.trim()).append(" ");

@ -27,8 +27,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class DescriptionExtractorTests {
private static final String NEW_LINE = System.getProperty("line.separator");
private DescriptionExtractor extractor = new DescriptionExtractor();
@Test
@ -41,14 +39,14 @@ public class DescriptionExtractorTests {
@Test
public void extractShortDescriptionNewLineBeforeDot() {
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.");
}
@Test
public void extractShortDescriptionNewLineBeforeDotWithSpaces() {
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.");
}
@ -61,7 +59,7 @@ public class DescriptionExtractorTests {
@Test
public void extractShortDescriptionNoDotMultipleLines() {
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");
}

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

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

@ -30,8 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class ExtendedWhitespaceThrowableProxyConverterTests {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final ExtendedWhitespaceThrowableProxyConverter converter = new ExtendedWhitespaceThrowableProxyConverter();
private final LoggingEvent event = new LoggingEvent();
@ -46,7 +44,7 @@ public class ExtendedWhitespaceThrowableProxyConverterTests {
public void withStackTrace() {
this.event.setThrowableProxy(new ThrowableProxy(new RuntimeException()));
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 {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final WhitespaceThrowableProxyConverter converter = new WhitespaceThrowableProxyConverter();
private final LoggingEvent event = new LoggingEvent();
@ -46,7 +44,7 @@ public class WhitespaceThrowableProxyConverterTests {
public void withStackTrace() {
this.event.setThrowableProxy(new ThrowableProxy(new RuntimeException()));
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