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

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

There is a newer version: 0.19.1
Show newest version
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 enumAssert) {
      Refaster.anyOf(
          enumAssert.hasSize(0),
          enumAssert.hasSizeLessThanOrEqualTo(0),
          enumAssert.hasSizeLessThan(1));
    }

    @AfterTemplate
    void after(EnumerableAssert enumAssert) {
      enumAssert.isEmpty();
    }
  }

  static final class EnumerableAssertIsNotEmpty {
    @BeforeTemplate
    EnumerableAssert before(EnumerableAssert enumAssert) {
      return Refaster.anyOf(
          enumAssert.hasSizeGreaterThan(0), enumAssert.hasSizeGreaterThanOrEqualTo(1));
    }

    @AfterTemplate
    EnumerableAssert after(EnumerableAssert enumAssert) {
      return enumAssert.isNotEmpty();
    }
  }

  static final class EnumerableAssertHasSameSizeAs {
    @BeforeTemplate
    EnumerableAssert before(EnumerableAssert enumAssert, Iterable iterable) {
      return enumAssert.hasSize(Iterables.size(iterable));
    }

    @BeforeTemplate
    EnumerableAssert before(EnumerableAssert enumAssert, Collection iterable) {
      return enumAssert.hasSize(iterable.size());
    }

    @BeforeTemplate
    EnumerableAssert before(EnumerableAssert enumAssert, T[] iterable) {
      return enumAssert.hasSize(iterable.length);
    }

    @AfterTemplate
    EnumerableAssert after(EnumerableAssert enumAssert, Iterable iterable) {
      return enumAssert.hasSameSizeAs(iterable);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy