From 7885a2c42d3bfa4f35abdb1ae013e952a839ffc1 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 9 Sep 2022 11:49:36 +0200 Subject: [PATCH] Introduce `AssertJPrimitiveTemplates` and move some templates --- .../AssertJNumberTemplates.java | 97 -------------- .../AssertJPrimitivesTemplates.java | 111 ++++++++++++++++ .../RefasterTemplatesTest.java | 1 + .../AssertJNumberTemplatesTestInput.java | 115 ---------------- .../AssertJNumberTemplatesTestOutput.java | 115 ---------------- .../AssertJPrimitivesTemplatesTestInput.java | 123 ++++++++++++++++++ .../AssertJPrimitivesTemplatesTestOutput.java | 123 ++++++++++++++++++ 7 files changed, 358 insertions(+), 327 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplates.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplatesTestInput.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplatesTestOutput.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplates.java index 94500186e92..5ebba09d0e0 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplates.java @@ -11,7 +11,6 @@ import java.math.BigInteger; import org.assertj.core.api.AbstractBigDecimalAssert; import org.assertj.core.api.AbstractBigIntegerAssert; -import org.assertj.core.api.AbstractBooleanAssert; import org.assertj.core.api.AbstractByteAssert; import org.assertj.core.api.AbstractDoubleAssert; import org.assertj.core.api.AbstractFloatAssert; @@ -23,102 +22,6 @@ final class AssertJNumberTemplates { private AssertJNumberTemplates() {} - static final class AssertThatIsEqualTo { - @BeforeTemplate - AbstractBooleanAssert before(boolean actual, boolean expected) { - return Refaster.anyOf( - assertThat(actual == expected).isTrue(), assertThat(actual != expected).isFalse()); - } - - @BeforeTemplate - AbstractBooleanAssert before(double actual, double expected) { - return Refaster.anyOf( - assertThat(actual == expected).isTrue(), assertThat(actual != expected).isFalse()); - } - - @AfterTemplate - @UseImportPolicy(STATIC_IMPORT_ALWAYS) - AbstractBooleanAssert after(boolean actual, boolean expected) { - return assertThat(actual).isEqualTo(expected); - } - } - - static final class AssertThatIsNotEqualTo { - @BeforeTemplate - AbstractBooleanAssert before(boolean actual, boolean expected) { - return Refaster.anyOf( - assertThat(actual != expected).isTrue(), assertThat(actual == expected).isFalse()); - } - - @BeforeTemplate - AbstractBooleanAssert before(double actual, double expected) { - return Refaster.anyOf( - assertThat(actual != expected).isTrue(), assertThat(actual == expected).isFalse()); - } - - @AfterTemplate - @UseImportPolicy(STATIC_IMPORT_ALWAYS) - AbstractBooleanAssert after(boolean actual, boolean expected) { - return assertThat(actual).isNotEqualTo(expected); - } - } - - static final class AssertThatIsLessThan { - @BeforeTemplate - AbstractBooleanAssert before(double actual, double expected) { - return Refaster.anyOf( - assertThat(actual < expected).isTrue(), assertThat(actual >= expected).isFalse()); - } - - @AfterTemplate - @UseImportPolicy(STATIC_IMPORT_ALWAYS) - AbstractDoubleAssert after(double actual, double expected) { - return assertThat(actual).isLessThan(expected); - } - } - - static final class AssertThatIsLessThanOrEqualTo { - @BeforeTemplate - AbstractBooleanAssert before(double actual, double expected) { - return Refaster.anyOf( - assertThat(actual <= expected).isTrue(), assertThat(actual > expected).isFalse()); - } - - @AfterTemplate - @UseImportPolicy(STATIC_IMPORT_ALWAYS) - AbstractDoubleAssert after(double actual, double expected) { - return assertThat(actual).isLessThanOrEqualTo(expected); - } - } - - static final class AssertThatIsGreaterThan { - @BeforeTemplate - AbstractBooleanAssert before(double actual, double expected) { - return Refaster.anyOf( - assertThat(actual > expected).isTrue(), assertThat(actual <= expected).isFalse()); - } - - @AfterTemplate - @UseImportPolicy(STATIC_IMPORT_ALWAYS) - AbstractDoubleAssert after(double actual, double expected) { - return assertThat(actual).isGreaterThan(expected); - } - } - - static final class AssertThatIsGreaterThanOrEqualTo { - @BeforeTemplate - AbstractBooleanAssert before(double actual, double expected) { - return Refaster.anyOf( - assertThat(actual >= expected).isTrue(), assertThat(actual < expected).isFalse()); - } - - @AfterTemplate - @UseImportPolicy(STATIC_IMPORT_ALWAYS) - AbstractDoubleAssert after(double actual, double expected) { - return assertThat(actual).isGreaterThanOrEqualTo(expected); - } - } - static final class NumberAssertIsPositive { @BeforeTemplate AbstractByteAssert before(AbstractByteAssert numberAssert) { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplates.java new file mode 100644 index 00000000000..202b3e735b4 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplates.java @@ -0,0 +1,111 @@ +package tech.picnic.errorprone.refastertemplates; + +import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.errorprone.refaster.Refaster; +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; +import com.google.errorprone.refaster.annotation.UseImportPolicy; +import org.assertj.core.api.AbstractBooleanAssert; +import org.assertj.core.api.AbstractDoubleAssert; + +final class AssertJPrimitivesTemplates { + private AssertJPrimitivesTemplates() {} + + static final class AssertThatIsEqualTo { + @BeforeTemplate + AbstractBooleanAssert before(boolean actual, boolean expected) { + return Refaster.anyOf( + assertThat(actual == expected).isTrue(), assertThat(actual != expected).isFalse()); + } + + @BeforeTemplate + AbstractBooleanAssert before(double actual, double expected) { + return Refaster.anyOf( + assertThat(actual == expected).isTrue(), assertThat(actual != expected).isFalse()); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractBooleanAssert after(boolean actual, boolean expected) { + return assertThat(actual).isEqualTo(expected); + } + } + + static final class AssertThatIsNotEqualTo { + @BeforeTemplate + AbstractBooleanAssert before(boolean actual, boolean expected) { + return Refaster.anyOf( + assertThat(actual != expected).isTrue(), assertThat(actual == expected).isFalse()); + } + + @BeforeTemplate + AbstractBooleanAssert before(double actual, double expected) { + return Refaster.anyOf( + assertThat(actual != expected).isTrue(), assertThat(actual == expected).isFalse()); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractBooleanAssert after(boolean actual, boolean expected) { + return assertThat(actual).isNotEqualTo(expected); + } + } + + static final class AssertThatIsLessThan { + @BeforeTemplate + AbstractBooleanAssert before(double actual, double expected) { + return Refaster.anyOf( + assertThat(actual < expected).isTrue(), assertThat(actual >= expected).isFalse()); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractDoubleAssert after(double actual, double expected) { + return assertThat(actual).isLessThan(expected); + } + } + + static final class AssertThatIsLessThanOrEqualTo { + @BeforeTemplate + AbstractBooleanAssert before(double actual, double expected) { + return Refaster.anyOf( + assertThat(actual <= expected).isTrue(), assertThat(actual > expected).isFalse()); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractDoubleAssert after(double actual, double expected) { + return assertThat(actual).isLessThanOrEqualTo(expected); + } + } + + static final class AssertThatIsGreaterThan { + @BeforeTemplate + AbstractBooleanAssert before(double actual, double expected) { + return Refaster.anyOf( + assertThat(actual > expected).isTrue(), assertThat(actual <= expected).isFalse()); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractDoubleAssert after(double actual, double expected) { + return assertThat(actual).isGreaterThan(expected); + } + } + + static final class AssertThatIsGreaterThanOrEqualTo { + @BeforeTemplate + AbstractBooleanAssert before(double actual, double expected) { + return Refaster.anyOf( + assertThat(actual >= expected).isTrue(), assertThat(actual < expected).isFalse()); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractDoubleAssert after(double actual, double expected) { + return assertThat(actual).isGreaterThanOrEqualTo(expected); + } + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java index b0c235bdf09..3880f627471 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java @@ -29,6 +29,7 @@ final class RefasterTemplatesTest { AssertJMapTemplates.class, AssertJObjectTemplates.class, AssertJOptionalTemplates.class, + AssertJPrimitivesTemplates.class, AssertJShortTemplates.class, AssertJStringTemplates.class, AssertJThrowingCallableTemplates.class, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java index a231d8c7e6d..9b31b3c3070 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java @@ -5,125 +5,10 @@ import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; import java.math.BigInteger; -import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.NumberAssert; import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJNumberTemplatesTest implements RefasterTemplateTestCase { - @SuppressWarnings("SimplifyBooleanExpression") - ImmutableSet> testAssertThatIsEqualTo() { - return ImmutableSet.of( - assertThat(true == false).isTrue(), - assertThat(true != false).isFalse(), - assertThat((byte) 1 == (byte) 2).isTrue(), - assertThat((byte) 1 != (byte) 2).isFalse(), - assertThat((char) 1 == (char) 2).isTrue(), - assertThat((char) 1 != (char) 2).isFalse(), - assertThat((short) 1 == (short) 2).isTrue(), - assertThat((short) 1 != (short) 2).isFalse(), - assertThat(1 == 2).isTrue(), - assertThat(1 != 2).isFalse(), - assertThat(1L == 2L).isTrue(), - assertThat(1L != 2L).isFalse(), - assertThat(1F == 2F).isTrue(), - assertThat(1F != 2F).isFalse(), - assertThat(1.0 == 2.0).isTrue(), - assertThat(1.0 != 2.0).isFalse()); - } - - @SuppressWarnings("SimplifyBooleanExpression") - ImmutableSet> testAssertThatIsNotEqualTo() { - return ImmutableSet.of( - assertThat(true != false).isTrue(), - assertThat(true == false).isFalse(), - assertThat((byte) 1 != (byte) 2).isTrue(), - assertThat((byte) 1 == (byte) 2).isFalse(), - assertThat((char) 1 != (char) 2).isTrue(), - assertThat((char) 1 == (char) 2).isFalse(), - assertThat((short) 1 != (short) 2).isTrue(), - assertThat((short) 1 == (short) 2).isFalse(), - assertThat(1 != 2).isTrue(), - assertThat(1 == 2).isFalse(), - assertThat(1L != 2L).isTrue(), - assertThat(1L == 2L).isFalse(), - assertThat(1F != 2F).isTrue(), - assertThat(1F == 2F).isFalse(), - assertThat(1.0 != 2.0).isTrue(), - assertThat(1.0 == 2.0).isFalse()); - } - - ImmutableSet> testAssertThatIsLessThan() { - return ImmutableSet.of( - assertThat((byte) 1 < (byte) 2).isTrue(), - assertThat((byte) 1 >= (byte) 2).isFalse(), - assertThat((char) 1 < (char) 2).isTrue(), - assertThat((char) 1 >= (char) 2).isFalse(), - assertThat((short) 1 < (short) 2).isTrue(), - assertThat((short) 1 >= (short) 2).isFalse(), - assertThat(1 < 2).isTrue(), - assertThat(1 >= 2).isFalse(), - assertThat(1L < 2L).isTrue(), - assertThat(1L >= 2L).isFalse(), - assertThat(1F < 2F).isTrue(), - assertThat(1F >= 2F).isFalse(), - assertThat(1.0 < 2.0).isTrue(), - assertThat(1.0 >= 2.0).isFalse()); - } - - ImmutableSet> testAssertThatIsLessThanOrEqualTo() { - return ImmutableSet.of( - assertThat((byte) 1 <= (byte) 2).isTrue(), - assertThat((byte) 1 > (byte) 2).isFalse(), - assertThat((char) 1 <= (char) 2).isTrue(), - assertThat((char) 1 > (char) 2).isFalse(), - assertThat((short) 1 <= (short) 2).isTrue(), - assertThat((short) 1 > (short) 2).isFalse(), - assertThat(1 <= 2).isTrue(), - assertThat(1 > 2).isFalse(), - assertThat(1L <= 2L).isTrue(), - assertThat(1L > 2L).isFalse(), - assertThat(1F <= 2F).isTrue(), - assertThat(1F > 2F).isFalse(), - assertThat(1.0 <= 2.0).isTrue(), - assertThat(1.0 > 2.0).isFalse()); - } - - ImmutableSet> testAssertThatIsGreaterThan() { - return ImmutableSet.of( - assertThat((byte) 1 > (byte) 2).isTrue(), - assertThat((byte) 1 <= (byte) 2).isFalse(), - assertThat((char) 1 > (char) 2).isTrue(), - assertThat((char) 1 <= (char) 2).isFalse(), - assertThat((short) 1 > (short) 2).isTrue(), - assertThat((short) 1 <= (short) 2).isFalse(), - assertThat(1 > 2).isTrue(), - assertThat(1 <= 2).isFalse(), - assertThat(1L > 2L).isTrue(), - assertThat(1L <= 2L).isFalse(), - assertThat(1F > 2F).isTrue(), - assertThat(1F <= 2F).isFalse(), - assertThat(1.0 > 2.0).isTrue(), - assertThat(1.0 <= 2.0).isFalse()); - } - - ImmutableSet> testAssertThatIsGreaterThanOrEqualTo() { - return ImmutableSet.of( - assertThat((byte) 1 >= (byte) 2).isTrue(), - assertThat((byte) 1 < (byte) 2).isFalse(), - assertThat((char) 1 >= (char) 2).isTrue(), - assertThat((char) 1 < (char) 2).isFalse(), - assertThat((short) 1 >= (short) 2).isTrue(), - assertThat((short) 1 < (short) 2).isFalse(), - assertThat(1 >= 2).isTrue(), - assertThat(1 < 2).isFalse(), - assertThat(1L >= 2L).isTrue(), - assertThat(1L < 2L).isFalse(), - assertThat(1F >= 2F).isTrue(), - assertThat(1F < 2F).isFalse(), - assertThat(1.0 >= 2.0).isTrue(), - assertThat(1.0 < 2.0).isFalse()); - } - ImmutableSet> testNumberAssertIsPositive() { return ImmutableSet.of( assertThat((byte) 0).isGreaterThan((byte) 0), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java index 3f1b18e89d9..36a4479d5e7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java @@ -5,125 +5,10 @@ import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; import java.math.BigInteger; -import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.NumberAssert; import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJNumberTemplatesTest implements RefasterTemplateTestCase { - @SuppressWarnings("SimplifyBooleanExpression") - ImmutableSet> testAssertThatIsEqualTo() { - return ImmutableSet.of( - assertThat(true).isEqualTo(false), - assertThat(true).isEqualTo(false), - assertThat((byte) 1).isEqualTo((byte) 2), - assertThat((byte) 1).isEqualTo((byte) 2), - assertThat((char) 1).isEqualTo((char) 2), - assertThat((char) 1).isEqualTo((char) 2), - assertThat((short) 1).isEqualTo((short) 2), - assertThat((short) 1).isEqualTo((short) 2), - assertThat(1).isEqualTo(2), - assertThat(1).isEqualTo(2), - assertThat(1L).isEqualTo(2L), - assertThat(1L).isEqualTo(2L), - assertThat(1F).isEqualTo(2F), - assertThat(1F).isEqualTo(2F), - assertThat(1.0).isEqualTo(2.0), - assertThat(1.0).isEqualTo(2.0)); - } - - @SuppressWarnings("SimplifyBooleanExpression") - ImmutableSet> testAssertThatIsNotEqualTo() { - return ImmutableSet.of( - assertThat(true).isNotEqualTo(false), - assertThat(true).isNotEqualTo(false), - assertThat((byte) 1).isNotEqualTo((byte) 2), - assertThat((byte) 1).isNotEqualTo((byte) 2), - assertThat((char) 1).isNotEqualTo((char) 2), - assertThat((char) 1).isNotEqualTo((char) 2), - assertThat((short) 1).isNotEqualTo((short) 2), - assertThat((short) 1).isNotEqualTo((short) 2), - assertThat(1).isNotEqualTo(2), - assertThat(1).isNotEqualTo(2), - assertThat(1L).isNotEqualTo(2L), - assertThat(1L).isNotEqualTo(2L), - assertThat(1F).isNotEqualTo(2F), - assertThat(1F).isNotEqualTo(2F), - assertThat(1.0).isNotEqualTo(2.0), - assertThat(1.0).isNotEqualTo(2.0)); - } - - ImmutableSet> testAssertThatIsLessThan() { - return ImmutableSet.of( - assertThat((byte) 1).isLessThan((byte) 2), - assertThat((byte) 1).isLessThan((byte) 2), - assertThat((char) 1).isLessThan((char) 2), - assertThat((char) 1).isLessThan((char) 2), - assertThat((short) 1).isLessThan((short) 2), - assertThat((short) 1).isLessThan((short) 2), - assertThat(1).isLessThan(2), - assertThat(1).isLessThan(2), - assertThat(1L).isLessThan(2L), - assertThat(1L).isLessThan(2L), - assertThat(1F).isLessThan(2F), - assertThat(1F).isLessThan(2F), - assertThat(1.0).isLessThan(2.0), - assertThat(1.0).isLessThan(2.0)); - } - - ImmutableSet> testAssertThatIsLessThanOrEqualTo() { - return ImmutableSet.of( - assertThat((byte) 1).isLessThanOrEqualTo((byte) 2), - assertThat((byte) 1).isLessThanOrEqualTo((byte) 2), - assertThat((char) 1).isLessThanOrEqualTo((char) 2), - assertThat((char) 1).isLessThanOrEqualTo((char) 2), - assertThat((short) 1).isLessThanOrEqualTo((short) 2), - assertThat((short) 1).isLessThanOrEqualTo((short) 2), - assertThat(1).isLessThanOrEqualTo(2), - assertThat(1).isLessThanOrEqualTo(2), - assertThat(1L).isLessThanOrEqualTo(2L), - assertThat(1L).isLessThanOrEqualTo(2L), - assertThat(1F).isLessThanOrEqualTo(2F), - assertThat(1F).isLessThanOrEqualTo(2F), - assertThat(1.0).isLessThanOrEqualTo(2.0), - assertThat(1.0).isLessThanOrEqualTo(2.0)); - } - - ImmutableSet> testAssertThatIsGreaterThan() { - return ImmutableSet.of( - assertThat((byte) 1).isGreaterThan((byte) 2), - assertThat((byte) 1).isGreaterThan((byte) 2), - assertThat((char) 1).isGreaterThan((char) 2), - assertThat((char) 1).isGreaterThan((char) 2), - assertThat((short) 1).isGreaterThan((short) 2), - assertThat((short) 1).isGreaterThan((short) 2), - assertThat(1).isGreaterThan(2), - assertThat(1).isGreaterThan(2), - assertThat(1L).isGreaterThan(2L), - assertThat(1L).isGreaterThan(2L), - assertThat(1F).isGreaterThan(2F), - assertThat(1F).isGreaterThan(2F), - assertThat(1.0).isGreaterThan(2.0), - assertThat(1.0).isGreaterThan(2.0)); - } - - ImmutableSet> testAssertThatIsGreaterThanOrEqualTo() { - return ImmutableSet.of( - assertThat((byte) 1).isGreaterThanOrEqualTo((byte) 2), - assertThat((byte) 1).isGreaterThanOrEqualTo((byte) 2), - assertThat((char) 1).isGreaterThanOrEqualTo((char) 2), - assertThat((char) 1).isGreaterThanOrEqualTo((char) 2), - assertThat((short) 1).isGreaterThanOrEqualTo((short) 2), - assertThat((short) 1).isGreaterThanOrEqualTo((short) 2), - assertThat(1).isGreaterThanOrEqualTo(2), - assertThat(1).isGreaterThanOrEqualTo(2), - assertThat(1L).isGreaterThanOrEqualTo(2L), - assertThat(1L).isGreaterThanOrEqualTo(2L), - assertThat(1F).isGreaterThanOrEqualTo(2F), - assertThat(1F).isGreaterThanOrEqualTo(2F), - assertThat(1.0).isGreaterThanOrEqualTo(2.0), - assertThat(1.0).isGreaterThanOrEqualTo(2.0)); - } - ImmutableSet> testNumberAssertIsPositive() { return ImmutableSet.of( assertThat((byte) 0).isPositive(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplatesTestInput.java new file mode 100644 index 00000000000..fd07a1d8bda --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplatesTestInput.java @@ -0,0 +1,123 @@ +package tech.picnic.errorprone.refastertemplates; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.collect.ImmutableSet; +import org.assertj.core.api.AbstractAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; + +final class AssertJStringTemplatesTest implements RefasterTemplateTestCase { + @SuppressWarnings("SimplifyBooleanExpression") + ImmutableSet> testAssertThatIsEqualTo() { + return ImmutableSet.of( + assertThat(true == false).isTrue(), + assertThat(true != false).isFalse(), + assertThat((byte) 1 == (byte) 2).isTrue(), + assertThat((byte) 1 != (byte) 2).isFalse(), + assertThat((char) 1 == (char) 2).isTrue(), + assertThat((char) 1 != (char) 2).isFalse(), + assertThat((short) 1 == (short) 2).isTrue(), + assertThat((short) 1 != (short) 2).isFalse(), + assertThat(1 == 2).isTrue(), + assertThat(1 != 2).isFalse(), + assertThat(1L == 2L).isTrue(), + assertThat(1L != 2L).isFalse(), + assertThat(1F == 2F).isTrue(), + assertThat(1F != 2F).isFalse(), + assertThat(1.0 == 2.0).isTrue(), + assertThat(1.0 != 2.0).isFalse()); + } + + @SuppressWarnings("SimplifyBooleanExpression") + ImmutableSet> testAssertThatIsNotEqualTo() { + return ImmutableSet.of( + assertThat(true != false).isTrue(), + assertThat(true == false).isFalse(), + assertThat((byte) 1 != (byte) 2).isTrue(), + assertThat((byte) 1 == (byte) 2).isFalse(), + assertThat((char) 1 != (char) 2).isTrue(), + assertThat((char) 1 == (char) 2).isFalse(), + assertThat((short) 1 != (short) 2).isTrue(), + assertThat((short) 1 == (short) 2).isFalse(), + assertThat(1 != 2).isTrue(), + assertThat(1 == 2).isFalse(), + assertThat(1L != 2L).isTrue(), + assertThat(1L == 2L).isFalse(), + assertThat(1F != 2F).isTrue(), + assertThat(1F == 2F).isFalse(), + assertThat(1.0 != 2.0).isTrue(), + assertThat(1.0 == 2.0).isFalse()); + } + + ImmutableSet> testAssertThatIsLessThan() { + return ImmutableSet.of( + assertThat((byte) 1 < (byte) 2).isTrue(), + assertThat((byte) 1 >= (byte) 2).isFalse(), + assertThat((char) 1 < (char) 2).isTrue(), + assertThat((char) 1 >= (char) 2).isFalse(), + assertThat((short) 1 < (short) 2).isTrue(), + assertThat((short) 1 >= (short) 2).isFalse(), + assertThat(1 < 2).isTrue(), + assertThat(1 >= 2).isFalse(), + assertThat(1L < 2L).isTrue(), + assertThat(1L >= 2L).isFalse(), + assertThat(1F < 2F).isTrue(), + assertThat(1F >= 2F).isFalse(), + assertThat(1.0 < 2.0).isTrue(), + assertThat(1.0 >= 2.0).isFalse()); + } + + ImmutableSet> testAssertThatIsLessThanOrEqualTo() { + return ImmutableSet.of( + assertThat((byte) 1 <= (byte) 2).isTrue(), + assertThat((byte) 1 > (byte) 2).isFalse(), + assertThat((char) 1 <= (char) 2).isTrue(), + assertThat((char) 1 > (char) 2).isFalse(), + assertThat((short) 1 <= (short) 2).isTrue(), + assertThat((short) 1 > (short) 2).isFalse(), + assertThat(1 <= 2).isTrue(), + assertThat(1 > 2).isFalse(), + assertThat(1L <= 2L).isTrue(), + assertThat(1L > 2L).isFalse(), + assertThat(1F <= 2F).isTrue(), + assertThat(1F > 2F).isFalse(), + assertThat(1.0 <= 2.0).isTrue(), + assertThat(1.0 > 2.0).isFalse()); + } + + ImmutableSet> testAssertThatIsGreaterThan() { + return ImmutableSet.of( + assertThat((byte) 1 > (byte) 2).isTrue(), + assertThat((byte) 1 <= (byte) 2).isFalse(), + assertThat((char) 1 > (char) 2).isTrue(), + assertThat((char) 1 <= (char) 2).isFalse(), + assertThat((short) 1 > (short) 2).isTrue(), + assertThat((short) 1 <= (short) 2).isFalse(), + assertThat(1 > 2).isTrue(), + assertThat(1 <= 2).isFalse(), + assertThat(1L > 2L).isTrue(), + assertThat(1L <= 2L).isFalse(), + assertThat(1F > 2F).isTrue(), + assertThat(1F <= 2F).isFalse(), + assertThat(1.0 > 2.0).isTrue(), + assertThat(1.0 <= 2.0).isFalse()); + } + + ImmutableSet> testAssertThatIsGreaterThanOrEqualTo() { + return ImmutableSet.of( + assertThat((byte) 1 >= (byte) 2).isTrue(), + assertThat((byte) 1 < (byte) 2).isFalse(), + assertThat((char) 1 >= (char) 2).isTrue(), + assertThat((char) 1 < (char) 2).isFalse(), + assertThat((short) 1 >= (short) 2).isTrue(), + assertThat((short) 1 < (short) 2).isFalse(), + assertThat(1 >= 2).isTrue(), + assertThat(1 < 2).isFalse(), + assertThat(1L >= 2L).isTrue(), + assertThat(1L < 2L).isFalse(), + assertThat(1F >= 2F).isTrue(), + assertThat(1F < 2F).isFalse(), + assertThat(1.0 >= 2.0).isTrue(), + assertThat(1.0 < 2.0).isFalse()); + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplatesTestOutput.java new file mode 100644 index 00000000000..b3bfc451ffa --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplatesTestOutput.java @@ -0,0 +1,123 @@ +package tech.picnic.errorprone.refastertemplates; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.collect.ImmutableSet; +import org.assertj.core.api.AbstractAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; + +final class AssertJStringTemplatesTest implements RefasterTemplateTestCase { + @SuppressWarnings("SimplifyBooleanExpression") + ImmutableSet> testAssertThatIsEqualTo() { + return ImmutableSet.of( + assertThat(true).isEqualTo(false), + assertThat(true).isEqualTo(false), + assertThat((byte) 1).isEqualTo((byte) 2), + assertThat((byte) 1).isEqualTo((byte) 2), + assertThat((char) 1).isEqualTo((char) 2), + assertThat((char) 1).isEqualTo((char) 2), + assertThat((short) 1).isEqualTo((short) 2), + assertThat((short) 1).isEqualTo((short) 2), + assertThat(1).isEqualTo(2), + assertThat(1).isEqualTo(2), + assertThat(1L).isEqualTo(2L), + assertThat(1L).isEqualTo(2L), + assertThat(1F).isEqualTo(2F), + assertThat(1F).isEqualTo(2F), + assertThat(1.0).isEqualTo(2.0), + assertThat(1.0).isEqualTo(2.0)); + } + + @SuppressWarnings("SimplifyBooleanExpression") + ImmutableSet> testAssertThatIsNotEqualTo() { + return ImmutableSet.of( + assertThat(true).isNotEqualTo(false), + assertThat(true).isNotEqualTo(false), + assertThat((byte) 1).isNotEqualTo((byte) 2), + assertThat((byte) 1).isNotEqualTo((byte) 2), + assertThat((char) 1).isNotEqualTo((char) 2), + assertThat((char) 1).isNotEqualTo((char) 2), + assertThat((short) 1).isNotEqualTo((short) 2), + assertThat((short) 1).isNotEqualTo((short) 2), + assertThat(1).isNotEqualTo(2), + assertThat(1).isNotEqualTo(2), + assertThat(1L).isNotEqualTo(2L), + assertThat(1L).isNotEqualTo(2L), + assertThat(1F).isNotEqualTo(2F), + assertThat(1F).isNotEqualTo(2F), + assertThat(1.0).isNotEqualTo(2.0), + assertThat(1.0).isNotEqualTo(2.0)); + } + + ImmutableSet> testAssertThatIsLessThan() { + return ImmutableSet.of( + assertThat((byte) 1).isLessThan((byte) 2), + assertThat((byte) 1).isLessThan((byte) 2), + assertThat((char) 1).isLessThan((char) 2), + assertThat((char) 1).isLessThan((char) 2), + assertThat((short) 1).isLessThan((short) 2), + assertThat((short) 1).isLessThan((short) 2), + assertThat(1).isLessThan(2), + assertThat(1).isLessThan(2), + assertThat(1L).isLessThan(2L), + assertThat(1L).isLessThan(2L), + assertThat(1F).isLessThan(2F), + assertThat(1F).isLessThan(2F), + assertThat(1.0).isLessThan(2.0), + assertThat(1.0).isLessThan(2.0)); + } + + ImmutableSet> testAssertThatIsLessThanOrEqualTo() { + return ImmutableSet.of( + assertThat((byte) 1).isLessThanOrEqualTo((byte) 2), + assertThat((byte) 1).isLessThanOrEqualTo((byte) 2), + assertThat((char) 1).isLessThanOrEqualTo((char) 2), + assertThat((char) 1).isLessThanOrEqualTo((char) 2), + assertThat((short) 1).isLessThanOrEqualTo((short) 2), + assertThat((short) 1).isLessThanOrEqualTo((short) 2), + assertThat(1).isLessThanOrEqualTo(2), + assertThat(1).isLessThanOrEqualTo(2), + assertThat(1L).isLessThanOrEqualTo(2L), + assertThat(1L).isLessThanOrEqualTo(2L), + assertThat(1F).isLessThanOrEqualTo(2F), + assertThat(1F).isLessThanOrEqualTo(2F), + assertThat(1.0).isLessThanOrEqualTo(2.0), + assertThat(1.0).isLessThanOrEqualTo(2.0)); + } + + ImmutableSet> testAssertThatIsGreaterThan() { + return ImmutableSet.of( + assertThat((byte) 1).isGreaterThan((byte) 2), + assertThat((byte) 1).isGreaterThan((byte) 2), + assertThat((char) 1).isGreaterThan((char) 2), + assertThat((char) 1).isGreaterThan((char) 2), + assertThat((short) 1).isGreaterThan((short) 2), + assertThat((short) 1).isGreaterThan((short) 2), + assertThat(1).isGreaterThan(2), + assertThat(1).isGreaterThan(2), + assertThat(1L).isGreaterThan(2L), + assertThat(1L).isGreaterThan(2L), + assertThat(1F).isGreaterThan(2F), + assertThat(1F).isGreaterThan(2F), + assertThat(1.0).isGreaterThan(2.0), + assertThat(1.0).isGreaterThan(2.0)); + } + + ImmutableSet> testAssertThatIsGreaterThanOrEqualTo() { + return ImmutableSet.of( + assertThat((byte) 1).isGreaterThanOrEqualTo((byte) 2), + assertThat((byte) 1).isGreaterThanOrEqualTo((byte) 2), + assertThat((char) 1).isGreaterThanOrEqualTo((char) 2), + assertThat((char) 1).isGreaterThanOrEqualTo((char) 2), + assertThat((short) 1).isGreaterThanOrEqualTo((short) 2), + assertThat((short) 1).isGreaterThanOrEqualTo((short) 2), + assertThat(1).isGreaterThanOrEqualTo(2), + assertThat(1).isGreaterThanOrEqualTo(2), + assertThat(1L).isGreaterThanOrEqualTo(2L), + assertThat(1L).isGreaterThanOrEqualTo(2L), + assertThat(1F).isGreaterThanOrEqualTo(2F), + assertThat(1F).isGreaterThanOrEqualTo(2F), + assertThat(1.0).isGreaterThanOrEqualTo(2.0), + assertThat(1.0).isGreaterThanOrEqualTo(2.0)); + } +}