From 8d5fb3bd48c0d8ddb93ddb38108b6f04dc8abe4c Mon Sep 17 00:00:00 2001 From: Kerollos Magdy Date: Fri, 16 Dec 2022 17:57:33 +0000 Subject: [PATCH] Convert exception assertions to AssertJ --- .../grains/src/test/java/GrainsTest.java | 35 ++++++------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/exercises/practice/grains/src/test/java/GrainsTest.java b/exercises/practice/grains/src/test/java/GrainsTest.java index 0755a6381..112c7a58d 100644 --- a/exercises/practice/grains/src/test/java/GrainsTest.java +++ b/exercises/practice/grains/src/test/java/GrainsTest.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; @@ -10,7 +9,7 @@ public class GrainsTest { private Grains grains = new Grains(); - + @Test public void countAtSquare1() { BigInteger result = grains.grainsOnSquare(1); @@ -62,37 +61,25 @@ public void countAtSquare64() { @Ignore("Remove to run test") @Test public void errorOnNullBoardSize() { - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> grains.grainsOnSquare(0)); - - assertThat(expected) - .hasMessage("square must be between 1 and 64"); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> grains.grainsOnSquare(0)) + .withMessage("square must be between 1 and 64"); } @Ignore("Remove to run test") @Test public void errorOnNegativeBoardSize() { - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> grains.grainsOnSquare(-1)); - - assertThat(expected) - .hasMessage("square must be between 1 and 64"); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> grains.grainsOnSquare(-1)) + .withMessage("square must be between 1 and 64"); } @Ignore("Remove to run test") @Test public void errorOnExcessiveBoardSize() { - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> grains.grainsOnSquare(65)); - - assertThat(expected) - .hasMessage("square must be between 1 and 64"); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> grains.grainsOnSquare(65)) + .withMessage("square must be between 1 and 64"); } @Ignore("Remove to run test")