From 2346fee9f1fa03a492dac0cfbcbb7627461a5ef8 Mon Sep 17 00:00:00 2001 From: CoolTomatos Date: Tue, 6 Sep 2022 17:41:01 +0200 Subject: [PATCH] Added one template. --- .../AssertJComparableTemplates.java | 14 ++++++++++++++ .../AssertJComparableTemplatesTestInput.java | 4 ++++ .../AssertJComparableTemplatesTestOutput.java | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplates.java index e10eb1577d1..ce4770a15b8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplates.java @@ -12,6 +12,20 @@ final class AssertJComparableTemplates { private AssertJComparableTemplates() {} + static final class AbstractComparableAssertActualIsEqualByComparingToExpected< + T extends Comparable> { + @BeforeTemplate + AbstractIntegerAssert before(T actual, T expected) { + return assertThat(actual.compareTo(expected)).isEqualTo(0); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractComparableAssert after(T actual, T expected) { + return assertThat(actual).isEqualByComparingTo(expected); + } + } + static final class AbstractComparableAssertActualIsLessThanExpected< T extends Comparable> { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestInput.java index 2bb51ef4493..145905c43ff 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestInput.java @@ -7,6 +7,10 @@ import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJComparableTemplatesTest implements RefasterTemplateTestCase { + AbstractAssert testAbstractComparableAssertActualIsEqualByComparingToExpected() { + return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isEqualTo(0); + } + AbstractAssert testAbstractComparableAssertActualIsLessThanExpected() { return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNegative(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestOutput.java index 85b41a5dee3..347548bb197 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestOutput.java @@ -7,6 +7,10 @@ import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJComparableTemplatesTest implements RefasterTemplateTestCase { + AbstractAssert testAbstractComparableAssertActualIsEqualByComparingToExpected() { + return assertThat(BigDecimal.ZERO).isEqualByComparingTo(BigDecimal.ONE); + } + AbstractAssert testAbstractComparableAssertActualIsLessThanExpected() { return assertThat(BigDecimal.ZERO).isLessThan(BigDecimal.ONE); }