TestNGToAssertJRules

SUGGESTION

Simplification

View source code on GitHub

Suppression

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

Table of contents
  1. Fail
  2. FailWithMessage
  3. FailWithMessageAndThrowable
  4. AssertTrue
  5. AssertTrueWithMessage
  6. AssertFalse
  7. AssertFalseWithMessage
  8. AssertNull
  9. AssertNullWithMessage
  10. AssertNotNull
  11. AssertNotNullWithMessage
  12. AssertSame
  13. AssertSameWithMessage
  14. AssertNotSame
  15. AssertNotSameWithMessage
  16. AssertEqual
  17. AssertEqualWithMessage
  18. AssertEqualFloatsWithDelta
  19. AssertEqualFloatsWithDeltaWithMessage
  20. AssertEqualDoublesWithDelta
  21. AssertEqualDoublesWithDeltaWithMessage
  22. AssertEqualArrayIterationOrder
  23. AssertEqualArrayIterationOrderWithMessage
  24. AssertEqualArraysIrrespectiveOfOrder
  25. AssertEqualArraysIrrespectiveOfOrderWithMessage
  26. AssertEqualIteratorIterationOrder
  27. AssertEqualIteratorIterationOrderWithMessage
  28. AssertEqualIterableIterationOrder
  29. AssertEqualIterableIterationOrderWithMessage
  30. AssertEqualSets
  31. AssertEqualSetsWithMessage
  32. AssertUnequal
  33. AssertUnequalWithMessage
  34. AssertUnequalFloatsWithDelta
  35. AssertUnequalFloatsWithDeltaWithMessage
  36. AssertUnequalDoublesWithDelta
  37. AssertUnequalDoublesWithDeltaWithMessage
  38. AssertThrows
  39. AssertThrowsWithType

Fail

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testFail() {
-    org.testng.Assert.fail();
+    throw new AssertionError();
   }

FailWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testFailWithMessage() {
-    org.testng.Assert.fail("foo");
+    fail("foo");
   }

FailWithMessageAndThrowable

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testFailWithMessageAndThrowable() {
-    org.testng.Assert.fail("foo", new IllegalStateException());
+    fail("foo", new IllegalStateException());
   }

AssertTrue

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertTrue() {
-    assertTrue(true);
+    assertThat(true).isTrue();
   }

AssertTrueWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertTrueWithMessage() {
-    assertTrue(true, "foo");
+    assertThat(true).withFailMessage("foo").isTrue();
   }

AssertFalse

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertFalse() {
-    assertFalse(true);
+    assertThat(true).isFalse();
   }

AssertFalseWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertFalseWithMessage() {
-    assertFalse(true, "message");
+    assertThat(true).withFailMessage("message").isFalse();
   }

AssertNull

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertNull() {
-    assertNull(new Object());
+    assertThat(new Object()).isNull();
   }

AssertNullWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertNullWithMessage() {
-    assertNull(new Object(), "foo");
+    assertThat(new Object()).withFailMessage("foo").isNull();
   }

AssertNotNull

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertNotNull() {
-    assertNotNull(new Object());
+    assertThat(new Object()).isNotNull();
   }

AssertNotNullWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertNotNullWithMessage() {
-    assertNotNull(new Object(), "foo");
+    assertThat(new Object()).withFailMessage("foo").isNotNull();
   }

AssertSame

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertSame() {
-    assertSame(new Object(), new Object());
+    assertThat(new Object()).isSameAs(new Object());
   }

AssertSameWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertSameWithMessage() {
-    assertSame(new Object(), new Object(), "foo");
+    assertThat(new Object()).withFailMessage("foo").isSameAs(new Object());
   }

AssertNotSame

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertNotSame() {
-    assertNotSame(new Object(), new Object());
+    assertThat(new Object()).isNotSameAs(new Object());
   }

AssertNotSameWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertNotSameWithMessage() {
-    assertNotSame(new Object(), new Object(), "foo");
+    assertThat(new Object()).withFailMessage("foo").isNotSameAs(new Object());
   }

AssertEqual

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqual() {
-    assertEquals(true, true);
-    assertEquals((byte) 0, (byte) 0);
-    assertEquals((char) 0, (char) 0);
-    assertEquals((short) 0, (short) 0);
-    assertEquals(0, 0);
-    assertEquals(0L, 0L);
-    assertEquals(0.0F, 0.0F);
-    assertEquals(0.0, 0.0);
-    assertEquals(new Object(), new Object());
-    assertEquals("actual", "expected");
-    assertEquals(ImmutableMap.of(), ImmutableMap.of());
+    assertThat(true).isEqualTo(true);
+    assertThat((byte) 0).isEqualTo((byte) 0);
+    assertThat((char) 0).isEqualTo((char) 0);
+    assertThat((short) 0).isEqualTo((short) 0);
+    assertThat(0).isEqualTo(0);
+    assertThat(0L).isEqualTo(0L);
+    assertThat(0.0F).isEqualTo(0.0F);
+    assertThat(0.0).isEqualTo(0.0);
+    assertThat(new Object()).isEqualTo(new Object());
+    assertThat("actual").isEqualTo("expected");
+    assertThat(ImmutableMap.of()).isEqualTo(ImmutableMap.of());
   }

AssertEqualWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualWithMessage() {
-    assertEquals(true, true, "foo");
-    assertEquals((byte) 0, (byte) 0, "bar");
-    assertEquals((char) 0, (char) 0, "baz");
-    assertEquals((short) 0, (short) 0, "qux");
-    assertEquals(0, 0, "quux");
-    assertEquals(0L, 0L, "quuz");
-    assertEquals(0.0F, 0.0F, "corge");
-    assertEquals(0.0, 0.0, "grault");
-    assertEquals(new Object(), new Object(), "garply");
-    assertEquals("actual", "expected", "waldo");
-    assertEquals(ImmutableMap.of(), ImmutableMap.of(), "plugh");
+    assertThat(true).withFailMessage("foo").isEqualTo(true);
+    assertThat((byte) 0).withFailMessage("bar").isEqualTo((byte) 0);
+    assertThat((char) 0).withFailMessage("baz").isEqualTo((char) 0);
+    assertThat((short) 0).withFailMessage("qux").isEqualTo((short) 0);
+    assertThat(0).withFailMessage("quux").isEqualTo(0);
+    assertThat(0L).withFailMessage("quuz").isEqualTo(0L);
+    assertThat(0.0F).withFailMessage("corge").isEqualTo(0.0F);
+    assertThat(0.0).withFailMessage("grault").isEqualTo(0.0);
+    assertThat(new Object()).withFailMessage("garply").isEqualTo(new Object());
+    assertThat("actual").withFailMessage("waldo").isEqualTo("expected");
+    assertThat(ImmutableMap.of()).withFailMessage("plugh").isEqualTo(ImmutableMap.of());
   }

AssertEqualFloatsWithDelta

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualFloatsWithDelta() {
-    assertEquals(0.0F, 0.0F, 0.0F);
+    assertThat(0.0F).isCloseTo(0.0F, offset(0.0F));
   }

AssertEqualFloatsWithDeltaWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualFloatsWithDeltaWithMessage() {
-    assertEquals(0.0F, 0.0F, 0.0F, "foo");
+    assertThat(0.0F).withFailMessage("foo").isCloseTo(0.0F, offset(0.0F));
   }

AssertEqualDoublesWithDelta

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualDoublesWithDelta() {
-    assertEquals(0.0, 0.0, 0.0);
+    assertThat(0.0).isCloseTo(0.0, offset(0.0));
   }

AssertEqualDoublesWithDeltaWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualDoublesWithDeltaWithMessage() {
-    assertEquals(0.0, 0.0, 0.0, "foo");
+    assertThat(0.0).withFailMessage("foo").isCloseTo(0.0, offset(0.0));
   }

AssertEqualArrayIterationOrder

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualArrayIterationOrder() {
-    assertEquals(new boolean[0], new boolean[0]);
-    assertEquals(new byte[0], new byte[0]);
-    assertEquals(new char[0], new char[0]);
-    assertEquals(new short[0], new short[0]);
-    assertEquals(new int[0], new int[0]);
-    assertEquals(new long[0], new long[0]);
-    assertEquals(new float[0], new float[0]);
-    assertEquals(new double[0], new double[0]);
-    assertEquals(new Object[0], new Object[0]);
+    assertThat(new boolean[0]).containsExactly(new boolean[0]);
+    assertThat(new byte[0]).containsExactly(new byte[0]);
+    assertThat(new char[0]).containsExactly(new char[0]);
+    assertThat(new short[0]).containsExactly(new short[0]);
+    assertThat(new int[0]).containsExactly(new int[0]);
+    assertThat(new long[0]).containsExactly(new long[0]);
+    assertThat(new float[0]).containsExactly(new float[0]);
+    assertThat(new double[0]).containsExactly(new double[0]);
+    assertThat(new Object[0]).containsExactly(new Object[0]);
   }

AssertEqualArrayIterationOrderWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualArrayIterationOrderWithMessage() {
-    assertEquals(new boolean[0], new boolean[0], "foo");
-    assertEquals(new byte[0], new byte[0], "bar");
-    assertEquals(new char[0], new char[0], "baz");
-    assertEquals(new short[0], new short[0], "qux");
-    assertEquals(new int[0], new int[0], "quux");
-    assertEquals(new long[0], new long[0], "quuz");
-    assertEquals(new float[0], new float[0], "corge");
-    assertEquals(new double[0], new double[0], "grault");
-    assertEquals(new Object[0], new Object[0], "garply");
+    assertThat(new boolean[0]).withFailMessage("foo").containsExactly(new boolean[0]);
+    assertThat(new byte[0]).withFailMessage("bar").containsExactly(new byte[0]);
+    assertThat(new char[0]).withFailMessage("baz").containsExactly(new char[0]);
+    assertThat(new short[0]).withFailMessage("qux").containsExactly(new short[0]);
+    assertThat(new int[0]).withFailMessage("quux").containsExactly(new int[0]);
+    assertThat(new long[0]).withFailMessage("quuz").containsExactly(new long[0]);
+    assertThat(new float[0]).withFailMessage("corge").containsExactly(new float[0]);
+    assertThat(new double[0]).withFailMessage("grault").containsExactly(new double[0]);
+    assertThat(new Object[0]).withFailMessage("garply").containsExactly(new Object[0]);
   }

AssertEqualArraysIrrespectiveOfOrder

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualArraysIrrespectiveOfOrder() {
-    assertEqualsNoOrder(new Object[0], new Object[0]);
+    assertThat(new Object[0]).containsExactlyInAnyOrder(new Object[0]);
   }

AssertEqualArraysIrrespectiveOfOrderWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualArraysIrrespectiveOfOrderWithMessage() {
-    assertEqualsNoOrder(new Object[0], new Object[0], "foo");
+    assertThat(new Object[0]).withFailMessage("foo").containsExactlyInAnyOrder(new Object[0]);
   }

AssertEqualIteratorIterationOrder

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualIteratorIterationOrder() {
-    assertEquals(
-        Iterators.unmodifiableIterator(new ArrayList<>().iterator()),
-        Iterators.unmodifiableIterator(new ArrayList<>().iterator()));
+    assertThat(Iterators.unmodifiableIterator(new ArrayList<>().iterator()))
+        .toIterable()
+        .containsExactlyElementsOf(
+            copyOf(Iterators.unmodifiableIterator(new ArrayList<>().iterator())));
   }

AssertEqualIteratorIterationOrderWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualIteratorIterationOrderWithMessage() {
-    assertEquals(
-        Iterators.unmodifiableIterator(new ArrayList<>().iterator()),
-        Iterators.unmodifiableIterator(new ArrayList<>().iterator()),
-        "foo");
+    assertThat(Iterators.unmodifiableIterator(new ArrayList<>().iterator()))
+        .toIterable()
+        .withFailMessage("foo")
+        .containsExactlyElementsOf(
+            copyOf(Iterators.unmodifiableIterator(new ArrayList<>().iterator())));
   }

AssertEqualIterableIterationOrder

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualIterableIterationOrder() {
-    assertEquals(
-        Iterables.unmodifiableIterable(new ArrayList<>()),
-        Iterables.unmodifiableIterable(new ArrayList<>()));
-    assertEquals(
-        Collections.synchronizedCollection(new ArrayList<>()),
-        Collections.synchronizedCollection(new ArrayList<>()));
+    assertThat(Iterables.unmodifiableIterable(new ArrayList<>()))
+        .containsExactlyElementsOf(Iterables.unmodifiableIterable(new ArrayList<>()));
+    assertThat(Collections.synchronizedCollection(new ArrayList<>()))
+        .containsExactlyElementsOf(Collections.synchronizedCollection(new ArrayList<>()));
   }

AssertEqualIterableIterationOrderWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualIterableIterationOrderWithMessage() {
-    assertEquals(
-        Iterables.unmodifiableIterable(new ArrayList<>()),
-        Iterables.unmodifiableIterable(new ArrayList<>()),
-        "foo");
-    assertEquals(
-        Collections.synchronizedCollection(new ArrayList<>()),
-        Collections.synchronizedCollection(new ArrayList<>()),
-        "bar");
+    assertThat(Iterables.unmodifiableIterable(new ArrayList<>()))
+        .withFailMessage("foo")
+        .containsExactlyElementsOf(Iterables.unmodifiableIterable(new ArrayList<>()));
+    assertThat(Collections.synchronizedCollection(new ArrayList<>()))
+        .withFailMessage("bar")
+        .containsExactlyElementsOf(Collections.synchronizedCollection(new ArrayList<>()));
   }

AssertEqualSets

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualSets() {
-    assertEquals(ImmutableSet.of(), ImmutableSet.of());
+    assertThat(ImmutableSet.of()).hasSameElementsAs(ImmutableSet.of());
   }

AssertEqualSetsWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertEqualSetsWithMessage() {
-    assertEquals(ImmutableSet.of(), ImmutableSet.of(), "foo");
+    assertThat(ImmutableSet.of()).withFailMessage("foo").hasSameElementsAs(ImmutableSet.of());
   }

AssertUnequal

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertUnequal() {
-    assertNotEquals(true, true);
-    assertNotEquals((byte) 0, (byte) 0);
-    assertNotEquals((char) 0, (char) 0);
-    assertNotEquals((short) 0, (short) 0);
-    assertNotEquals(0, 0);
-    assertNotEquals(0L, 0L);
-    assertNotEquals(0.0F, 0.0F);
-    assertNotEquals(0.0, 0.0);
-    assertNotEquals(new Object(), new Object());
-    assertNotEquals("actual", "expected");
-    assertNotEquals(ImmutableSet.of(), ImmutableSet.of());
-    assertNotEquals(ImmutableMap.of(), ImmutableMap.of());
+    assertThat(true).isNotEqualTo(true);
+    assertThat((byte) 0).isNotEqualTo((byte) 0);
+    assertThat((char) 0).isNotEqualTo((char) 0);
+    assertThat((short) 0).isNotEqualTo((short) 0);
+    assertThat(0).isNotEqualTo(0);
+    assertThat(0L).isNotEqualTo(0L);
+    assertThat(0.0F).isNotEqualTo(0.0F);
+    assertThat(0.0).isNotEqualTo(0.0);
+    assertThat(new Object()).isNotEqualTo(new Object());
+    assertThat("actual").isNotEqualTo("expected");
+    assertThat(ImmutableSet.of()).isNotEqualTo(ImmutableSet.of());
+    assertThat(ImmutableMap.of()).isNotEqualTo(ImmutableMap.of());
   }

AssertUnequalWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertUnequalWithMessage() {
-    assertNotEquals(true, true, "foo");
-    assertNotEquals((byte) 0, (byte) 0, "bar");
-    assertNotEquals((char) 0, (char) 0, "baz");
-    assertNotEquals((short) 0, (short) 0, "qux");
-    assertNotEquals(0, 0, "quux");
-    assertNotEquals(0L, 0L, "quuz");
-    assertNotEquals(0.0F, 0.0F, "corge");
-    assertNotEquals(0.0, 0.0, "grault");
-    assertNotEquals(new Object(), new Object(), "garply");
-    assertNotEquals("actual", "expected", "waldo");
-    assertNotEquals(ImmutableSet.of(), ImmutableSet.of(), "fred");
-    assertNotEquals(ImmutableMap.of(), ImmutableMap.of(), "plugh");
+    assertThat(true).withFailMessage("foo").isNotEqualTo(true);
+    assertThat((byte) 0).withFailMessage("bar").isNotEqualTo((byte) 0);
+    assertThat((char) 0).withFailMessage("baz").isNotEqualTo((char) 0);
+    assertThat((short) 0).withFailMessage("qux").isNotEqualTo((short) 0);
+    assertThat(0).withFailMessage("quux").isNotEqualTo(0);
+    assertThat(0L).withFailMessage("quuz").isNotEqualTo(0L);
+    assertThat(0.0F).withFailMessage("corge").isNotEqualTo(0.0F);
+    assertThat(0.0).withFailMessage("grault").isNotEqualTo(0.0);
+    assertThat(new Object()).withFailMessage("garply").isNotEqualTo(new Object());
+    assertThat("actual").withFailMessage("waldo").isNotEqualTo("expected");
+    assertThat(ImmutableSet.of()).withFailMessage("fred").isNotEqualTo(ImmutableSet.of());
+    assertThat(ImmutableMap.of()).withFailMessage("plugh").isNotEqualTo(ImmutableMap.of());
   }

AssertUnequalFloatsWithDelta

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertUnequalFloatsWithDelta() {
-    assertNotEquals(0.0F, 0.0F, 0.0F);
+    assertThat(0.0F).isNotCloseTo(0.0F, offset(0.0F));
   }

AssertUnequalFloatsWithDeltaWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertUnequalFloatsWithDeltaWithMessage() {
-    assertNotEquals(0.0F, 0.0F, 0.0F, "foo");
+    assertThat(0.0F).withFailMessage("foo").isNotCloseTo(0.0F, offset(0.0F));
   }

AssertUnequalDoublesWithDelta

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertUnequalDoublesWithDelta() {
-    assertNotEquals(0.0, 0.0, 0.0);
+    assertThat(0.0).isNotCloseTo(0.0, offset(0.0));
   }

AssertUnequalDoublesWithDeltaWithMessage

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertUnequalDoublesWithDeltaWithMessage() {
-    assertNotEquals(0.0, 0.0, 0.0, "foo");
+    assertThat(0.0).withFailMessage("foo").isNotCloseTo(0.0, offset(0.0));
   }

AssertThrows

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertThrows() {
-    assertThrows(() -> {});
+    assertThatThrownBy(() -> {});
   }

AssertThrowsWithType

SUGGESTION

Simplification

Suppression

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

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

Samples

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

 void testAssertThrowsWithType() {
-    assertThrows(IllegalStateException.class, () -> {});
+    assertThatThrownBy(() -> {}).isInstanceOf(IllegalStateException.class);
   }

Copyright © 2017-2024 Picnic Technologies BV