Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert exception assertions to AssertJ #2224

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions exercises/practice/grains/src/test/java/GrainsTest.java
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 All @@ -10,7 +9,7 @@
public class GrainsTest {

private Grains grains = new Grains();

@Test
public void countAtSquare1() {
BigInteger result = grains.grainsOnSquare(1);
Expand Down Expand Up @@ -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")
Expand Down