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 uses of JUnit's assertThrows to use AssertJ's assertThatExceptionOfType #2306

Conversation

GitteV-2159432
Copy link

@GitteV-2159432 GitteV-2159432 commented May 6, 2023

pull request

changed assertThrows to assertThatExceptionOfType in:

  • nth-prime (PrimeCalculatorTest)
  • triangle (TriangleTest)
  • simple-linked-list (SimpleLinkedListTest)
  • ocr-numbers (OpticalCharacterReaderTest)
  • error-handling (ErrorHandlingTest)
  • palindrome-products (PalindromeCalculatorTest)
  • ledger (LedgerTest)
  • sgf-parsing (SgfParsingTest)
  • phone-number (PhoneNumberTest)
  • forth (ForthEvaluatorTest)

Contributes to #2147


Reviewer Resources:

Track Policies

Copy link
Contributor

@sanderploegsma sanderploegsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I left a couple of comments to address, but other than that this PR look good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert your changes to this file, as it's not related to the PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert your changes to this file, as it's not related to the PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert your changes to this file, as it's not related to the PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert your changes to this file, as it's not related to the PR

}

@Ignore("Remove to run test")
//@Ignore("Remove to run test")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change, we want all tests except the first test to be ignored by default.

() -> new SgfParsing().parse(input));
assertThatExceptionOfType(SgfParsingException.class)
.isThrownBy(() -> new SgfParsing().parse(input))
.withMessage("tree missing");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .withMessage() is incorrect: the first argument to JUnit's assertThrows() doesn't assert the exception message but is used as the message printed when the assertion fails.

In fact, the original test doesn't perform an assertion of the exception message, only on its type, so there is no need to call .withMessage() in any of the tests in this file.

@sanderploegsma sanderploegsma changed the title Using AssertJ assertions on entire exercises #2147 Convert uses of JUnit's assertThrows to use AssertJ's assertThatExceptionOfType Aug 25, 2023
@sanderploegsma
Copy link
Contributor

Closing this PR as it's currently inactive. @GitteVandevenne if you want to pick this up again just let me know and we'll reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants