Skip to content

Commit 08adf38

Browse files
authored
add assertJ to haming (exercism#2178)
1 parent 84f99ff commit 08adf38

1 file changed

Lines changed: 13 additions & 29 deletions

File tree

exercises/practice/hamming/src/test/java/HammingTest.java

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import static org.assertj.core.api.Assertions.assertThat;
2-
import static org.junit.Assert.assertThrows;
2+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
33

44
import org.junit.Ignore;
55
import org.junit.Test;
@@ -38,49 +38,33 @@ public void testDistanceInLongDifferentStrands() {
3838
@Ignore("Remove to run test")
3939
@Test
4040
public void testValidatesFirstStrandNotLonger() {
41-
IllegalArgumentException expected =
42-
assertThrows(
43-
IllegalArgumentException.class,
44-
() -> new Hamming("AATG", "AAA"));
45-
46-
assertThat(expected)
47-
.hasMessage("leftStrand and rightStrand must be of equal length.");
41+
assertThatExceptionOfType(IllegalArgumentException.class)
42+
.isThrownBy(() -> new Hamming("AATG", "AAA"))
43+
.withMessage("leftStrand and rightStrand must be of equal length.");
4844
}
4945

5046
@Ignore("Remove to run test")
5147
@Test
5248
public void testValidatesSecondStrandNotLonger() {
53-
IllegalArgumentException expected =
54-
assertThrows(
55-
IllegalArgumentException.class,
56-
() -> new Hamming("ATA", "AGTG"));
57-
58-
assertThat(expected)
59-
.hasMessage("leftStrand and rightStrand must be of equal length.");
49+
assertThatExceptionOfType(IllegalArgumentException.class)
50+
.isThrownBy(() -> new Hamming("ATA", "AGTG"))
51+
.withMessage("leftStrand and rightStrand must be of equal length.");
6052
}
6153

6254
@Ignore("Remove to run test")
6355
@Test
6456
public void testDisallowLeftEmptyStrand() {
65-
IllegalArgumentException expected =
66-
assertThrows(
67-
IllegalArgumentException.class,
68-
() -> new Hamming("", "G"));
69-
70-
assertThat(expected)
71-
.hasMessage("left strand must not be empty.");
57+
assertThatExceptionOfType(IllegalArgumentException.class)
58+
.isThrownBy(() -> new Hamming("", "G"))
59+
.withMessage("left strand must not be empty.");
7260
}
7361

7462
@Ignore("Remove to run test")
7563
@Test
7664
public void testDisallowRightEmptyStrand() {
77-
IllegalArgumentException expected =
78-
assertThrows(
79-
IllegalArgumentException.class,
80-
() -> new Hamming("G", ""));
81-
82-
assertThat(expected)
83-
.hasMessage("right strand must not be empty.");
65+
assertThatExceptionOfType(IllegalArgumentException.class)
66+
.isThrownBy(() -> new Hamming("G", ""))
67+
.withMessage("right strand must not be empty.");
8468
}
8569

8670
}

0 commit comments

Comments
 (0)