All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.picnic.errorprone.refasterrules.AssertJIntegerRules Maven / Gradle / Ivy

There is a newer version: 0.19.1
Show newest version
package tech.picnic.errorprone.refasterrules;

import static org.assertj.core.data.Offset.offset;
import static org.assertj.core.data.Percentage.withPercentage;

import com.google.errorprone.refaster.Refaster;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import org.assertj.core.api.AbstractIntegerAssert;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;

@OnlineDocumentation
final class AssertJIntegerRules {
  private AssertJIntegerRules() {}

  static final class AbstractIntegerAssertIsEqualTo {
    @BeforeTemplate
    AbstractIntegerAssert before(AbstractIntegerAssert intAssert, int n) {
      return Refaster.anyOf(
          intAssert.isCloseTo(n, offset(0)), intAssert.isCloseTo(n, withPercentage(0)));
    }

    @AfterTemplate
    AbstractIntegerAssert after(AbstractIntegerAssert intAssert, int n) {
      return intAssert.isEqualTo(n);
    }
  }

  static final class AbstractIntegerAssertIsNotEqualTo {
    @BeforeTemplate
    AbstractIntegerAssert before(AbstractIntegerAssert intAssert, int n) {
      return Refaster.anyOf(
          intAssert.isNotCloseTo(n, offset(0)), intAssert.isNotCloseTo(n, withPercentage(0)));
    }

    @AfterTemplate
    AbstractIntegerAssert after(AbstractIntegerAssert intAssert, int n) {
      return intAssert.isNotEqualTo(n);
    }
  }

  static final class AbstractIntegerAssertIsZero {
    @BeforeTemplate
    AbstractIntegerAssert before(AbstractIntegerAssert intAssert) {
      return intAssert.isZero();
    }

    @AfterTemplate
    AbstractIntegerAssert after(AbstractIntegerAssert intAssert) {
      return intAssert.isEqualTo(0);
    }
  }

  static final class AbstractIntegerAssertIsNotZero {
    @BeforeTemplate
    AbstractIntegerAssert before(AbstractIntegerAssert intAssert) {
      return intAssert.isNotZero();
    }

    @AfterTemplate
    AbstractIntegerAssert after(AbstractIntegerAssert intAssert) {
      return intAssert.isNotEqualTo(0);
    }
  }

  static final class AbstractIntegerAssertIsOne {
    @BeforeTemplate
    AbstractIntegerAssert before(AbstractIntegerAssert intAssert) {
      return intAssert.isOne();
    }

    @AfterTemplate
    AbstractIntegerAssert after(AbstractIntegerAssert intAssert) {
      return intAssert.isEqualTo(1);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy