[rm-trailing-space] rm trailing whithspace
This commit is contained in:
parent
bd36eddeca
commit
501c511e74
|
@ -12,6 +12,14 @@
|
||||||
<artifactId>core-java-modules</artifactId>
|
<artifactId>core-java-modules</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>${apache.commons.lang3.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -29,6 +37,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<apache.commons.lang3.version>3.14.0</apache.commons.lang3.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.baeldung.removetrailingspaces;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class RemoveTrailingSpaceOrWhitespaceUnitTest {
|
||||||
|
|
||||||
|
private final static String INPUT = " a b c d e \t ";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenUsingTrim_thenBothLeadingAndTrailingWhitespaceAreRemoved() {
|
||||||
|
String result = INPUT.trim();
|
||||||
|
assertEquals("a b c d e", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenUsingReplaceAll_thenGetExpectedResult() {
|
||||||
|
String result1 = INPUT.replaceAll(" +$", "");
|
||||||
|
assertEquals(" a b c d e \t", result1);
|
||||||
|
|
||||||
|
String result2 = INPUT.replaceAll("\\s+$", "");
|
||||||
|
assertEquals(" a b c d e", result2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenUsingStripTrailing_thenAllTrailingWhitespaceRemoved() {
|
||||||
|
String result = INPUT.stripTrailing();
|
||||||
|
assertEquals(" a b c d e", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenUsingStringUtilsStripEnd_thenTrailingSpaceRemoved() {
|
||||||
|
String result = StringUtils.stripEnd(INPUT, " ");
|
||||||
|
assertEquals(" a b c d e \t", result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue