Skip to content

Commit

Permalink
perfect-numbers: convert exception assertions to AssertJ in NaturalNu…
Browse files Browse the repository at this point in the history
…mberTest (#2193)
  • Loading branch information
kerolloz authored Oct 30, 2022
1 parent 02fac4d commit b415b67
Showing 1 changed file with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -79,25 +78,17 @@ public void testThatOneIsCorrectlyClassifiedAsDeficient() {
@Ignore("Remove to run test")
@Test
public void testThatNonNegativeIntegerIsRejected() {
IllegalArgumentException expected =
assertThrows(
IllegalArgumentException.class,
() -> new NaturalNumber(0));

assertThat(expected)
.hasMessage("You must supply a natural number (positive integer)");
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new NaturalNumber(0))
.withMessage("You must supply a natural number (positive integer)");
}

@Ignore("Remove to run test")
@Test
public void testThatNegativeIntegerIsRejected() {
IllegalArgumentException expected =
assertThrows(
IllegalArgumentException.class,
() -> new NaturalNumber(-1));

assertThat(expected)
.hasMessage("You must supply a natural number (positive integer)");
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new NaturalNumber(-1))
.withMessage("You must supply a natural number (positive integer)");
}

}

0 comments on commit b415b67

Please sign in to comment.