forked from amyaim99/CR-Ch1-Day1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestStringUtilities.java
176 lines (130 loc) · 3.72 KB
/
TestStringUtilities.java
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.zipcodewilmington.danny_do_better_exercises;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by dan on 6/14/17.
*/
public class TestStringUtilities {
@org.junit.jupiter.api.Test
public void getHelloWorldTest() {
// : Given
String expected = "Hello World";
// : When
String actual = StringUtilities.getHelloWorld();
// : Then
assertEquals(expected, actual);
}
@Test
public void concatenationStringTest(){
// : Given
String one = "Hello";
String two = " Java";
String expected = "Hello Java";
// : When
String actual = StringUtilities.concatenation(one,two);
// : Then
assertEquals(expected, actual);
}
@Test
public void concatenationStringAndIntegerTest(){
// : Given
int one = 1;
String two = " Java";
String expected = "1 Java";
// : When
String actual = StringUtilities.concatenation(one,two);
// : Then
assertEquals(expected, actual);
}
@Test
public void substringBeginTest(){
// : Given
String input = "Hello";
String expected = "Hel";
// : When
String actual = StringUtilities.getPrefix(input);
// : Then
assertEquals(expected, actual);
}
@Test
public void substringEndTest(){
// : Given
String input = "Hello";
String expected = "llo";
// : When
String actual = StringUtilities.getSuffix("Hello");
// : Then
assertEquals(expected, actual);
}
@Test
public void compareToTestEquals(){
// : Given
String inputValue = "Zipcode";
String comparableValue = "Zipcode";
// : When
boolean actual = StringUtilities.compareTwoStrings(inputValue, comparableValue);
// : Then
assertTrue(actual);
}
@Test
public void compareToTestNotEquals(){
// : Given
String inputValue = "Zipcode";
String comparableValue = "Zipcodee";
// : When
boolean actual = StringUtilities.compareTwoStrings(inputValue, comparableValue);
// : Then
assertFalse(actual);
}
@Test
public void getTheMiddleChar1(){
// : Given
String input = "Zipcode";
char expected = 'c';
// : When
char actual = StringUtilities.getMiddleCharacter(input);
// : Then
Assert.assertEquals(expected, actual);
}
@Test
public void getTheMiddleChar2(){
// : Given
String input = "Zipcoder";
Character expected = 'c';
// : When
Character actual = StringUtilities.getMiddleCharacter(input);
// : Then
Assert.assertEquals(expected.toString(), actual.toString());
}
@Test
public void getTheFirstWord(){
// : Given
String input = "Zipcode Wilmington";
String expected = "Zipcode";
// : When
String actual = StringUtilities.getFirstWord(input);
// : Then
assertEquals(expected, actual);
}
@Test
public void getTheSecondWord(){
// : Given
String input = "Zipcode Wilmington";
String expected = "Wilmington";
// : When
String actual = StringUtilities.getSecondWord(input);
// : Then
assertEquals(expected, actual);
}
@Test
public void reverseThem(){
// : Given
String input = "Zipcode Wilmington";
String expected = "notgnimliW edocpiZ";
// : When
String actual = StringUtilities.reverseTheTwo(input);
// : Then
assertEquals(expected, actual);
}
}