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. AssertThatOptional
  2. AbstractOptionalAssertIsPresent
  3. AssertThatOptionalIsPresent
  4. AbstractOptionalAssertIsEmpty
  5. AssertThatOptionalIsEmpty
  6. AbstractOptionalAssertHasValue
  7. AbstractOptionalAssertContainsSame
  8. AssertThatOptionalHasValueMatching

AssertThatOptional

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 AbstractAssert<?, ?> testAssertThatOptional() {
-  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());
 }

AssertThatOptionalIsPresent

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<AbstractAssert<?, ?>> testAssertThatOptionalIsPresent() {
   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());
 }

AssertThatOptionalIsEmpty

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 ImmutableSet<AbstractAssert<?, ?>> testAssertThatOptionalIsEmpty() {
   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));
 }

AssertThatOptionalHasValueMatching

SUGGESTION

Simplification

Suppression

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

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

Samples

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

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

Copyright © 2017-2024 Picnic Technologies BV