tech.picnic.errorprone.refasterrules.AssertJDoubleRules Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of error-prone-contrib Show documentation
Show all versions of error-prone-contrib Show documentation
Extra Error Prone plugins by Picnic.
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.AbstractDoubleAssert;
import org.assertj.core.data.Offset;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
@OnlineDocumentation
final class AssertJDoubleRules {
private AssertJDoubleRules() {}
static final class AbstractDoubleAssertIsCloseToWithOffset {
@BeforeTemplate
AbstractDoubleAssert> before(
AbstractDoubleAssert> doubleAssert, double n, Offset offset) {
return doubleAssert.isEqualTo(n, offset);
}
@BeforeTemplate
AbstractDoubleAssert> before(
AbstractDoubleAssert> doubleAssert, Double n, Offset offset) {
return doubleAssert.isEqualTo(n, offset);
}
@AfterTemplate
AbstractDoubleAssert> after(
AbstractDoubleAssert> doubleAssert, double n, Offset offset) {
return doubleAssert.isCloseTo(n, offset);
}
}
static final class AbstractDoubleAssertIsEqualTo {
@BeforeTemplate
AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert, double n) {
return Refaster.anyOf(
doubleAssert.isCloseTo(n, offset(0.0)), doubleAssert.isCloseTo(n, withPercentage(0.0)));
}
@AfterTemplate
AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert, double n) {
return doubleAssert.isEqualTo(n);
}
}
static final class AbstractDoubleAssertIsNotEqualTo {
@BeforeTemplate
AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert, double n) {
return Refaster.anyOf(
doubleAssert.isNotCloseTo(n, offset(0.0)),
doubleAssert.isNotCloseTo(n, withPercentage(0.0)));
}
@AfterTemplate
AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert, double n) {
return doubleAssert.isNotEqualTo(n);
}
}
static final class AbstractDoubleAssertIsZero {
@BeforeTemplate
AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert) {
return doubleAssert.isZero();
}
@AfterTemplate
AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert) {
return doubleAssert.isEqualTo(0);
}
}
static final class AbstractDoubleAssertIsNotZero {
@BeforeTemplate
AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert) {
return doubleAssert.isNotZero();
}
@AfterTemplate
AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert) {
return doubleAssert.isNotEqualTo(0);
}
}
static final class AbstractDoubleAssertIsOne {
@BeforeTemplate
AbstractDoubleAssert> before(AbstractDoubleAssert> doubleAssert) {
return doubleAssert.isOne();
}
@AfterTemplate
AbstractDoubleAssert> after(AbstractDoubleAssert> doubleAssert) {
return doubleAssert.isEqualTo(1);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy