@@ -1005,37 +1005,34 @@ private static void assertSyncMethod(Method method, String apiName, List<String>
1005
1005
}
1006
1006
1007
1007
assertEquals ("incorrect number of exceptions for method [" + method + "]" , 1 , method .getExceptionTypes ().length );
1008
+ final Class <?>[] parameterTypes = method .getParameterTypes ();
1008
1009
// a few methods don't accept a request object as argument
1009
1010
if (APIS_WITHOUT_REQUEST_OBJECT .contains (apiName )) {
1010
- assertEquals ("incorrect number of arguments for method [" + method + "]" , 1 , method .getParameterTypes ().length );
1011
- assertThat (
1012
- "the parameter to method [" + method + "] is the wrong type" ,
1013
- method .getParameterTypes ()[0 ],
1014
- equalTo (RequestOptions .class )
1015
- );
1011
+ assertEquals ("incorrect number of arguments for method [" + method + "]" , 1 , method .getParameterCount ());
1012
+ assertThat ("the parameter to method [" + method + "] is the wrong type" , parameterTypes [0 ], equalTo (RequestOptions .class ));
1016
1013
} else {
1017
- assertEquals ("incorrect number of arguments for method [" + method + "]" , 2 , method .getParameterTypes (). length );
1014
+ assertEquals ("incorrect number of arguments for method [" + method + "]" , 2 , method .getParameterCount () );
1018
1015
// This is no longer true for all methods. Some methods can contain these 2 args backwards because of deprecation
1019
- if (method . getParameterTypes () [0 ].equals (RequestOptions .class )) {
1016
+ if (parameterTypes [0 ].equals (RequestOptions .class )) {
1020
1017
assertThat (
1021
1018
"the first parameter to method [" + method + "] is the wrong type" ,
1022
- method . getParameterTypes () [0 ],
1019
+ parameterTypes [0 ],
1023
1020
equalTo (RequestOptions .class )
1024
1021
);
1025
1022
assertThat (
1026
1023
"the second parameter to method [" + method + "] is the wrong type" ,
1027
- method . getParameterTypes () [1 ].getSimpleName (),
1024
+ parameterTypes [1 ].getSimpleName (),
1028
1025
endsWith ("Request" )
1029
1026
);
1030
1027
} else {
1031
1028
assertThat (
1032
1029
"the first parameter to method [" + method + "] is the wrong type" ,
1033
- method . getParameterTypes () [0 ].getSimpleName (),
1030
+ parameterTypes [0 ].getSimpleName (),
1034
1031
endsWith ("Request" )
1035
1032
);
1036
1033
assertThat (
1037
1034
"the second parameter to method [" + method + "] is the wrong type" ,
1038
- method . getParameterTypes () [1 ],
1035
+ parameterTypes [1 ],
1039
1036
equalTo (RequestOptions .class )
1040
1037
);
1041
1038
}
@@ -1049,39 +1046,40 @@ private static void assertAsyncMethod(Map<String, Set<Method>> methods, Method m
1049
1046
);
1050
1047
assertThat ("async method [" + method + "] should return Cancellable" , method .getReturnType (), equalTo (Cancellable .class ));
1051
1048
assertEquals ("async method [" + method + "] should not throw any exceptions" , 0 , method .getExceptionTypes ().length );
1049
+ final Class <?>[] parameterTypes = method .getParameterTypes ();
1052
1050
if (APIS_WITHOUT_REQUEST_OBJECT .contains (apiName .replaceAll ("_async$" , "" ))) {
1053
- assertEquals (2 , method . getParameterTypes () .length );
1054
- assertThat (method . getParameterTypes () [0 ], equalTo (RequestOptions .class ));
1055
- assertThat (method . getParameterTypes () [1 ], equalTo (ActionListener .class ));
1051
+ assertEquals (2 , parameterTypes .length );
1052
+ assertThat (parameterTypes [0 ], equalTo (RequestOptions .class ));
1053
+ assertThat (parameterTypes [1 ], equalTo (ActionListener .class ));
1056
1054
} else {
1057
- assertEquals ("async method [" + method + "] has the wrong number of arguments" , 3 , method .getParameterTypes (). length );
1055
+ assertEquals ("async method [" + method + "] has the wrong number of arguments" , 3 , method .getParameterCount () );
1058
1056
// This is no longer true for all methods. Some methods can contain these 2 args backwards because of deprecation
1059
- if (method . getParameterTypes () [0 ].equals (RequestOptions .class )) {
1057
+ if (parameterTypes [0 ].equals (RequestOptions .class )) {
1060
1058
assertThat (
1061
1059
"the first parameter to async method [" + method + "] should be a request type" ,
1062
- method . getParameterTypes () [0 ],
1060
+ parameterTypes [0 ],
1063
1061
equalTo (RequestOptions .class )
1064
1062
);
1065
1063
assertThat (
1066
1064
"the second parameter to async method [" + method + "] is the wrong type" ,
1067
- method . getParameterTypes () [1 ].getSimpleName (),
1065
+ parameterTypes [1 ].getSimpleName (),
1068
1066
endsWith ("Request" )
1069
1067
);
1070
1068
} else {
1071
1069
assertThat (
1072
1070
"the first parameter to async method [" + method + "] should be a request type" ,
1073
- method . getParameterTypes () [0 ].getSimpleName (),
1071
+ parameterTypes [0 ].getSimpleName (),
1074
1072
endsWith ("Request" )
1075
1073
);
1076
1074
assertThat (
1077
1075
"the second parameter to async method [" + method + "] is the wrong type" ,
1078
- method . getParameterTypes () [1 ],
1076
+ parameterTypes [1 ],
1079
1077
equalTo (RequestOptions .class )
1080
1078
);
1081
1079
}
1082
1080
assertThat (
1083
1081
"the third parameter to async method [" + method + "] is the wrong type" ,
1084
- method . getParameterTypes () [2 ],
1082
+ parameterTypes [2 ],
1085
1083
equalTo (ActionListener .class )
1086
1084
);
1087
1085
}
@@ -1094,16 +1092,17 @@ private static void assertSubmitTaskMethod(
1094
1092
ClientYamlSuiteRestSpec restSpec
1095
1093
) {
1096
1094
String methodName = extractMethodName (apiName );
1095
+ final Class <?>[] parameterTypes = method .getParameterTypes ();
1097
1096
assertTrue ("submit task method [" + method .getName () + "] doesn't have corresponding sync method" , methods .containsKey (methodName ));
1098
- assertEquals ("submit task method [" + method + "] has the wrong number of arguments" , 2 , method .getParameterTypes (). length );
1097
+ assertEquals ("submit task method [" + method + "] has the wrong number of arguments" , 2 , method .getParameterCount () );
1099
1098
assertThat (
1100
1099
"the first parameter to submit task method [" + method + "] is the wrong type" ,
1101
- method . getParameterTypes () [0 ].getSimpleName (),
1100
+ parameterTypes [0 ].getSimpleName (),
1102
1101
endsWith ("Request" )
1103
1102
);
1104
1103
assertThat (
1105
1104
"the second parameter to submit task method [" + method + "] is the wrong type" ,
1106
- method . getParameterTypes () [1 ],
1105
+ parameterTypes [1 ],
1107
1106
equalTo (RequestOptions .class )
1108
1107
);
1109
1108
0 commit comments