Skip to content

Commit 2d97a6a

Browse files
authored
Bob assertj (exercism#2019)
* Converting Bob tests to use AssertJ. * Reformatting
1 parent fb47686 commit 2d97a6a

File tree

1 file changed

+52
-89
lines changed

1 file changed

+52
-89
lines changed

exercises/practice/bob/src/test/java/BobTest.java

Lines changed: 52 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,226 +2,189 @@
22
import org.junit.Ignore;
33
import org.junit.Before;
44

5-
import static org.junit.Assert.*;
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
67

78
public class BobTest {
89
private Bob bob;
910

10-
1111
@Before
1212
public void setUp() {
1313
bob = new Bob();
1414
}
1515

1616
@Test
1717
public void saySomething() {
18-
assertEquals(
19-
"Whatever.",
20-
bob.hey("Tom-ay-to, tom-aaaah-to.")
21-
);
18+
assertThat(bob.hey("Tom-ay-to, tom-aaaah-to."))
19+
.isEqualTo("Whatever.");
2220
}
2321

2422
@Ignore("Remove to run test")
2523
@Test
2624
public void shouting() {
27-
assertEquals(
28-
"Whoa, chill out!",
29-
bob.hey("WATCH OUT!")
30-
);
25+
assertThat(bob.hey("WATCH OUT!"))
26+
.isEqualTo("Whoa, chill out!");
3127
}
3228

3329
@Ignore("Remove to run test")
3430
@Test
3531
public void shoutingGibberish() {
36-
assertEquals(
37-
"Whoa, chill out!",
38-
bob.hey("FCECDFCAAB")
39-
);
32+
assertThat(bob.hey("FCECDFCAAB"))
33+
.isEqualTo("Whoa, chill out!");
4034
}
4135

4236
@Ignore("Remove to run test")
4337
@Test
4438
public void askingAQuestion() {
45-
assertEquals(
46-
"Sure.",
47-
bob.hey("Does this cryogenic chamber make me look fat?")
48-
);
39+
assertThat(bob.hey("Does this cryogenic chamber make me look fat?"))
40+
.isEqualTo("Sure.");
4941
}
5042

5143
@Ignore("Remove to run test")
5244
@Test
5345
public void askingANumericQuestion() {
54-
assertEquals(
55-
"Sure.",
56-
bob.hey("You are, what, like 15?")
57-
);
46+
assertThat(bob.hey("You are, what, like 15?"))
47+
.isEqualTo("Sure.");
5848
}
5949

6050
@Ignore("Remove to run test")
6151
@Test
6252
public void askingGibberish() {
63-
assertEquals(
64-
"Sure.",
65-
bob.hey("fffbbcbeab?")
66-
);
53+
assertThat(bob.hey("fffbbcbeab?"))
54+
.isEqualTo("Sure.");
6755
}
6856

6957
@Ignore("Remove to run test")
7058
@Test
7159
public void talkingForcefully() {
72-
assertEquals(
73-
"Whatever.",
74-
bob.hey("Hi there!")
75-
);
60+
assertThat(bob.hey("Hi there!"))
61+
.isEqualTo("Whatever.");
7662
}
7763

7864
@Ignore("Remove to run test")
7965
@Test
8066
public void usingAcronymsInRegularSpeech() {
81-
assertEquals(
82-
"Whatever.", bob.hey("It's OK if you don't want to go work for NASA.")
83-
);
67+
assertThat(bob.hey("It's OK if you don't want to go work for NASA."))
68+
.isEqualTo("Whatever.");
8469
}
8570

8671
@Ignore("Remove to run test")
8772
@Test
8873
public void forcefulQuestions() {
89-
assertEquals(
90-
"Calm down, I know what I'm doing!", bob.hey("WHAT'S GOING ON?")
91-
);
74+
assertThat(bob.hey("WHAT'S GOING ON?"))
75+
.isEqualTo("Calm down, I know what I'm doing!");
9276
}
9377

9478
@Ignore("Remove to run test")
9579
@Test
9680
public void shoutingNumbers() {
97-
assertEquals(
98-
"Whoa, chill out!", bob.hey("1, 2, 3 GO!")
99-
);
81+
assertThat(bob.hey("1, 2, 3 GO!"))
82+
.isEqualTo("Whoa, chill out!");
10083
}
10184

10285
@Ignore("Remove to run test")
10386
@Test
10487
public void onlyNumbers() {
105-
assertEquals(
106-
"Whatever.", bob.hey("1, 2, 3")
107-
);
88+
assertThat(bob.hey("1, 2, 3"))
89+
.isEqualTo("Whatever.");
10890
}
10991

11092
@Ignore("Remove to run test")
11193
@Test
11294
public void questionWithOnlyNumbers() {
113-
assertEquals(
114-
"Sure.", bob.hey("4?")
115-
);
95+
assertThat(bob.hey("4?"))
96+
.isEqualTo("Sure.");
11697
}
11798

11899
@Ignore("Remove to run test")
119100
@Test
120101
public void shoutingWithSpecialCharacters() {
121-
assertEquals(
122-
"Whoa, chill out!", bob.hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")
123-
);
102+
assertThat(bob.hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"))
103+
.isEqualTo("Whoa, chill out!");
124104
}
125105

126106
@Ignore("Remove to run test")
127107
@Test
128108
public void shoutingWithNoExclamationMark() {
129-
assertEquals(
130-
"Whoa, chill out!", bob.hey("I HATE THE DENTIST")
131-
);
109+
assertThat(bob.hey("I HATE THE DENTIST"))
110+
.isEqualTo("Whoa, chill out!");
132111
}
133112

134113
@Ignore("Remove to run test")
135114
@Test
136115
public void statementContainingQuestionMark() {
137-
assertEquals(
138-
"Whatever.", bob.hey("Ending with ? means a question.")
139-
);
116+
assertThat(bob.hey("Ending with ? means a question."))
117+
.isEqualTo("Whatever.");
140118
}
141119

142120
@Ignore("Remove to run test")
143121
@Test
144122
public void nonLettersWithQuestion() {
145-
assertEquals(
146-
"Sure.", bob.hey(":) ?")
147-
);
123+
assertThat(bob.hey(":) ?"))
124+
.isEqualTo("Sure.");
148125
}
149126

150127
@Ignore("Remove to run test")
151128
@Test
152129
public void prattlingOn() {
153-
assertEquals(
154-
"Sure.", bob.hey("Wait! Hang on. Are you going to be OK?")
155-
);
130+
assertThat(bob.hey("Wait! Hang on. Are you going to be OK?"))
131+
.isEqualTo("Sure.");
156132
}
157133

158134
@Ignore("Remove to run test")
159135
@Test
160136
public void silence() {
161-
assertEquals(
162-
"Fine. Be that way!", bob.hey("")
163-
);
137+
assertThat(bob.hey(""))
138+
.isEqualTo("Fine. Be that way!");
164139
}
165140

166141
@Ignore("Remove to run test")
167142
@Test
168143
public void prolongedSilence() {
169-
assertEquals(
170-
"Fine. Be that way!", bob.hey(" ")
171-
);
144+
assertThat(bob.hey(" "))
145+
.isEqualTo("Fine. Be that way!");
172146
}
173147

174148
@Ignore("Remove to run test")
175149
@Test
176150
public void alternateSilence() {
177-
assertEquals(
178-
"Fine. Be that way!", bob.hey("\t\t\t\t\t\t\t\t\t\t")
179-
);
151+
assertThat(bob.hey("\t\t\t\t\t\t\t\t\t\t"))
152+
.isEqualTo("Fine. Be that way!");
180153
}
181154

182155
@Ignore("Remove to run test")
183156
@Test
184157
public void multipleLineQuestion() {
185-
assertEquals(
186-
"Whatever.",
187-
bob.hey("\nDoes this cryogenic chamber make me look fat?\nNo.")
188-
);
158+
assertThat(bob.hey("\nDoes this cryogenic chamber make me look fat?\nNo."))
159+
.isEqualTo("Whatever.");
189160
}
190161

191162
@Ignore("Remove to run test")
192163
@Test
193164
public void startingWithWhitespace() {
194-
assertEquals(
195-
"Whatever.",
196-
bob.hey(" hmmmmmmm...")
197-
);
165+
assertThat(bob.hey(" hmmmmmmm..."))
166+
.isEqualTo("Whatever.");
198167
}
199168

200169
@Ignore("Remove to run test")
201170
@Test
202171
public void endingWithWhiteSpace() {
203-
assertEquals(
204-
"Sure.",
205-
bob.hey("Okay if like my spacebar quite a bit? ")
206-
);
172+
assertThat(bob.hey("Okay if like my spacebar quite a bit? "))
173+
.isEqualTo("Sure.");
207174
}
208175

209176
@Ignore("Remove to run test")
210177
@Test
211178
public void otherWhiteSpace() {
212-
assertEquals(
213-
"Fine. Be that way!",
214-
bob.hey("\n\r \t")
215-
);
179+
assertThat(bob.hey("\n\r \t"))
180+
.isEqualTo("Fine. Be that way!");
216181
}
217182

218183
@Ignore("Remove to run test")
219184
@Test
220185
public void nonQuestionEndingWithWhiteSpace() {
221-
assertEquals(
222-
"Whatever.",
223-
bob.hey("This is a statement ending with whitespace ")
224-
);
186+
assertThat(bob.hey("This is a statement ending with whitespace "))
187+
.isEqualTo("Whatever.");
225188
}
226189

227190
}

0 commit comments

Comments
 (0)