|
@@ -0,0 +1,162 @@
|
|
1
|
+import org.junit.Test;
|
|
2
|
+
|
|
3
|
+import static org.junit.Assert.*;
|
|
4
|
+
|
|
5
|
+public class StringParserTest {
|
|
6
|
+ @Test
|
|
7
|
+ public void upperCaseString() {
|
|
8
|
+ //Given
|
|
9
|
+ String string1 = "test string";
|
|
10
|
+ String expected = "TEST STRING";
|
|
11
|
+
|
|
12
|
+ //When
|
|
13
|
+ String actual = StringParser.upperCaseString(string1);
|
|
14
|
+
|
|
15
|
+ //Expect
|
|
16
|
+ assertEquals(expected, actual);
|
|
17
|
+ }
|
|
18
|
+
|
|
19
|
+ @Test
|
|
20
|
+ public void lowerCaseString() {
|
|
21
|
+ //Given
|
|
22
|
+ String string1 = "TEST STRING";
|
|
23
|
+ String expected = "test string";
|
|
24
|
+
|
|
25
|
+ //When
|
|
26
|
+ String actual = StringParser.lowerCaseString(string1);
|
|
27
|
+
|
|
28
|
+ //Expect
|
|
29
|
+ assertEquals(expected, actual);
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ @Test
|
|
33
|
+ public void getFirstCharacter() {
|
|
34
|
+ //Given
|
|
35
|
+ String string1 = "test string";
|
|
36
|
+ Character expected = 't';
|
|
37
|
+
|
|
38
|
+ //When
|
|
39
|
+ Character actual = StringParser.getFirstCharacter(string1);
|
|
40
|
+
|
|
41
|
+ //Expect
|
|
42
|
+ assertEquals(expected, actual);
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ @Test
|
|
46
|
+ public void getNthCharacter() {
|
|
47
|
+ //Given
|
|
48
|
+ String string1 = "test string";
|
|
49
|
+ Integer index = 2;
|
|
50
|
+ Character expected = 's';
|
|
51
|
+
|
|
52
|
+ //When
|
|
53
|
+ Character actual = StringParser.getNthCharacter(string1, index);
|
|
54
|
+
|
|
55
|
+ //Expect
|
|
56
|
+ assertEquals(expected, actual);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ @Test
|
|
60
|
+ public void upperCaseFirstCharacter() {
|
|
61
|
+ //Given
|
|
62
|
+ String string1 = "test string";
|
|
63
|
+ String expected = "Test string";
|
|
64
|
+
|
|
65
|
+ //When
|
|
66
|
+ String actual = StringParser.upperCaseFirstCharacter(string1);
|
|
67
|
+
|
|
68
|
+ //Expect
|
|
69
|
+ assertEquals(expected, actual);
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ @Test
|
|
73
|
+ public void camelCaseString() {
|
|
74
|
+ //Given
|
|
75
|
+ String string1 = "tEsT sTrInG";
|
|
76
|
+ String expected = "TestString";
|
|
77
|
+
|
|
78
|
+ //When
|
|
79
|
+ String actual = StringParser.camelCaseString(string1);
|
|
80
|
+
|
|
81
|
+ //Expect
|
|
82
|
+ assertEquals(expected, actual);
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ @Test
|
|
86
|
+ public void snakeCaseString() {
|
|
87
|
+ //Given
|
|
88
|
+ String string1 = "tEST STring";
|
|
89
|
+ String expected = "test_string";
|
|
90
|
+
|
|
91
|
+ //When
|
|
92
|
+ String actual = StringParser.snakeCaseString(string1);
|
|
93
|
+
|
|
94
|
+ //Expect
|
|
95
|
+ assertEquals(expected, actual);
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ @Test
|
|
99
|
+ public void getLength() {
|
|
100
|
+ //Given
|
|
101
|
+ String string1 = "A different string";
|
|
102
|
+ Integer expected1 = 18;
|
|
103
|
+
|
|
104
|
+ String string2 = "test string";
|
|
105
|
+ Integer expected2 = 11;
|
|
106
|
+
|
|
107
|
+ //When
|
|
108
|
+ Integer actual1 = StringParser.getLength(string1);
|
|
109
|
+ Integer actual2 = StringParser.getLength(string2);
|
|
110
|
+
|
|
111
|
+ //Expect
|
|
112
|
+ assertEquals(expected1, actual1);
|
|
113
|
+ assertEquals(expected2, actual2);
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ @Test
|
|
117
|
+ public void isEqual() {
|
|
118
|
+ //Given
|
|
119
|
+ String string1 = "A different string";
|
|
120
|
+ String compareString1 = "a Different string";
|
|
121
|
+ Boolean expected1 = false;
|
|
122
|
+
|
|
123
|
+ String string2 = "test string";
|
|
124
|
+ String compareString2 = "test string";
|
|
125
|
+ Boolean expected2 = true;
|
|
126
|
+
|
|
127
|
+ //When
|
|
128
|
+ Boolean actual1 = StringParser.isEqual(string1, compareString1);
|
|
129
|
+ Boolean actual2 = StringParser.isEqual(string2, compareString2);
|
|
130
|
+
|
|
131
|
+ //Expect
|
|
132
|
+ assertEquals(expected1, actual1);
|
|
133
|
+ assertEquals(expected2, actual2);
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ @Test
|
|
137
|
+ public void isEqualIgnoreCase() {
|
|
138
|
+ //Given
|
|
139
|
+ String string1 = "A different string";
|
|
140
|
+ String compareString1 = "a Different string";
|
|
141
|
+ Boolean expected1 = true;
|
|
142
|
+
|
|
143
|
+ String string2 = "test string";
|
|
144
|
+ String compareString2 = "test string";
|
|
145
|
+ Boolean expected2 = true;
|
|
146
|
+
|
|
147
|
+ String string3 = "A different string";
|
|
148
|
+ String compareString3 = "A different string!";
|
|
149
|
+ Boolean expected3 = false;
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+ //When
|
|
153
|
+ Boolean actual1 = StringParser.isEqualIgnoreCase(string1, compareString1);
|
|
154
|
+ Boolean actual2 = StringParser.isEqualIgnoreCase(string2, compareString2);
|
|
155
|
+ Boolean actual3 = StringParser.isEqualIgnoreCase(string3, compareString3);
|
|
156
|
+
|
|
157
|
+ //Expect
|
|
158
|
+ assertEquals(expected1, actual1);
|
|
159
|
+ assertEquals(expected2, actual2);
|
|
160
|
+ assertEquals(expected3, actual3);
|
|
161
|
+ }
|
|
162
|
+}
|