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

Introduce AssertThatThrownBy*ExceptionRootCauseHasMessage Refaster rules #1471

Merged
merged 1 commit into from
Dec 22, 2024

Conversation

rickie
Copy link
Member

@rickie rickie commented Dec 19, 2024

This PR aims to get rid of the following part of the init-patch of the new IT: https://github.com/PicnicSupermarket/error-prone-support/pull/1468/files#diff-6b99a1fb957cc4c8081a8a95423c965335a67c526f4b5b634aafa0d6912dc4dcR61.

Not sure about the * part in the title, let me know what options are :D.

@rickie rickie added this to the 0.20.0 milestone Dec 19, 2024
@rickie rickie changed the title Introduce AssertThat{*}ExceptionRootCauseHasMessage Refaster rules Introduce AssertThatThrownBy{*}RootCauseHasMessage Refaster rules Dec 19, 2024
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 changed the title Introduce AssertThatThrownBy{*}RootCauseHasMessage Refaster rules Introduce AssertThatThrownBy*ExceptionRootCauseHasMessage Refaster rules Dec 21, 2024
Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Suggested commit message:

Introduce `AssertThatThrownBy*ExceptionRootCauseHasMessage` Refaster rules (#1471)

Not great, but works :)

Comment on lines +575 to +599
static final class AssertThatThrownByRootCauseHasMessage {
@BeforeTemplate
@SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */)
AbstractObjectAssert<?, ?> before(
ThrowingCallable throwingCallable,
Class<? extends Throwable> exceptionType,
String message) {
return assertThatExceptionOfType(exceptionType)
.isThrownBy(throwingCallable)
.havingRootCause()
.withMessage(message);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
AbstractObjectAssert<?, ?> after(
ThrowingCallable throwingCallable,
Class<? extends Throwable> exceptionType,
String message) {
return assertThatThrownBy(throwingCallable)
.isInstanceOf(exceptionType)
.rootCause()
.hasMessage(message);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We should make the return types more explicit, and replace ? extends Throwable with a shared type variable T, but that applies to many rules in this class, so: for another time. (Ideally both these steps are automated.)

Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

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

LGMT 🚀

@Stephan202 Stephan202 force-pushed the rossendrijver/assertj_having_rootcause branch from e0b0007 to ac0cdbf Compare December 22, 2024 11:26
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 merged commit acb8b65 into master Dec 22, 2024
16 checks passed
@Stephan202 Stephan202 deleted the rossendrijver/assertj_having_rootcause branch December 22, 2024 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants