From 13fcf5552034268a1d236b399348cc4b7338bfb5 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 16 Sep 2024 17:43:59 +0200 Subject: [PATCH] Do not `assertDoesNotThrow` when using `reactor.test.StepVerifier` --- .../cleanup/TestsShouldIncludeAssertions.java | 17 +++---- .../TestsShouldIncludeAssertionsTest.java | 46 +++++++++---------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java index 24db0e09c..9800de315 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java @@ -38,21 +38,22 @@ public class TestsShouldIncludeAssertions extends Recipe { private static final List TEST_ANNOTATIONS = Collections.singletonList("org.junit.jupiter.api.Test"); private static final List DEFAULT_ASSERTIONS = Arrays.asList( + "com.github.tomakehurst.wiremock.client.WireMock", + "io.restassured", + "mockit", "org.assertj.core.api", - "org.junit.jupiter.api.Assertions", + "org.easymock", "org.hamcrest.MatcherAssert", + "org.jmock", + "org.junit.Assert", // rarely, the test annotation is junit 5 but the assert is junit 4 + "org.junit.jupiter.api.Assertions", "org.mockito.Mockito.verify", "org.mockito.Mockito.verifyNoInteractions", "org.mockito.Mockito.verifyNoMoreInteractions", "org.mockito.Mockito.verifyZeroInteractions", - "org.easymock", - "org.jmock", - "mockit", - "io.restassured", - "org.springframework.test.web.servlet.ResultActions", "org.springframework.test.web.client.MockRestServiceServer.verify", - "com.github.tomakehurst.wiremock.client.WireMock", - "org.junit.Assert"// rarely, the test annotation is junit 5 but the assert is junit 4 + "org.springframework.test.web.servlet.ResultActions", + "reactor.test.StepVerifier" ); @Option(displayName = "Additional assertions", diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertionsTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertionsTest.java index 6b8baa713..9f9a2adc4 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertionsTest.java @@ -70,9 +70,9 @@ public void methodTest() { """, """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - + public class AaTest { @Test public void methodTest() { @@ -94,11 +94,11 @@ void hasAssertDoesNotThrowAssertion() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - + public class AaTest { - + @Test public void methodTest() { assertDoesNotThrow(() -> { @@ -119,11 +119,11 @@ void assertJAssertion() { java( """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { - + @Test public void test() { assertThat(notification()).isEqualTo(1); @@ -144,10 +144,10 @@ void hamcrestAssertion() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; - + public class ATest { @Test public void methodTest() { @@ -189,16 +189,16 @@ void methodBodyContainsMethodInvocationWithAssert() { """ import java.util.Set; import org.junit.jupiter.api.Test; - + import static org.junit.Assert.assertTrue; - + public class TestClass { @Test public void methodTest() { Set s = Set.of("hello"); testContains(s, "hello"); } - + private static void testContains(Set set, String word) { assertTrue(set.contains(word)); } @@ -218,9 +218,9 @@ void usesAdditionalAssertion() { java( """ package org.foo; - + import java.util.Set; - + public class TestUtil { public static void testContains(Set set, String word) { } @@ -252,7 +252,7 @@ public void changes() { import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import org.junit.jupiter.api.Test; - + public class TestClass { @Test public void doesNotChange() { @@ -287,7 +287,7 @@ void hasMockitoVerify() { class AaTest { @Mock MyMathService myMathService; - + @Test public void verifyTest() { when(myMathService.addIntegers("1", "2")).thenReturn(3); @@ -313,12 +313,12 @@ void hasMockitoVerifyNoInteractions() { class AaTest { @Mock org.learning.math.MyMathService myMathService; - + @Test public void noMore() { verifyNoMoreInteractions(myMathService); } - + @Test public void zero() { verifyZeroInteractions(myMathService); @@ -340,11 +340,11 @@ void hasMockitoDoesNotValidate() { import org.learning.math.MyMathService; import static org.mockito.Mockito.when; import org.learning.math.Stuff; - + class AaTest { @Mock MyMathService myMathService; - + @Test public void methodTest() { when(myMathService.addIntegers("1", "2")).thenReturn(3); @@ -360,11 +360,11 @@ public void methodTest() { import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.Mockito.when; import org.learning.math.Stuff; - + class AaTest { @Mock MyMathService myMathService; - + @Test public void methodTest() { assertDoesNotThrow(() -> {