Skip to content

Commit edb5725

Browse files
authored
Update tests to use assertj (#2510)
* Update tests to use assertj * Fix style check in DominoesTest * Fix style check * Revert changes in deprecated exercise
1 parent 633956b commit edb5725

File tree

8 files changed

+124
-147
lines changed

8 files changed

+124
-147
lines changed

exercises/practice/collatz-conjecture/src/test/java/CollatzCalculatorTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2-
import static org.junit.Assert.assertEquals;
3-
41
import org.junit.Ignore;
52
import org.junit.Test;
63

4+
import static org.assertj.core.api.Assertions.assertThat;
5+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
6+
77
public class CollatzCalculatorTest {
88

99
private CollatzCalculator collatzCalculator = new CollatzCalculator();
1010

1111
@Test
1212
public void testZeroStepsRequiredWhenStartingFrom1() {
13-
assertEquals(0, collatzCalculator.computeStepCount(1));
13+
assertThat(collatzCalculator.computeStepCount(1)).isEqualTo(0);
1414
}
1515

1616
@Ignore("Remove to run test")
1717
@Test
1818
public void testCorrectNumberOfStepsWhenAllStepsAreDivisions() {
19-
assertEquals(4, collatzCalculator.computeStepCount(16));
19+
assertThat(collatzCalculator.computeStepCount(16)).isEqualTo(4);
2020
}
2121

2222
@Ignore("Remove to run test")
2323
@Test
2424
public void testCorrectNumberOfStepsWhenBothStepTypesAreNeeded() {
25-
assertEquals(9, collatzCalculator.computeStepCount(12));
25+
assertThat(collatzCalculator.computeStepCount(12)).isEqualTo(9);
2626
}
2727

2828
@Ignore("Remove to run test")
2929
@Test
3030
public void testAVeryLargeInput() {
31-
assertEquals(152, collatzCalculator.computeStepCount(1000000));
31+
assertThat(collatzCalculator.computeStepCount(1000000)).isEqualTo(152);
3232
}
3333

3434
@Ignore("Remove to run test")
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import org.junit.Test;
21
import org.junit.Ignore;
2+
import org.junit.Test;
33

4-
import static org.junit.Assert.assertEquals;
4+
import static org.assertj.core.api.Assertions.assertThat;
55

66
public class CryptoSquareTest {
77

@@ -10,7 +10,7 @@ public void emptyPlaintextResultsInEmptyCiphertext() {
1010
CryptoSquare cryptoSquare = new CryptoSquare("");
1111
String expectedOutput = "";
1212

13-
assertEquals(expectedOutput, cryptoSquare.getCiphertext());
13+
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
1414
}
1515

1616
@Ignore("Remove to run test")
@@ -19,7 +19,7 @@ public void lettersAreLowerCasedDuringEncryption() {
1919
CryptoSquare cryptoSquare = new CryptoSquare("A");
2020
String expectedOutput = "a";
2121

22-
assertEquals(expectedOutput, cryptoSquare.getCiphertext());
22+
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
2323
}
2424

2525
@Ignore("Remove to run test")
@@ -28,7 +28,7 @@ public void spacesAreRemovedDuringEncryption() {
2828
CryptoSquare cryptoSquare = new CryptoSquare(" b ");
2929
String expectedOutput = "b";
3030

31-
assertEquals(expectedOutput, cryptoSquare.getCiphertext());
31+
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
3232
}
3333

3434
@Ignore("Remove to run test")
@@ -37,7 +37,7 @@ public void punctuationIsRemovedDuringEncryption() {
3737
CryptoSquare cryptoSquare = new CryptoSquare("@1,%!");
3838
String expectedOutput = "1";
3939

40-
assertEquals(expectedOutput, cryptoSquare.getCiphertext());
40+
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
4141
}
4242

4343
@Ignore("Remove to run test")
@@ -46,7 +46,7 @@ public void nineCharacterPlaintextResultsInThreeChunksOfThreeCharacters() {
4646
CryptoSquare cryptoSquare = new CryptoSquare("This is fun!");
4747
String expectedOutput = "tsf hiu isn";
4848

49-
assertEquals(expectedOutput, cryptoSquare.getCiphertext());
49+
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
5050
}
5151

5252
@Ignore("Remove to run test")
@@ -55,7 +55,7 @@ public void eightCharacterPlaintextResultsInThreeChunksWithATrailingSpace() {
5555
CryptoSquare cryptoSquare = new CryptoSquare("Chill out.");
5656
String expectedOutput = "clu hlt io ";
5757

58-
assertEquals(expectedOutput, cryptoSquare.getCiphertext());
58+
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
5959
}
6060

6161
@Ignore("Remove to run test")
@@ -65,6 +65,6 @@ public void fiftyFourCharacterPlaintextResultsInSevenChunksWithTrailingSpaces()
6565
"given us roots.");
6666
String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ";
6767

68-
assertEquals(expectedOutput, cryptoSquare.getCiphertext());
68+
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
6969
}
7070
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
11
import org.junit.Ignore;
22
import org.junit.Test;
33

4-
import static org.junit.Assert.assertEquals;
4+
import static org.assertj.core.api.Assertions.assertThat;
55

66
public class DartsTest {
77

88
Darts darts = new Darts();
99
@Test
1010
public void missedTarget() {
11-
assertEquals(0, darts.score(-9, 9));
11+
assertThat(darts.score(-9, 9)).isEqualTo(0);
1212
}
1313

1414
@Ignore("Remove to run test")
1515
@Test
1616
public void onTheOuterCircle() {
17-
assertEquals(1, darts.score(0, 10));
17+
assertThat(darts.score(0, 10)).isEqualTo(1);
1818
}
1919

2020
@Ignore("Remove to run test")
2121
@Test
2222
public void onTheMiddleCircle() {
23-
assertEquals(5, darts.score(-5, 0));
23+
assertThat(darts.score(-5, 0)).isEqualTo(5);
2424
}
2525

2626
@Ignore("Remove to run test")
2727
@Test
2828
public void onTheInnerCircle() {
29-
assertEquals(10, darts.score(0, -1));
29+
assertThat(darts.score(0, -1)).isEqualTo(10);
3030
}
3131

3232
@Ignore("Remove to run test")
3333
@Test
3434
public void exactlyOnCentre() {
35-
assertEquals(10, darts.score(0, 0));
35+
assertThat(darts.score(0, 0)).isEqualTo(10);
3636
}
3737

3838
@Ignore("Remove to run test")
3939
@Test
4040
public void nearTheCentre() {
41-
assertEquals(10, darts.score(-0.1, -0.1));
41+
assertThat(darts.score(-0.1, -0.1)).isEqualTo(10);
4242
}
4343

4444
@Ignore("Remove to run test")
4545
@Test
4646
public void justWithinTheInnerCircle() {
47-
assertEquals(10, darts.score(0.7, 0.7));
47+
assertThat(darts.score(0.7, 0.7)).isEqualTo(10);
4848
}
4949

5050
@Ignore("Remove to run test")
5151
@Test
5252
public void justOutsideTheInnerCircle() {
53-
assertEquals(5, darts.score(0.8, -0.8));
53+
assertThat(darts.score(0.8, -0.8)).isEqualTo(5);
5454
}
5555

5656
@Ignore("Remove to run test")
5757
@Test
5858
public void justWithinTheMiddleCircle() {
59-
assertEquals(5, darts.score(-3.5, 3.5));
59+
assertThat(darts.score(-3.5, 3.5)).isEqualTo(5);
6060
}
6161

6262
@Ignore("Remove to run test")
6363
@Test
6464
public void justOutsideTheMiddleCircle() {
65-
assertEquals(1, darts.score(-3.6, -3.6));
65+
assertThat(darts.score(-3.6, -3.6)).isEqualTo(1);
6666
}
6767

6868

6969
@Ignore("Remove to run test")
7070
@Test
7171
public void justWithinTheOuterCircle() {
72-
assertEquals(1, darts.score(-7.0, 7.0));
72+
assertThat(darts.score(-7.0, 7.0)).isEqualTo(1);
7373
}
7474

7575
@Ignore("Remove to run test")
7676
@Test
7777
public void justOutsideTheOuterCircle() {
78-
assertEquals(0, darts.score(7.1, -7.1));
78+
assertThat(darts.score(7.1, -7.1)).isEqualTo(0);
7979
}
8080

8181
@Ignore("Remove to run test")
8282
@Test
8383
public void asymmetricPositionBetweenTheInnerAndMiddleCircles() {
84-
assertEquals(5, darts.score(0.5, -4));
84+
assertThat(darts.score(0.5, -4)).isEqualTo(5);
8585
}
8686

8787
}

exercises/practice/difference-of-squares/src/test/java/DifferenceOfSquaresCalculatorTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import org.junit.Ignore;
33
import org.junit.Test;
44

5-
import static org.junit.Assert.assertEquals;
5+
import static org.assertj.core.api.Assertions.assertThat;
66

77
public class DifferenceOfSquaresCalculatorTest {
88

@@ -17,71 +17,71 @@ public void setUp() {
1717
public void testSquareOfSumUpToOne() {
1818
int expected = 1;
1919
int actual = calculator.computeSquareOfSumTo(1);
20-
assertEquals(expected, actual);
20+
assertThat(actual).isEqualTo(expected);
2121
}
2222

2323
@Ignore("Remove to run test")
2424
@Test
2525
public void testSquareOfSumUpToFive() {
2626
int expected = 225;
2727
int actual = calculator.computeSquareOfSumTo(5);
28-
assertEquals(expected, actual);
28+
assertThat(actual).isEqualTo(expected);
2929
}
3030

3131
@Ignore("Remove to run test")
3232
@Test
3333
public void testSquareOfSumUpToHundred() {
3434
int expected = 25502500;
3535
int actual = calculator.computeSquareOfSumTo(100);
36-
assertEquals(expected, actual);
36+
assertThat(actual).isEqualTo(expected);
3737
}
3838

3939
@Ignore("Remove to run test")
4040
@Test
4141
public void testSumOfSquaresUpToOne() {
4242
int expected = 1;
4343
int actual = calculator.computeSumOfSquaresTo(1);
44-
assertEquals(expected, actual);
44+
assertThat(actual).isEqualTo(expected);
4545
}
4646

4747
@Ignore("Remove to run test")
4848
@Test
4949
public void testSumOfSquaresUpToFive() {
5050
int expected = 55;
5151
int actual = calculator.computeSumOfSquaresTo(5);
52-
assertEquals(expected, actual);
52+
assertThat(actual).isEqualTo(expected);
5353
}
5454

5555
@Ignore("Remove to run test")
5656
@Test
5757
public void testSumOfSquaresUpToHundred() {
5858
int expected = 338350;
5959
int actual = calculator.computeSumOfSquaresTo(100);
60-
assertEquals(expected, actual);
60+
assertThat(actual).isEqualTo(expected);
6161
}
6262

6363
@Ignore("Remove to run test")
6464
@Test
6565
public void testDifferenceOfSquaresUpToOne() {
6666
int expected = 0;
6767
int actual = calculator.computeDifferenceOfSquares(1);
68-
assertEquals(expected, actual);
68+
assertThat(actual).isEqualTo(expected);
6969
}
7070

7171
@Ignore("Remove to run test")
7272
@Test
7373
public void testDifferenceOfSquaresUpToFive() {
7474
int expected = 170;
7575
int actual = calculator.computeDifferenceOfSquares(5);
76-
assertEquals(expected, actual);
76+
assertThat(actual).isEqualTo(expected);
7777
}
7878

7979
@Ignore("Remove to run test")
8080
@Test
8181
public void testDifferenceOfSquaresUpToHundred() {
8282
int expected = 25164150;
8383
int actual = calculator.computeDifferenceOfSquares(100);
84-
assertEquals(expected, actual);
84+
assertThat(actual).isEqualTo(expected);
8585
}
8686

8787
}

0 commit comments

Comments
 (0)