Skip to main content Link Search Menu Expand Document (external link)

AssertJNumberRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. NumberAssertIsPositive
  2. NumberAssertIsNotPositive
  3. NumberAssertIsNegative
  4. NumberAssertIsNotNegative
  5. AssertThatIsOdd
  6. AssertThatIsEven

NumberAssertIsPositive

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(AssertJNumberRules\.NumberAssertIsPositive)) as compiler argument.

Samples

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

 ImmutableSet<NumberAssert<?, ?>> testNumberAssertIsPositive() {
     return ImmutableSet.of(
-        assertThat((byte) 0).isGreaterThan((byte) 0),
-        assertThat((byte) 0).isGreaterThanOrEqualTo((byte) 1),
-        assertThat((short) 0).isGreaterThan((short) 0),
-        assertThat((short) 0).isGreaterThanOrEqualTo((short) 1),
-        assertThat(0).isGreaterThan(0),
-        assertThat(0).isGreaterThanOrEqualTo(1),
-        assertThat(0L).isGreaterThan(0),
-        assertThat(0L).isGreaterThanOrEqualTo(1),
-        assertThat(0.0F).isGreaterThan(0),
-        assertThat(0.0).isGreaterThan(0),
-        assertThat(BigInteger.ZERO).isGreaterThan(BigInteger.ZERO),
-        assertThat(BigInteger.ZERO).isGreaterThanOrEqualTo(BigInteger.valueOf(1)),
-        assertThat(BigDecimal.ZERO).isGreaterThan(BigDecimal.ZERO));
+        assertThat((byte) 0).isPositive(),
+        assertThat((byte) 0).isPositive(),
+        assertThat((short) 0).isPositive(),
+        assertThat((short) 0).isPositive(),
+        assertThat(0).isPositive(),
+        assertThat(0).isPositive(),
+        assertThat(0L).isPositive(),
+        assertThat(0L).isPositive(),
+        assertThat(0.0F).isPositive(),
+        assertThat(0.0).isPositive(),
+        assertThat(BigInteger.ZERO).isPositive(),
+        assertThat(BigInteger.ZERO).isPositive(),
+        assertThat(BigDecimal.ZERO).isPositive());
   }

NumberAssertIsNotPositive

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(AssertJNumberRules\.NumberAssertIsNotPositive)) as compiler argument.

Samples

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

 ImmutableSet<NumberAssert<?, ?>> testNumberAssertIsNotPositive() {
     return ImmutableSet.of(
-        assertThat((byte) 0).isLessThanOrEqualTo((byte) 0),
-        assertThat((byte) 0).isLessThan((byte) 1),
-        assertThat((short) 0).isLessThanOrEqualTo((short) 0),
-        assertThat((short) 0).isLessThan((short) 1),
-        assertThat(0).isLessThanOrEqualTo(0),
-        assertThat(0).isLessThan(1),
-        assertThat(0L).isLessThanOrEqualTo(0),
-        assertThat(0L).isLessThan(1),
-        assertThat(0.0F).isLessThanOrEqualTo(0),
-        assertThat(0.0).isLessThanOrEqualTo(0),
-        assertThat(BigInteger.ZERO).isLessThanOrEqualTo(BigInteger.ZERO),
-        assertThat(BigInteger.ZERO).isLessThan(BigInteger.valueOf(1)),
-        assertThat(BigDecimal.ZERO).isLessThanOrEqualTo(BigDecimal.ZERO));
+        assertThat((byte) 0).isNotPositive(),
+        assertThat((byte) 0).isNotPositive(),
+        assertThat((short) 0).isNotPositive(),
+        assertThat((short) 0).isNotPositive(),
+        assertThat(0).isNotPositive(),
+        assertThat(0).isNotPositive(),
+        assertThat(0L).isNotPositive(),
+        assertThat(0L).isNotPositive(),
+        assertThat(0.0F).isNotPositive(),
+        assertThat(0.0).isNotPositive(),
+        assertThat(BigInteger.ZERO).isNotPositive(),
+        assertThat(BigInteger.ZERO).isNotPositive(),
+        assertThat(BigDecimal.ZERO).isNotPositive());
   }

NumberAssertIsNegative

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(AssertJNumberRules\.NumberAssertIsNegative)) as compiler argument.

Samples

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

 ImmutableSet<NumberAssert<?, ?>> testNumberAssertIsNegative() {
     return ImmutableSet.of(
-        assertThat((byte) 0).isLessThan((byte) 0),
-        assertThat((byte) 0).isLessThanOrEqualTo((byte) -1),
-        assertThat((short) 0).isLessThan((short) 0),
-        assertThat((short) 0).isLessThanOrEqualTo((short) -1),
-        assertThat(0).isLessThan(0),
-        assertThat(0).isLessThanOrEqualTo(-1),
-        assertThat(0L).isLessThan(0),
-        assertThat(0L).isLessThanOrEqualTo(-1),
-        assertThat(0.0F).isLessThan(0),
-        assertThat(0.0).isLessThan(0),
-        assertThat(BigInteger.ZERO).isLessThan(BigInteger.ZERO),
-        assertThat(BigInteger.ZERO).isLessThanOrEqualTo(BigInteger.valueOf(-1)),
-        assertThat(BigDecimal.ZERO).isLessThan(BigDecimal.ZERO));
+        assertThat((byte) 0).isNegative(),
+        assertThat((byte) 0).isNegative(),
+        assertThat((short) 0).isNegative(),
+        assertThat((short) 0).isNegative(),
+        assertThat(0).isNegative(),
+        assertThat(0).isNegative(),
+        assertThat(0L).isNegative(),
+        assertThat(0L).isNegative(),
+        assertThat(0.0F).isNegative(),
+        assertThat(0.0).isNegative(),
+        assertThat(BigInteger.ZERO).isNegative(),
+        assertThat(BigInteger.ZERO).isNegative(),
+        assertThat(BigDecimal.ZERO).isNegative());
   }

NumberAssertIsNotNegative

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(AssertJNumberRules\.NumberAssertIsNotNegative)) as compiler argument.

Samples

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

 ImmutableSet<NumberAssert<?, ?>> testNumberAssertIsNotNegative() {
     return ImmutableSet.of(
-        assertThat((byte) 0).isGreaterThanOrEqualTo((byte) 0),
-        assertThat((byte) 0).isGreaterThan((byte) -1),
-        assertThat((short) 0).isGreaterThanOrEqualTo((short) 0),
-        assertThat((short) 0).isGreaterThan((short) -1),
-        assertThat(0).isGreaterThanOrEqualTo(0),
-        assertThat(0).isGreaterThan(-1),
-        assertThat(0L).isGreaterThanOrEqualTo(0),
-        assertThat(0L).isGreaterThan(-1),
-        assertThat(0.0F).isGreaterThanOrEqualTo(0),
-        assertThat(0.0).isGreaterThanOrEqualTo(0),
-        assertThat(BigInteger.ZERO).isGreaterThanOrEqualTo(BigInteger.ZERO),
-        assertThat(BigInteger.ZERO).isGreaterThan(BigInteger.valueOf(-1)),
-        assertThat(BigDecimal.ZERO).isGreaterThanOrEqualTo(BigDecimal.ZERO));
+        assertThat((byte) 0).isNotNegative(),
+        assertThat((byte) 0).isNotNegative(),
+        assertThat((short) 0).isNotNegative(),
+        assertThat((short) 0).isNotNegative(),
+        assertThat(0).isNotNegative(),
+        assertThat(0).isNotNegative(),
+        assertThat(0L).isNotNegative(),
+        assertThat(0L).isNotNegative(),
+        assertThat(0.0F).isNotNegative(),
+        assertThat(0.0).isNotNegative(),
+        assertThat(BigInteger.ZERO).isNotNegative(),
+        assertThat(BigInteger.ZERO).isNotNegative(),
+        assertThat(BigDecimal.ZERO).isNotNegative());
   }

AssertThatIsOdd

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(AssertJNumberRules\.AssertThatIsOdd)) as compiler argument.

Samples

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

 ImmutableSet<NumberAssert<?, ?>> testAssertThatIsOdd() {
     return ImmutableSet.of(
-        assertThat((byte) 1 % 2).isEqualTo(1),
-        assertThat(Byte.valueOf((byte) 1) % 2).isEqualTo(1),
+        assertThat((byte) 1).isOdd(),
+        assertThat(Byte.valueOf((byte) 1)).isOdd(),
         assertThat((char) 1 % 2).isEqualTo(1),
         assertThat(Character.valueOf((char) 1) % 2).isEqualTo(1),
-        assertThat((short) 1 % 2).isEqualTo(1),
-        assertThat(Short.valueOf((short) 1) % 2).isEqualTo(1),
-        assertThat(1 % 2).isEqualTo(1),
-        assertThat(Integer.valueOf(1) % 2).isEqualTo(1),
-        assertThat(1L % 2).isEqualTo(1),
-        assertThat(Long.valueOf(1) % 2).isEqualTo(1));
+        assertThat((short) 1).isOdd(),
+        assertThat(Short.valueOf((short) 1)).isOdd(),
+        assertThat(1).isOdd(),
+        assertThat(Integer.valueOf(1)).isOdd(),
+        assertThat(1L).isOdd(),
+        assertThat(Long.valueOf(1)).isOdd());
   }

AssertThatIsEven

SUGGESTION

Simplification

Suppression

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

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!(AssertJNumberRules\.AssertThatIsEven)) as compiler argument.

Samples

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

 ImmutableSet<NumberAssert<?, ?>> testAssertThatIsEven() {
     return ImmutableSet.of(
-        assertThat((byte) 1 % 2).isEqualTo(0),
-        assertThat(Byte.valueOf((byte) 1) % 2).isEqualTo(0),
+        assertThat((byte) 1).isEven(),
+        assertThat(Byte.valueOf((byte) 1)).isEven(),
         assertThat((char) 1 % 2).isEqualTo(0),
         assertThat(Character.valueOf((char) 1) % 2).isEqualTo(0),
-        assertThat((short) 1 % 2).isEqualTo(0),
-        assertThat(Short.valueOf((short) 1) % 2).isEqualTo(0),
-        assertThat(1 % 2).isEqualTo(0),
-        assertThat(Integer.valueOf(1) % 2).isEqualTo(0),
-        assertThat(1L % 2).isEqualTo(0),
-        assertThat(Long.valueOf(1) % 2).isEqualTo(0));
+        assertThat((short) 1).isEven(),
+        assertThat(Short.valueOf((short) 1)).isEven(),
+        assertThat(1).isEven(),
+        assertThat(Integer.valueOf(1)).isEven(),
+        assertThat(1L).isEven(),
+        assertThat(Long.valueOf(1)).isEven());
   }

Copyright © 2017-2023 Picnic Technologies BV