Skip to content

Commit fd360d9

Browse files
authored
Migrate all assertions to assertJ (OpenFeign#2261)
* Migrate all assertions to assertJ mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.junit5.AssertToAssertions,org.openrewrite.java.testing.assertj.Assertj * Remove obsolete testing framework * Migrate more tests for assertJ and assertThrows * Remove obsolete testing framework * Build using junit 5 * Use lambdas on tests --------- Co-authored-by: Marvin Froeder <velobr@gmail.com>
1 parent 2a72821 commit fd360d9

147 files changed

Lines changed: 4165 additions & 3960 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.mvn/jvm.config‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
1+
-XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom

‎annotation-error-decoder/pom.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@
4646

4747
<dependency>
4848
<groupId>com.squareup.okhttp3</groupId>
49-
<artifactId>mockwebserver</artifactId>
49+
<artifactId>mockwebserver3-junit5</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.junit.jupiter</groupId>
54+
<artifactId>junit-jupiter</artifactId>
5055
<scope>test</scope>
5156
</dependency>
5257
</dependencies>

‎annotation-error-decoder/src/test/java/feign/error/AbstractAnnotationErrorDecoderTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Response testResponse(int status) {
3535
}
3636

3737
Response testResponse(int status, String body) {
38-
return testResponse(status, body, new HashMap<String, Collection<String>>());
38+
return testResponse(status, body, new HashMap<>());
3939
}
4040

4141
Response testResponse(int status, String body, Map<String, Collection<String>> headers) {

‎annotation-error-decoder/src/test/java/feign/error/AnnotationErrorDecoderAnnotationInheritanceTest.java‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818
import java.lang.annotation.Retention;
1919
import java.lang.annotation.RetentionPolicy;
2020
import java.util.Arrays;
21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
23-
import org.junit.runners.Parameterized;
24-
import org.junit.runners.Parameterized.Parameter;
25-
import org.junit.runners.Parameterized.Parameters;
21+
import org.junit.jupiter.params.ParameterizedTest;
22+
import org.junit.jupiter.params.provider.MethodSource;
2623

27-
@RunWith(Parameterized.class)
2824
public class AnnotationErrorDecoderAnnotationInheritanceTest
2925
extends AbstractAnnotationErrorDecoderTest<
3026
AnnotationErrorDecoderAnnotationInheritanceTest.TestClientInterfaceWithWithMetaAnnotation> {
@@ -33,8 +29,6 @@ public Class<TestClientInterfaceWithWithMetaAnnotation> interfaceAtTest() {
3329
return TestClientInterfaceWithWithMetaAnnotation.class;
3430
}
3531

36-
@Parameters(
37-
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
3832
public static Iterable<Object[]> data() {
3933
return Arrays.asList(
4034
new Object[][] {
@@ -45,22 +39,24 @@ public static Iterable<Object[]> data() {
4539
{"Test Code Specific At Method", 403, "method2Test", MethodLevelNotFoundException.class},
4640
{"Test Code Specific At Method", 404, "method2Test", ClassLevelNotFoundException.class},
4741
});
48-
}
42+
} // first data value (0) is default
4943

50-
@Parameter // first data value (0) is default
5144
public String testType;
52-
53-
@Parameter(1)
5445
public int errorCode;
55-
56-
@Parameter(2)
5746
public String method;
58-
59-
@Parameter(3)
6047
public Class<? extends Exception> expectedExceptionClass;
6148

62-
@Test
63-
public void test() throws Exception {
49+
@MethodSource("data")
50+
@ParameterizedTest(
51+
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
52+
void test(
53+
String testType,
54+
int errorCode,
55+
String method,
56+
Class<? extends Exception> expectedExceptionClass)
57+
throws Exception {
58+
initAnnotationErrorDecoderAnnotationInheritanceTest(
59+
testType, errorCode, method, expectedExceptionClass);
6460
AnnotationErrorDecoder decoder =
6561
AnnotationErrorDecoder.builderFor(TestClientInterfaceWithWithMetaAnnotation.class).build();
6662

@@ -69,7 +65,7 @@ public void test() throws Exception {
6965
}
7066

7167
@ClassError
72-
interface TestClientInterfaceWithWithMetaAnnotation {
68+
public static interface TestClientInterfaceWithWithMetaAnnotation {
7369
@MethodError
7470
void method1Test();
7571

@@ -117,4 +113,15 @@ public MethodLevelDefaultException() {}
117113
static class MethodLevelNotFoundException extends Exception {
118114
public MethodLevelNotFoundException() {}
119115
}
116+
117+
public void initAnnotationErrorDecoderAnnotationInheritanceTest(
118+
String testType,
119+
int errorCode,
120+
String method,
121+
Class<? extends Exception> expectedExceptionClass) {
122+
this.testType = testType;
123+
this.errorCode = errorCode;
124+
this.method = method;
125+
this.expectedExceptionClass = expectedExceptionClass;
126+
}
120127
}

‎annotation-error-decoder/src/test/java/feign/error/AnnotationErrorDecoderClassInheritanceTest.java‎

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ServeErrorException;
2525
import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.UnauthenticatedOrUnauthorizedException;
2626
import java.util.Arrays;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
29-
import org.junit.runners.Parameterized;
30-
import org.junit.runners.Parameterized.Parameter;
31-
import org.junit.runners.Parameterized.Parameters;
27+
import org.junit.jupiter.params.ParameterizedTest;
28+
import org.junit.jupiter.params.provider.MethodSource;
3229

33-
@RunWith(Parameterized.class)
3430
public class AnnotationErrorDecoderClassInheritanceTest
3531
extends AbstractAnnotationErrorDecoderTest<
3632
AnnotationErrorDecoderClassInheritanceTest.GrandChild> {
@@ -40,8 +36,6 @@ public Class<GrandChild> interfaceAtTest() {
4036
return GrandChild.class;
4137
}
4238

43-
@Parameters(
44-
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
4539
public static Iterable<Object[]> data() {
4640
return Arrays.asList(
4741
new Object[][] {
@@ -78,22 +72,24 @@ public static Iterable<Object[]> data() {
7872
{"Test Default At Method", 504, "method3Test", Method3DefaultException.class},
7973
{"Test Default At Class", 504, "method2Test", ClassLevelDefaultException.class},
8074
});
81-
}
75+
} // first data value (0) is default
8276

83-
@Parameter // first data value (0) is default
8477
public String testType;
85-
86-
@Parameter(1)
8778
public int errorCode;
88-
89-
@Parameter(2)
9079
public String method;
91-
92-
@Parameter(3)
9380
public Class<? extends Exception> expectedExceptionClass;
9481

95-
@Test
96-
public void test() throws Exception {
82+
@MethodSource("data")
83+
@ParameterizedTest(
84+
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
85+
void test(
86+
String testType,
87+
int errorCode,
88+
String method,
89+
Class<? extends Exception> expectedExceptionClass)
90+
throws Exception {
91+
initAnnotationErrorDecoderClassInheritanceTest(
92+
testType, errorCode, method, expectedExceptionClass);
9793
AnnotationErrorDecoder decoder = AnnotationErrorDecoder.builderFor(GrandChild.class).build();
9894

9995
assertThat(decoder.decode(feignConfigKey(method), testResponse(errorCode)).getClass())
@@ -157,4 +153,15 @@ class ServeErrorException extends Exception {}
157153
abstract class Child implements ParentInterfaceWithErrorHandling {}
158154

159155
abstract class GrandChild extends Child {}
156+
157+
public void initAnnotationErrorDecoderClassInheritanceTest(
158+
String testType,
159+
int errorCode,
160+
String method,
161+
Class<? extends Exception> expectedExceptionClass) {
162+
this.testType = testType;
163+
this.errorCode = errorCode;
164+
this.method = method;
165+
this.expectedExceptionClass = expectedExceptionClass;
166+
}
160167
}

‎annotation-error-decoder/src/test/java/feign/error/AnnotationErrorDecoderExceptionConstructorsTest.java‎

Lines changed: 80 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,38 @@
1313
*/
1414
package feign.error;
1515

16-
import static feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors;
17-
import static feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.*;
1816
import static org.assertj.core.api.Assertions.assertThat;
1917

2018
import feign.Request;
2119
import feign.codec.Decoder;
20+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors;
21+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DeclaredDefaultConstructorException;
22+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DeclaredDefaultConstructorWithOtherConstructorsException;
23+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefaultConstructorException;
24+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForBody;
25+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForBodyAndHeaders;
26+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForBodyAndHeadersSecondOrder;
27+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForHeaders;
28+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForHeadersButNotForBody;
29+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForNonSupportedBody;
30+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithAnnotationForOptionalBody;
31+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithNoAnnotationForBody;
32+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequest;
33+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequestAndAnnotationForResponseBody;
34+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequestAndResponseBody;
35+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequestAndResponseHeadersAndOptionalResponseBody;
36+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.DefinedConstructorWithRequestAndResponseHeadersAndResponseBody;
37+
import feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.ParametersException;
2238
import feign.optionals.OptionalDecoder;
23-
import java.util.*;
24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
26-
import org.junit.runners.Parameterized;
27-
import org.junit.runners.Parameterized.Parameter;
28-
import org.junit.runners.Parameterized.Parameters;
29-
30-
@RunWith(Parameterized.class)
39+
import java.util.Arrays;
40+
import java.util.Collection;
41+
import java.util.Collections;
42+
import java.util.HashMap;
43+
import java.util.Map;
44+
import java.util.Optional;
45+
import org.junit.jupiter.params.ParameterizedTest;
46+
import org.junit.jupiter.params.provider.MethodSource;
47+
3148
public class AnnotationErrorDecoderExceptionConstructorsTest
3249
extends AbstractAnnotationErrorDecoderTest<
3350
TestClientInterfaceWithDifferentExceptionConstructors> {
@@ -43,17 +60,14 @@ public class AnnotationErrorDecoderExceptionConstructorsTest
4360
Request.Body.empty(),
4461
null);
4562
private static final feign.Request NO_REQUEST = null;
46-
private static final Map<String, Collection<String>> NON_NULL_HEADERS =
47-
new HashMap<String, Collection<String>>();
63+
private static final Map<String, Collection<String>> NON_NULL_HEADERS = new HashMap<>();
4864
private static final Map<String, Collection<String>> NO_HEADERS = null;
4965

5066
@Override
5167
public Class<TestClientInterfaceWithDifferentExceptionConstructors> interfaceAtTest() {
5268
return TestClientInterfaceWithDifferentExceptionConstructors.class;
5369
}
5470

55-
@Parameters(
56-
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
5771
public static Iterable<Object[]> data() {
5872
return Arrays.asList(
5973
new Object[][] {
@@ -186,28 +200,33 @@ public static Iterable<Object[]> data() {
186200
NON_NULL_HEADERS
187201
}
188202
});
189-
}
203+
} // first data value (0) is default
190204

191-
@Parameter // first data value (0) is default
192205
public String testName;
193-
194-
@Parameter(1)
195206
public int errorCode;
196-
197-
@Parameter(2)
198207
public Class<? extends Exception> expectedExceptionClass;
199-
200-
@Parameter(3)
201208
public Object expectedRequest;
202-
203-
@Parameter(4)
204209
public Object expectedBody;
205-
206-
@Parameter(5)
207210
public Map<String, Collection<String>> expectedHeaders;
208211

209-
@Test
210-
public void test() throws Exception {
212+
@MethodSource("data")
213+
@ParameterizedTest(
214+
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
215+
void test(
216+
String testName,
217+
int errorCode,
218+
Class<? extends Exception> expectedExceptionClass,
219+
Object expectedRequest,
220+
Object expectedBody,
221+
Map<String, Collection<String>> expectedHeaders)
222+
throws Exception {
223+
initAnnotationErrorDecoderExceptionConstructorsTest(
224+
testName,
225+
errorCode,
226+
expectedExceptionClass,
227+
expectedRequest,
228+
expectedBody,
229+
expectedHeaders);
211230
AnnotationErrorDecoder decoder =
212231
AnnotationErrorDecoder.builderFor(
213232
TestClientInterfaceWithDifferentExceptionConstructors.class)
@@ -226,8 +245,24 @@ public void test() throws Exception {
226245
assertThat(exception.headers()).isEqualTo(expectedHeaders);
227246
}
228247

229-
@Test
230-
public void testIfExceptionIsNotInTheList() throws Exception {
248+
@MethodSource("data")
249+
@ParameterizedTest(
250+
name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})")
251+
void ifExceptionIsNotInTheList(
252+
String testName,
253+
int errorCode,
254+
Class<? extends Exception> expectedExceptionClass,
255+
Object expectedRequest,
256+
Object expectedBody,
257+
Map<String, Collection<String>> expectedHeaders)
258+
throws Exception {
259+
initAnnotationErrorDecoderExceptionConstructorsTest(
260+
testName,
261+
errorCode,
262+
expectedExceptionClass,
263+
expectedRequest,
264+
expectedBody,
265+
expectedHeaders);
231266
AnnotationErrorDecoder decoder =
232267
AnnotationErrorDecoder.builderFor(
233268
TestClientInterfaceWithDifferentExceptionConstructors.class)
@@ -649,4 +684,19 @@ public Map<String, Collection<String>> headers() {
649684
}
650685
}
651686
}
687+
688+
public void initAnnotationErrorDecoderExceptionConstructorsTest(
689+
String testName,
690+
int errorCode,
691+
Class<? extends Exception> expectedExceptionClass,
692+
Object expectedRequest,
693+
Object expectedBody,
694+
Map<String, Collection<String>> expectedHeaders) {
695+
this.testName = testName;
696+
this.errorCode = errorCode;
697+
this.expectedExceptionClass = expectedExceptionClass;
698+
this.expectedRequest = expectedRequest;
699+
this.expectedBody = expectedBody;
700+
this.expectedHeaders = expectedHeaders;
701+
}
652702
}

0 commit comments

Comments
 (0)