BAEL-5193 Compare strings while ignoring whitespace (#11455)
* BAEL-5193-compare-strings-ignoring-whitespace * refactor * refactor Co-authored-by: tienvn4 <tienvn4@ghtk.co>
This commit is contained in:
parent
676f458032
commit
66311a52d3
|
@ -32,6 +32,16 @@
|
|||
<artifactId>opencsv</artifactId>
|
||||
<version>${opencsv.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${apache-commons-lang3.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -53,6 +63,8 @@
|
|||
<assertj.version>3.6.1</assertj.version>
|
||||
<guava.version>31.0.1-jre</guava.version>
|
||||
<opencsv.version>4.1</opencsv.version>
|
||||
<spring-core.version>5.3.13</spring-core.version>
|
||||
<apache-commons-lang3.version>3.12.0</apache-commons-lang3.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.comparestrings;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CompareIgnoreSpacesUnitTest {
|
||||
|
||||
private static String normalString = "ABCDEF";
|
||||
private static String stringWithSpaces = " AB CD EF ";
|
||||
|
||||
@Test
|
||||
public void givenTwoStrings_thenCompareWithReplaceAllMethod() {
|
||||
assertEquals(normalString.replaceAll("\\s+",""), stringWithSpaces.replaceAll("\\s+",""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoStrings_thenCompareWithApacheStringUtils() {
|
||||
assertEquals(StringUtils.deleteWhitespace(normalString), StringUtils.deleteWhitespace(stringWithSpaces));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoStrings_thenCompareWithSpringStringUtils() {
|
||||
assertEquals(org.springframework.util.StringUtils.trimAllWhitespace(normalString), org.springframework.util.StringUtils.trimAllWhitespace(stringWithSpaces));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue