Use System.lineSeparator()
See gh-11665
This commit is contained in:
committed by
Stephane Nicoll
parent
7002507304
commit
d8c83af987
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user