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

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

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

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.AbstractStringAssert;
import org.assertj.core.api.ObjectAssert;
import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation;

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

  static final class AssertThatIsInstanceOf {
    @BeforeTemplate
    AbstractBooleanAssert before(S object) {
      return assertThat(Refaster.isInstance(object)).isTrue();
    }

    @AfterTemplate
    @UseImportPolicy(STATIC_IMPORT_ALWAYS)
    ObjectAssert after(S object) {
      return assertThat(object).isInstanceOf(Refaster.clazz());
    }
  }

  static final class AssertThatIsNotInstanceOf {
    @BeforeTemplate
    AbstractBooleanAssert before(S object) {
      return assertThat(Refaster.isInstance(object)).isFalse();
    }

    @AfterTemplate
    @UseImportPolicy(STATIC_IMPORT_ALWAYS)
    ObjectAssert after(S object) {
      return assertThat(object).isNotInstanceOf(Refaster.clazz());
    }
  }

  static final class AssertThatIsIsEqualTo {
    @BeforeTemplate
    AbstractBooleanAssert before(S object1, T object2) {
      return assertThat(object1.equals(object2)).isTrue();
    }

    @AfterTemplate
    @UseImportPolicy(STATIC_IMPORT_ALWAYS)
    ObjectAssert after(S object1, T object2) {
      return assertThat(object1).isEqualTo(object2);
    }
  }

  static final class AssertThatIsIsNotEqualTo {
    @BeforeTemplate
    AbstractBooleanAssert before(S object1, T object2) {
      return assertThat(object1.equals(object2)).isFalse();
    }

    @AfterTemplate
    @UseImportPolicy(STATIC_IMPORT_ALWAYS)
    ObjectAssert after(S object1, T object2) {
      return assertThat(object1).isNotEqualTo(object2);
    }
  }

  static final class AssertThatHasToString {
    @BeforeTemplate
    AbstractStringAssert before(T object, String str) {
      return assertThat(object.toString()).isEqualTo(str);
    }

    @AfterTemplate
    @UseImportPolicy(STATIC_IMPORT_ALWAYS)
    ObjectAssert after(T object, String str) {
      return assertThat(object).hasToString(str);
    }
  }
}