tech.picnic.errorprone.refasterrules.AssertJEnumerableRules 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 com.google.common.collect.Iterables;
import com.google.errorprone.refaster.Refaster;
import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import java.util.Collection;
import org.assertj.core.api.EnumerableAssert;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;
@OnlineDocumentation
final class AssertJEnumerableRules {
private AssertJEnumerableRules() {}
static final class EnumerableAssertIsEmpty {
@BeforeTemplate
void before(EnumerableAssert, E> enumAssert) {
Refaster.anyOf(
enumAssert.hasSize(0),
enumAssert.hasSizeLessThanOrEqualTo(0),
enumAssert.hasSizeLessThan(1));
}
@AfterTemplate
void after(EnumerableAssert, E> enumAssert) {
enumAssert.isEmpty();
}
}
static final class EnumerableAssertIsNotEmpty {
@BeforeTemplate
EnumerableAssert, E> before(EnumerableAssert, E> enumAssert) {
return Refaster.anyOf(
enumAssert.hasSizeGreaterThan(0), enumAssert.hasSizeGreaterThanOrEqualTo(1));
}
@AfterTemplate
EnumerableAssert, E> after(EnumerableAssert, E> enumAssert) {
return enumAssert.isNotEmpty();
}
}
static final class EnumerableAssertHasSameSizeAs {
@BeforeTemplate
EnumerableAssert, S> before(EnumerableAssert, S> enumAssert, Iterable iterable) {
return enumAssert.hasSize(Iterables.size(iterable));
}
@BeforeTemplate
EnumerableAssert, S> before(EnumerableAssert, S> enumAssert, Collection iterable) {
return enumAssert.hasSize(iterable.size());
}
@BeforeTemplate
EnumerableAssert, S> before(EnumerableAssert, S> enumAssert, T[] iterable) {
return enumAssert.hasSize(iterable.length);
}
@AfterTemplate
EnumerableAssert, S> after(EnumerableAssert, S> enumAssert, Iterable iterable) {
return enumAssert.hasSameSizeAs(iterable);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy