- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringInterpolationTest.java
More file actions
Latest commit
79 lines (68 loc) · 2.65 KB
/
Copy pathStringInterpolationTest.java
File metadata and controls
79 lines (68 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
packagebasics;
importorg.apache.commons.text.StringSubstitutor;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.api.Test;
importjava.text.MessageFormat;
importjava.util.HashMap;
importjava.util.Map;
publicclassStringInterpolationTest {
@Test
publicvoidoperator_test() {
Stringexpected = "String Interpolation Test By Minseok";
Stringfirst = "Interpolation";
Stringsecond = "By";
Stringresult = "String " + first + " Test "+ second + " Minseok";
Assertions.assertEquals(expected, result);
}
@Test
publicvoidformat_test() {
Stringexpected = "String Interpolation Test By Minseok";
Stringfirst = "Interpolation";
Stringsecond = "By";
Stringresult = String.format("String %s Test %s Minseok", first, second);
Assertions.assertEquals(expected, result);
}
@Test
publicvoidformat_avoid_repeat_test() {
Stringexpected = "String Interpolation Test By Minseok By Baeldung";
Stringfirst = "Interpolation";
Stringsecond = "By";
Stringresult = String.format("String %1$s Test %2$s Minseok %2$s Baeldung", first, second);
Assertions.assertEquals(expected, result);
}
@Test
publicvoidbuilder_test() {
Stringexpected = "String Interpolation Test By Minseok";
Stringfirst = "Interpolation";
Stringsecond = "By";
Stringresult = newStringBuilder()
.append("String ")
.append(first)
.append(" Test ")
.append(second)
.append(" Minseok")
.toString();
Assertions.assertEquals(expected, result);
}
@Test
publicvoidmessageFormat_test() {
Stringexpected = "String Interpolation Test By Minseok";
Stringfirst = "Interpolation";
Stringsecond = "By";
Stringresult = MessageFormat.format("String {0} Test {1} Minseok", first, second);
Assertions.assertEquals(expected, result);
}
@Test
publicvoidapache_commons_test() {
Stringexpected = "String Interpolation Test with some Java examples By Minseok";
StringbaseString = "String ${first} Test with some Java examples ${second} Minseok";
Stringfirst = "Interpolation";
Stringsecond = "By";
Map<String, String> parameters = newHashMap<>();
parameters.put("first", first);
parameters.put("second", second);
StringSubstitutorsubstitutor = newStringSubstitutor(parameters);
Stringresult = substitutor.replace(baseString);
Assertions.assertEquals(expected, result);
}
}