- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringCompareTest.java
More file actions
Latest commit
114 lines (93 loc) · 4.04 KB
/
Copy pathStringCompareTest.java
File metadata and controls
114 lines (93 loc) · 4.04 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
packagebasics;
importorg.apache.commons.lang3.StringUtils;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.api.Test;
importjava.util.Objects;
publicclassStringCompareTest {
@Test
publicvoidoperator_Test() {
Strings1 = "hello minseok";
Strings2 = "hello minseok";
Strings3 = newString("hello minseok");
Assertions.assertTrue(s1 == s2);
Assertions.assertFalse(s1 == s3);
}
@Test
publicvoidstring_equals_test() {
Strings1 = "hello minseok";
Strings2 = "hello minseok";
Strings3 = "hello MINSEOK";
Strings4 = newString("hello minseok");
Assertions.assertTrue(s1.equals(s2));
Assertions.assertTrue(s1.equals(s4));
Assertions.assertFalse(s1.equals(null));
Assertions.assertFalse(s1.equals(s3));
}
@Test
publicvoidstring_equalsIgnoreCase_test() {
Strings1 = "hello minseok";
Strings2 = newString("hello MINseok");
Assertions.assertTrue(s1.equalsIgnoreCase(s2));
}
@Test
publicvoidstring_compareTo_test() {
Strings1 = "apple";
Strings2 = "banana";
Strings3 = "banana";
Assertions.assertEquals(s1.compareTo(s2), -1);
Assertions.assertEquals(s2.compareTo(s1), 1);
Assertions.assertEquals(s2.compareTo(s3), 0);
}
@Test
publicvoidstring_compareToIgnoreCase_test() {
Strings1 = "apple";
Strings2 = "banana";
Strings3 = "BANANA";
Assertions.assertEquals(s1.compareTo(s2), -1);
Assertions.assertEquals(s2.compareTo(s1), 1);
Assertions.assertTrue(s2.compareTo(s3) > 0);
Assertions.assertEquals(s2.compareToIgnoreCase(s3), 0);
}
@Test
publicvoidobject_equals_test() {
Strings1 = "hello minseok";
Strings2 = "hello minseok";
Strings3 = newString("hello minseok");
Assertions.assertTrue(Objects.equals(s1, s2));
Assertions.assertTrue(Objects.equals(s1, s3));
Assertions.assertTrue(Objects.equals(null, null));
Assertions.assertFalse(Objects.equals(null, s1));
}
@Test
publicvoidapache_equals_test() {
Assertions.assertTrue(StringUtils.equals(null, null));
Assertions.assertFalse(StringUtils.equals(null, "minseok "));
Assertions.assertTrue(StringUtils.equals("minseok", "minseok"));
Assertions.assertFalse(StringUtils.equals("minseok", "Minseok"));
Assertions.assertTrue(StringUtils.equalsIgnoreCase("minseok", "minseok"));
Assertions.assertTrue(StringUtils.equalsIgnoreCase("minseok", "Minseok"));
}
@Test
publicvoidapache_any_equals_test() {
Assertions.assertTrue(StringUtils.equalsAny(null, null, null));
Assertions.assertTrue(StringUtils.equalsAny("minseok", "minseok", "abc"));
Assertions.assertTrue(StringUtils.equalsAny("minseok", null, "minseok"));
Assertions.assertFalse(StringUtils.equalsAny(null, "abc", "minseok"));
Assertions.assertFalse(StringUtils.equalsAny("minseok", "abc", "Minseok"));
Assertions.assertTrue(StringUtils.equalsAnyIgnoreCase("minseok", "abc", "Minseok"));
}
@Test
publicvoidapache_compareTo_test() {
Assertions.assertEquals(StringUtils.compare(null,null),0);
Assertions.assertEquals(StringUtils.compare(null,"abc"),-1);
Assertions.assertEquals(StringUtils.compare("abc","bbc"),-1);
Assertions.assertEquals(StringUtils.compare("bbc","abc"),1);
Assertions.assertEquals(StringUtils.compareIgnoreCase("Abc", "bbc"), -1);
Assertions.assertEquals(StringUtils.compareIgnoreCase("bbc", "Abc"), 1);
Assertions.assertEquals(StringUtils.compareIgnoreCase("Abc", "abc"), 0);
Assertions.assertEquals(StringUtils.compare(null, "abc", true),-1);
Assertions.assertEquals(StringUtils.compare(null, "abc", false),1);
Assertions.assertEquals(StringUtils.compareIgnoreCase(null, "Abc", true),-1);
Assertions.assertEquals(StringUtils.compareIgnoreCase(null, "Abc", false),1);
}
}