From 38470b97dc4c961bda7d03f6143a5125121f7132 Mon Sep 17 00:00:00 2001 From: Kerollos Magdy Date: Mon, 10 Oct 2022 22:23:55 +0200 Subject: [PATCH 1/3] Convert exception assertions to AssertJ in SeriestTest #2147 --- .../series/src/test/java/SeriesTest.java | 46 ++++++------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/exercises/practice/series/src/test/java/SeriesTest.java b/exercises/practice/series/src/test/java/SeriesTest.java index c52efcd7a..d94ce8794 100644 --- a/exercises/practice/series/src/test/java/SeriesTest.java +++ b/exercises/practice/series/src/test/java/SeriesTest.java @@ -1,6 +1,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.util.Arrays; import java.util.Collections; @@ -83,41 +83,29 @@ public void slicesOfLongSeries() { public void sliceLengthIsToolarge() { Series series = new Series("12345"); - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> series.slices(6)); - - assertThat(expected) - .hasMessage("Slice size is too big."); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> series.slices(6)) + .withMessage("Slice size is too big."); } @Ignore("Remove to run test") @Test public void sliceLengthZero() { Series series = new Series("12345"); - - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> series.slices(0)); - - assertThat(expected) - .hasMessage("Slice size is too small."); + + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> series.slices(0)) + .withMessage("Slice size is too small."); } @Ignore("Remove to run test") @Test public void sliceLengthNegative() { Series series = new Series("123"); - - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> series.slices(-1)); - - assertThat(expected) - .hasMessage("Slice size is too small."); + + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> series.slices(-1)) + .withMessage("Slice size is too small."); } @Ignore("Remove to run test") @@ -125,13 +113,9 @@ public void sliceLengthNegative() { public void emptySeries() { Series series = new Series(""); - IllegalArgumentException expected = - assertThrows( - IllegalArgumentException.class, - () -> series.slices(1)); - - assertThat(expected) - .hasMessage("Slice size is too big."); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> series.slices(1)) + .withMessage("Slice size is too big."); } } From 761e56f4fca98a607b636599bfbcbbf4fedf9311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santos?= Date: Tue, 11 Oct 2022 00:06:05 +0100 Subject: [PATCH 2/3] Format test file --- .../series/src/test/java/SeriesTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/exercises/practice/series/src/test/java/SeriesTest.java b/exercises/practice/series/src/test/java/SeriesTest.java index d94ce8794..67b49df30 100644 --- a/exercises/practice/series/src/test/java/SeriesTest.java +++ b/exercises/practice/series/src/test/java/SeriesTest.java @@ -84,28 +84,28 @@ public void sliceLengthIsToolarge() { Series series = new Series("12345"); assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> series.slices(6)) - .withMessage("Slice size is too big."); + .isThrownBy(() -> series.slices(6)) + .withMessage("Slice size is too big."); } @Ignore("Remove to run test") @Test public void sliceLengthZero() { Series series = new Series("12345"); - + assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> series.slices(0)) - .withMessage("Slice size is too small."); + .isThrownBy(() -> series.slices(0)) + .withMessage("Slice size is too small."); } @Ignore("Remove to run test") @Test public void sliceLengthNegative() { Series series = new Series("123"); - + assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> series.slices(-1)) - .withMessage("Slice size is too small."); + .isThrownBy(() -> series.slices(-1)) + .withMessage("Slice size is too small."); } @Ignore("Remove to run test") @@ -114,8 +114,8 @@ public void emptySeries() { Series series = new Series(""); assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> series.slices(1)) - .withMessage("Slice size is too big."); + .isThrownBy(() -> series.slices(1)) + .withMessage("Slice size is too big."); } } From ddf711b53906fa610d0c3f5facc6bfb5967830f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santos?= Date: Tue, 11 Oct 2022 00:26:53 +0100 Subject: [PATCH 3/3] Remove unused import --- exercises/practice/series/src/test/java/SeriesTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/practice/series/src/test/java/SeriesTest.java b/exercises/practice/series/src/test/java/SeriesTest.java index 67b49df30..263d04abc 100644 --- a/exercises/practice/series/src/test/java/SeriesTest.java +++ b/exercises/practice/series/src/test/java/SeriesTest.java @@ -1,4 +1,3 @@ -import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;