diff --git a/exercises/practice/dominoes/src/test/java/DominoesTest.java b/exercises/practice/dominoes/src/test/java/DominoesTest.java index 0d27072c3..0092a42ca 100644 --- a/exercises/practice/dominoes/src/test/java/DominoesTest.java +++ b/exercises/practice/dominoes/src/test/java/DominoesTest.java @@ -1,6 +1,5 @@ -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; import org.junit.Ignore; import org.junit.Test; @@ -44,12 +43,9 @@ public void singletonCantBeChainedTest() { Domino[] dominoesArray = {new Domino(1, 2)}; List dominoesList = Arrays.asList(dominoesArray); - ChainNotFoundException expected = - assertThrows( - ChainNotFoundException.class, - () -> dominoes.formChain(dominoesList)); - - assertThat(expected).hasMessage("No domino chain found."); + assertThatExceptionOfType(ChainNotFoundException.class) + .isThrownBy(() -> dominoes.formChain(dominoesList)) + .withMessage("No domino chain found."); } @Ignore("Remove to run test") @@ -86,12 +82,9 @@ public void cantBeChainedTest() { Domino[] dominoesArray = {new Domino(1, 2), new Domino(4, 1), new Domino(2, 3)}; List dominoesList = Arrays.asList(dominoesArray); - ChainNotFoundException expected = - assertThrows( - ChainNotFoundException.class, - () -> dominoes.formChain(dominoesList)); - - assertThat(expected).hasMessage("No domino chain found."); + assertThatExceptionOfType(ChainNotFoundException.class) + .isThrownBy(() -> dominoes.formChain(dominoesList)) + .withMessage("No domino chain found."); } @Ignore("Remove to run test") @@ -102,12 +95,9 @@ public void disconnectedSimpleTest() { Domino[] dominoesArray = {new Domino(1, 1), new Domino(2, 2)}; List dominoesList = Arrays.asList(dominoesArray); - ChainNotFoundException expected = - assertThrows( - ChainNotFoundException.class, - () -> dominoes.formChain(dominoesList)); - - assertThat(expected).hasMessage("No domino chain found."); + assertThatExceptionOfType(ChainNotFoundException.class) + .isThrownBy(() -> dominoes.formChain(dominoesList)) + .withMessage("No domino chain found."); } @Ignore("Remove to run test") @@ -118,12 +108,9 @@ public void disconnectedDoubleLoopTest() { Domino[] dominoesArray = {new Domino(1, 2), new Domino(2, 1), new Domino(3, 4), new Domino(4, 3)}; List dominoesList = Arrays.asList(dominoesArray); - ChainNotFoundException expected = - assertThrows( - ChainNotFoundException.class, - () -> dominoes.formChain(dominoesList)); - - assertThat(expected).hasMessage("No domino chain found."); + assertThatExceptionOfType(ChainNotFoundException.class) + .isThrownBy(() -> dominoes.formChain(dominoesList)) + .withMessage("No domino chain found."); } @Ignore("Remove to run test") @@ -134,12 +121,9 @@ public void disconnectedSingleIsolatedTest() { Domino[] dominoesArray = {new Domino(1, 2), new Domino(2, 3), new Domino(3, 1), new Domino(4, 4)}; List dominoesList = Arrays.asList(dominoesArray); - ChainNotFoundException expected = - assertThrows( - ChainNotFoundException.class, - () -> dominoes.formChain(dominoesList)); - - assertThat(expected).hasMessage("No domino chain found."); + assertThatExceptionOfType(ChainNotFoundException.class) + .isThrownBy(() -> dominoes.formChain(dominoesList)) + .withMessage("No domino chain found."); } @Ignore("Remove to run test") diff --git a/exercises/practice/variable-length-quantity/src/test/java/VariableLengthQuantityTest.java b/exercises/practice/variable-length-quantity/src/test/java/VariableLengthQuantityTest.java index 0416bfc19..cda7559dd 100644 --- a/exercises/practice/variable-length-quantity/src/test/java/VariableLengthQuantityTest.java +++ b/exercises/practice/variable-length-quantity/src/test/java/VariableLengthQuantityTest.java @@ -1,6 +1,5 @@ -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; import org.junit.Ignore; import org.junit.Test; @@ -228,13 +227,9 @@ public void testDecodeMaximum32BitInteger() { public void testCannotDecodeIncompleteSequence() { List bytes = Arrays.asList(0xffL); - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> variableLengthQuantity.decode(bytes)); - - assertThat(expected) - .hasMessage("Invalid variable-length quantity encoding"); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> variableLengthQuantity.decode(bytes)) + .withMessage("Invalid variable-length quantity encoding"); } @Ignore("Remove to run test") @@ -242,13 +237,9 @@ public void testCannotDecodeIncompleteSequence() { public void testCannotDecodeIncompleteSequenceEvenIfValueIsZero() { List bytes = Arrays.asList(0x80L); - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> variableLengthQuantity.decode(bytes)); - - assertThat(expected) - .hasMessage("Invalid variable-length quantity encoding"); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> variableLengthQuantity.decode(bytes)) + .withMessage("Invalid variable-length quantity encoding"); } @Ignore("Remove to run test")