From a265a450f91021fffd6f24736bff35553bcea145 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 17 Jul 2024 16:14:56 +0200 Subject: [PATCH] Upgrade AssertJ 3.25.3 -> 3.26.0 (#1197) See: - https://github.com/assertj/assertj/releases/tag/assertj-build-3.26.0 - https://github.com/assertj/assertj/compare/assertj-build-3.25.3...assertj-build-3.26.0 --- .../refasterrules/JUnitToAssertJRules.java | 41 +++++++++---------- .../refasterrules/TestNGToAssertJRules.java | 3 +- .../JUnitToAssertJRulesTestInput.java | 8 ++-- .../JUnitToAssertJRulesTestOutput.java | 8 ++-- .../TestNGToAssertJRulesTestOutput.java | 2 +- pom.xml | 2 +- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitToAssertJRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitToAssertJRules.java index 23c3bc16..e7915237 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitToAssertJRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitToAssertJRules.java @@ -302,16 +302,22 @@ import tech.picnic.errorprone.refaster.annotation.TypeMigration; final class JUnitToAssertJRules { private JUnitToAssertJRules() {} - static final class ThrowNewAssertionError { + static final class Fail { @BeforeTemplate - void before() { - Assertions.fail(); + T before() { + return Assertions.fail(); } + // XXX: Add `@UseImportPolicy(STATIC_IMPORT_ALWAYS)` once + // https://github.com/google/error-prone/pull/3584 is resolved. Until that time, statically + // importing AssertJ's `fail` is likely to clash with an existing static import of JUnit's + // `fail`. Note that combining Error Prone's `RemoveUnusedImports` and + // `UnnecessarilyFullyQualified` checks and our `StaticImport` check will anyway cause the + // method to be imported statically if possible; just in a less efficient manner. @AfterTemplate @DoNotCall - void after() { - throw new AssertionError(); + T after() { + return fail(); } } @@ -321,12 +327,7 @@ final class JUnitToAssertJRules { return Assertions.fail(message); } - // XXX: Add `@UseImportPolicy(STATIC_IMPORT_ALWAYS)` once - // https://github.com/google/error-prone/pull/3584 is resolved. Until that time, statically - // importing AssertJ's `fail` is likely to clash with an existing static import of JUnit's - // `fail`. Note that combining Error Prone's `RemoveUnusedImports` and - // `UnnecessarilyFullyQualified` checks and our `StaticImport` check will anyway cause the - // method to be imported statically if possible; just in a less efficient manner. + // XXX: Add `@UseImportPolicy(STATIC_IMPORT_ALWAYS)`. See `Fail` comment. @AfterTemplate T after(String message) { return fail(message); @@ -339,28 +340,24 @@ final class JUnitToAssertJRules { return Assertions.fail(message, throwable); } - // XXX: Add `@UseImportPolicy(STATIC_IMPORT_ALWAYS)` once - // https://github.com/google/error-prone/pull/3584 is resolved. Until that time, statically - // importing AssertJ's `fail` is likely to clash with an existing static import of JUnit's - // `fail`. Note that combining Error Prone's `RemoveUnusedImports` and - // `UnnecessarilyFullyQualified` checks and our `StaticImport` check will anyway cause the - // method to be imported statically if possible; just in a less efficient manner. + // XXX: Add `@UseImportPolicy(STATIC_IMPORT_ALWAYS)`. See `Fail` comment. @AfterTemplate T after(String message, Throwable throwable) { return fail(message, throwable); } } - static final class FailWithThrowable { + static final class FailWithThrowable { @BeforeTemplate - void before(Throwable throwable) { - Assertions.fail(throwable); + T before(Throwable throwable) { + return Assertions.fail(throwable); } + // XXX: Add `@UseImportPolicy(STATIC_IMPORT_ALWAYS)`. See `Fail` comment. @AfterTemplate @DoNotCall - void after(Throwable throwable) { - throw new AssertionError(throwable); + T after(Throwable throwable) { + return fail(throwable); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java index e9662898..987812ac 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java @@ -161,8 +161,9 @@ final class TestNGToAssertJRules { @AfterTemplate @DoNotCall + @UseImportPolicy(STATIC_IMPORT_ALWAYS) void after() { - throw new AssertionError(); + fail(); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestInput.java index 0c398251..8abb82ce 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestInput.java @@ -32,8 +32,8 @@ final class JUnitToAssertJRulesTest implements RefasterRuleCollectionTestCase { (Runnable) () -> assertTrue(true)); } - void testThrowNewAssertionError() { - Assertions.fail(); + Object testFail() { + return Assertions.fail(); } Object testFailWithMessage() { @@ -44,8 +44,8 @@ final class JUnitToAssertJRulesTest implements RefasterRuleCollectionTestCase { return Assertions.fail("foo", new IllegalStateException()); } - void testFailWithThrowable() { - Assertions.fail(new IllegalStateException()); + Object testFailWithThrowable() { + return Assertions.fail(new IllegalStateException()); } void testAssertThatIsTrue() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestOutput.java index 99a62a38..66ce892c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestOutput.java @@ -35,8 +35,8 @@ final class JUnitToAssertJRulesTest implements RefasterRuleCollectionTestCase { (Runnable) () -> assertTrue(true)); } - void testThrowNewAssertionError() { - throw new AssertionError(); + Object testFail() { + return org.assertj.core.api.Assertions.fail(); } Object testFailWithMessage() { @@ -47,8 +47,8 @@ final class JUnitToAssertJRulesTest implements RefasterRuleCollectionTestCase { return org.assertj.core.api.Assertions.fail("foo", new IllegalStateException()); } - void testFailWithThrowable() { - throw new AssertionError(new IllegalStateException()); + Object testFailWithThrowable() { + return org.assertj.core.api.Assertions.fail(new IllegalStateException()); } void testAssertThatIsTrue() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestOutput.java index bd43fb87..7de09576 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestOutput.java @@ -41,7 +41,7 @@ final class TestNGToAssertJRulesTest implements RefasterRuleCollectionTestCase { } void testFail() { - throw new AssertionError(); + fail(); } void testFailWithMessage() { diff --git a/pom.xml b/pom.xml index 6d2e63ee..7f8658c4 100644 --- a/pom.xml +++ b/pom.xml @@ -425,7 +425,7 @@ org.assertj assertj-bom - 3.25.3 + 3.26.0 pom import