Skip to content

Commit

Permalink
Introduce AssertJPrimitiveTemplates and move some templates
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Sep 9, 2022
1 parent 989017c commit 7885a2c
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class RefasterTemplatesTest {
AssertJMapTemplates.class,
AssertJObjectTemplates.class,
AssertJOptionalTemplates.class,
AssertJPrimitivesTemplates.class,
AssertJShortTemplates.class,
AssertJStringTemplates.class,
AssertJThrowingCallableTemplates.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractAssert<?, ?>> 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<AbstractAssert<?, ?>> 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<AbstractAssert<?, ?>> 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<AbstractAssert<?, ?>> 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<AbstractAssert<?, ?>> 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<AbstractAssert<?, ?>> 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<NumberAssert<?, ?>> testNumberAssertIsPositive() {
return ImmutableSet.of(
assertThat((byte) 0).isGreaterThan((byte) 0),
Expand Down
Loading

0 comments on commit 7885a2c

Please sign in to comment.