1313 */
1414package feign .error ;
1515
16- import static feign .error .AnnotationErrorDecoderExceptionConstructorsTest .TestClientInterfaceWithDifferentExceptionConstructors ;
17- import static feign .error .AnnotationErrorDecoderExceptionConstructorsTest .TestClientInterfaceWithDifferentExceptionConstructors .*;
1816import static org .assertj .core .api .Assertions .assertThat ;
1917
2018import feign .Request ;
2119import 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 ;
2238import 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+
3148public 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