AssertJOptionalRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$).* as compiler argument.

Table of contents
  1. AssertThatGet
  2. AbstractOptionalAssertIsPresent
  3. AssertThatIsPresent
  4. AbstractOptionalAssertIsEmpty
  5. AssertThatIsEmpty
  6. AbstractOptionalAssertHasValue
  7. AbstractOptionalAssertContainsSame
  8. AbstractOptionalAssertHasValueSatisfying
  9. AssertThatGetMatches

AssertThatGet

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AssertThatGet") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AssertThatGet).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 AbstractAssert<?, ?> testAssertThatGet() {
-  return assertThat(Optional.of(new Object()).orElseThrow());
+  return assertThat(Optional.of(new Object())).get();
 }

AbstractOptionalAssertIsPresent

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AbstractOptionalAssertIsPresent") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AbstractOptionalAssertIsPresent).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<OptionalAssert<Integer>> testAbstractOptionalAssertIsPresent() {
   return ImmutableSet.of(
-      assertThat(Optional.of(1)).isNotEmpty(),
-      assertThat(Optional.of(2)).isNotEqualTo(Optional.empty()));
+      assertThat(Optional.of(1)).isPresent(), assertThat(Optional.of(2)).isPresent());
 }

AssertThatIsPresent

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AssertThatIsPresent") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AssertThatIsPresent).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<AbstractAssert<?, ?>> testAssertThatIsPresent() {
   return ImmutableSet.of(
-      assertThat(Optional.of(1).isPresent()).isTrue(),
-      assertThat(Optional.of(2).isEmpty()).isFalse());
+      assertThat(Optional.of(1)).isPresent(), assertThat(Optional.of(2)).isPresent());
 }

AbstractOptionalAssertIsEmpty

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AbstractOptionalAssertIsEmpty") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AbstractOptionalAssertIsEmpty).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<OptionalAssert<Integer>> testAbstractOptionalAssertIsEmpty() {
   return ImmutableSet.of(
-      assertThat(Optional.of(1)).isNotPresent(),
-      assertThat(Optional.of(2)).isEqualTo(Optional.empty()));
+      assertThat(Optional.of(1)).isEmpty(), assertThat(Optional.of(2)).isEmpty());
 }

AssertThatIsEmpty

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AssertThatIsEmpty") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AssertThatIsEmpty).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<AbstractAssert<?, ?>> testAssertThatIsEmpty() {
   return ImmutableSet.of(
-      assertThat(Optional.of(1).isEmpty()).isTrue(),
-      assertThat(Optional.of(2).isPresent()).isFalse());
+      assertThat(Optional.of(1)).isEmpty(), assertThat(Optional.of(2)).isEmpty());
 }

AbstractOptionalAssertHasValue

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AbstractOptionalAssertHasValue") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AbstractOptionalAssertHasValue).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<AbstractAssert<?, ?>> testAbstractOptionalAssertHasValue() {
   return ImmutableSet.of(
-      assertThat(Optional.of(1)).get().isEqualTo(1),
-      assertThat(Optional.of(2)).isEqualTo(Optional.of(2)),
-      assertThat(Optional.of(3)).contains(3),
-      assertThat(Optional.of(4)).isPresent().hasValue(4));
+      assertThat(Optional.of(1)).hasValue(1),
+      assertThat(Optional.of(2)).hasValue(2),
+      assertThat(Optional.of(3)).hasValue(3),
+      assertThat(Optional.of(4)).hasValue(4));
 }

AbstractOptionalAssertContainsSame

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AbstractOptionalAssertContainsSame") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AbstractOptionalAssertContainsSame).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<AbstractAssert<?, ?>> testAbstractOptionalAssertContainsSame() {
   return ImmutableSet.of(
-      assertThat(Optional.of(1)).get().isSameAs(1),
-      assertThat(Optional.of(2)).isPresent().isSameAs(2));
+      assertThat(Optional.of(1)).containsSame(1), assertThat(Optional.of(2)).containsSame(2));
 }

AbstractOptionalAssertHasValueSatisfying

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AbstractOptionalAssertHasValueSatisfying") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AbstractOptionalAssertHasValueSatisfying).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<AbstractAssert<?, ?>> testAbstractOptionalAssertHasValueSatisfying() {
   return ImmutableSet.of(
-      assertThat(Optional.of(Path.of("foo"))).get().satisfies((Consumer<Path>) Object::toString),
+      assertThat(Optional.of(Path.of("foo")))
+          .hasValueSatisfying((Consumer<Path>) Object::toString),
       assertThat(Optional.of(Path.of("baz"))).get().satisfies(Files::readString),
-      assertThat(Optional.of(Path.of("bar"))).get().satisfies(Object::toString));
+      assertThat(Optional.of(Path.of("bar"))).hasValueSatisfying(Object::toString));
 }

AssertThatGetMatches

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AssertThatGetMatches") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!AssertJOptionalRules\$AssertThatGetMatches).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 AbstractAssert<?, ?> testAssertThatGetMatches() {
-  return assertThat(Optional.of("foo").filter(String::isEmpty)).isPresent();
+  return assertThat(Optional.of("foo")).get().matches(String::isEmpty);
 }

Copyright © 2017-2026 Picnic Technologies BV