Skip to content

Commit 31b5f7a

Browse files
authored
Improve secret-handshake assertions with AssertJ (exercism#2061)
* Improve secret-hanshake assertions with AssertJ * Fix config.json issue about duplicate entries
1 parent ec97666 commit 31b5f7a

File tree

3 files changed

+25
-57
lines changed

3 files changed

+25
-57
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ exercises/*/.settings/
1919
_template/bin
2020
_template/.classpath
2121
_template/.project
22-
_template/.settings/
22+
_template/.settings/
23+
*.class

config.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
],
2828
"example": [
2929
".meta/src/reference/java/%{pascal_slug}.java"
30-
],
31-
"exemplar": [
32-
".meta/src/reference/java/%{pascal_slug}.java"
3330
]
3431
},
3532
"exercises": {
Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,100 @@
11
import org.junit.Ignore;
2-
import org.junit.Before;
32
import org.junit.Test;
43

5-
import static java.util.Arrays.asList;
6-
import static java.util.Collections.emptyList;
7-
import static java.util.Collections.singletonList;
8-
import static org.junit.Assert.assertEquals;
4+
import static org.assertj.core.api.Assertions.assertThat;
95

106
public class HandshakeCalculatorTest {
117

12-
private HandshakeCalculator handshakeCalculator;
13-
14-
@Before
15-
public void setUp() {
16-
handshakeCalculator = new HandshakeCalculator();
17-
}
8+
private final HandshakeCalculator handshakeCalculator = new HandshakeCalculator();
189

1910
@Test
2011
public void testThatInput1YieldsAWink() {
21-
assertEquals(
22-
singletonList(Signal.WINK),
23-
handshakeCalculator.calculateHandshake(1));
12+
assertThat(handshakeCalculator.calculateHandshake(1)).containsExactly(Signal.WINK);
2413
}
2514

2615
@Ignore("Remove to run test")
2716
@Test
2817
public void testThatInput2YieldsADoubleBlink() {
29-
assertEquals(
30-
singletonList(Signal.DOUBLE_BLINK),
31-
handshakeCalculator.calculateHandshake(2));
18+
assertThat(handshakeCalculator.calculateHandshake(2)).containsExactly(Signal.DOUBLE_BLINK);
3219
}
3320

3421
@Ignore("Remove to run test")
3522
@Test
3623
public void testThatInput4YieldsACloseYourEyes() {
37-
assertEquals(
38-
singletonList(Signal.CLOSE_YOUR_EYES),
39-
handshakeCalculator.calculateHandshake(4));
24+
assertThat(handshakeCalculator.calculateHandshake(4)).containsExactly(Signal.CLOSE_YOUR_EYES);
4025
}
4126

4227
@Ignore("Remove to run test")
4328
@Test
4429
public void testThatInput8YieldsAJump() {
45-
assertEquals(
46-
singletonList(Signal.JUMP),
47-
handshakeCalculator.calculateHandshake(8));
30+
assertThat(handshakeCalculator.calculateHandshake(8)).containsExactly(Signal.JUMP);
4831
}
4932

5033
@Ignore("Remove to run test")
5134
@Test
5235
public void testAnInputThatYieldsTwoActions() {
53-
assertEquals(
54-
asList(Signal.WINK, Signal.DOUBLE_BLINK),
55-
handshakeCalculator.calculateHandshake(3));
36+
assertThat(handshakeCalculator.calculateHandshake(3))
37+
.containsExactly(Signal.WINK, Signal.DOUBLE_BLINK);
5638
}
5739

5840
@Ignore("Remove to run test")
5941
@Test
6042
public void testAnInputThatYieldsTwoReversedActions() {
61-
assertEquals(
62-
asList(Signal.DOUBLE_BLINK, Signal.WINK),
63-
handshakeCalculator.calculateHandshake(19));
43+
assertThat(handshakeCalculator.calculateHandshake(19))
44+
.containsExactly(Signal.DOUBLE_BLINK, Signal.WINK);
6445
}
6546

6647
@Ignore("Remove to run test")
6748
@Test
6849
public void testReversingASingleActionYieldsTheSameAction() {
69-
assertEquals(
70-
singletonList(Signal.JUMP),
71-
handshakeCalculator.calculateHandshake(24));
50+
assertThat(handshakeCalculator.calculateHandshake(24)).containsExactly(Signal.JUMP);
7251
}
7352

7453
@Ignore("Remove to run test")
7554
@Test
7655
public void testReversingNoActionsYieldsNoActions() {
77-
assertEquals(
78-
emptyList(),
79-
handshakeCalculator.calculateHandshake(16));
56+
assertThat(handshakeCalculator.calculateHandshake(16)).isEmpty();
8057
}
8158

8259
@Ignore("Remove to run test")
8360
@Test
8461
public void testInputThatYieldsAllActions() {
85-
assertEquals(
86-
asList(Signal.WINK, Signal.DOUBLE_BLINK, Signal.CLOSE_YOUR_EYES, Signal.JUMP),
87-
handshakeCalculator.calculateHandshake(15));
62+
assertThat(handshakeCalculator.calculateHandshake(15))
63+
.containsExactly(Signal.WINK, Signal.DOUBLE_BLINK, Signal.CLOSE_YOUR_EYES, Signal.JUMP);
8864
}
8965

9066
@Ignore("Remove to run test")
9167
@Test
9268
public void testInputThatYieldsAllActionsReversed() {
93-
assertEquals(
94-
asList(Signal.JUMP, Signal.CLOSE_YOUR_EYES, Signal.DOUBLE_BLINK, Signal.WINK),
95-
handshakeCalculator.calculateHandshake(31));
69+
assertThat(handshakeCalculator.calculateHandshake(31))
70+
.containsExactly(Signal.JUMP, Signal.CLOSE_YOUR_EYES, Signal.DOUBLE_BLINK, Signal.WINK);
9671
}
9772

9873
@Ignore("Remove to run test")
9974
@Test
10075
public void testThatInput0YieldsNoActions() {
101-
assertEquals(
102-
emptyList(),
103-
handshakeCalculator.calculateHandshake(0));
76+
assertThat(handshakeCalculator.calculateHandshake(0)).isEmpty();
10477
}
10578

10679
@Ignore("Remove to run test")
10780
@Test
10881
public void testThatHandlesMoreThanFiveBinaryPlacesWithReversal() {
109-
assertEquals(
110-
asList(Signal.DOUBLE_BLINK, Signal.WINK),
111-
handshakeCalculator.calculateHandshake(51));
82+
assertThat(handshakeCalculator.calculateHandshake(51))
83+
.containsExactly(Signal.DOUBLE_BLINK, Signal.WINK);
11284
}
11385

11486
@Ignore("Remove to run test")
11587
@Test
11688
public void testThatHandlesMoreThanFiveBinaryPlacesWithoutReversal() {
117-
assertEquals(
118-
asList(Signal.WINK, Signal.DOUBLE_BLINK),
119-
handshakeCalculator.calculateHandshake(35));
89+
assertThat(handshakeCalculator.calculateHandshake(35))
90+
.containsExactly(Signal.WINK, Signal.DOUBLE_BLINK);
12091
}
12192

12293
@Ignore("Remove to run test")
12394
@Test
12495
public void testInputThatYieldsAllActionsFromMoreThanFiveBinaryPlaces() {
125-
assertEquals(
126-
asList(Signal.WINK, Signal.DOUBLE_BLINK, Signal.CLOSE_YOUR_EYES, Signal.JUMP),
127-
handshakeCalculator.calculateHandshake(111));
96+
assertThat(handshakeCalculator.calculateHandshake(111))
97+
.containsExactly(Signal.WINK, Signal.DOUBLE_BLINK, Signal.CLOSE_YOUR_EYES, Signal.JUMP);
12898
}
12999

130100
}

0 commit comments

Comments
 (0)