Java-20326: Changes made for replacing strSubstitutor with stringSubstitutor (#14301)
This commit is contained in:
parent
69fe2bb1ae
commit
dad0e8cf5e
|
@ -29,6 +29,11 @@
|
|||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${apache-commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>${apache-commons-text.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
|
@ -56,6 +61,7 @@
|
|||
<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>
|
||||
<apache-commons-text.version>1.10.0</apache-commons-text.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.namedformatting;
|
||||
|
||||
import org.apache.commons.text.StrSubstitutor;
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -12,20 +12,20 @@ class NamedFormatterUnitTest {
|
|||
private static final String TEMPLATE = "Text: [${text}] Number: [${number}] Text again: [${text}]";
|
||||
|
||||
@Test
|
||||
void givenTemplateWithNamedParam_whenCallingCommonsTextStrSubstitutor_shouldGetExpectedResult() {
|
||||
void givenTemplateWithNamedParam_whenCallingCommonsTextStringSubstitutor_shouldGetExpectedResult() {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("text", "It's awesome!");
|
||||
params.put("number", 42);
|
||||
String result = StrSubstitutor.replace(TEMPLATE, params, "${", "}");
|
||||
String result = StringSubstitutor.replace(TEMPLATE, params, "${", "}");
|
||||
assertThat(result).isEqualTo("Text: [It's awesome!] Number: [42] Text again: [It's awesome!]");
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTemplateWithNamedParam_whenCallingCommonsTextStrSubstitutorWithParameterNames_shouldNotWorkAsExpected() {
|
||||
void givenTemplateWithNamedParam_whenCallingCommonsTextStringSubstitutorWithParameterNames_shouldNotWorkAsExpected() {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("text", "'${number}' is a placeholder.");
|
||||
params.put("number", 42);
|
||||
String result = StrSubstitutor.replace(TEMPLATE, params, "${", "}");
|
||||
String result = StringSubstitutor.replace(TEMPLATE, params, "${", "}");
|
||||
|
||||
assertThat(result).isNotEqualTo("Text: ['${number}' is a placeholder.] Number: [42] Text again: ['${number}' is a placeholder.]");
|
||||
|
||||
|
|
Loading…
Reference in New Issue