summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilal Alsharifi <bilal.alsharifi@gmail.com>2020-10-20 10:37:05 -0400
committerBilal Alsharifi <bilal.alsharifi@gmail.com>2020-10-20 10:37:05 -0400
commitbf68c022d690a4bf4fabb64269be5ae74d0d66f2 (patch)
tree3dabb8d2fa28256b9188553cabfcd4b9cbed8697
parent71e3e940728d453dc3637295993f9e3815b605c2 (diff)
downloadsdl_android-bf68c022d690a4bf4fabb64269be5ae74d0d66f2.tar.gz
Check if params annotations match the specs
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCGenericTests.java30
1 files changed, 29 insertions, 1 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCGenericTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCGenericTests.java
index f886de5f6..e6c32c4d9 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCGenericTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/RPCGenericTests.java
@@ -14,6 +14,8 @@ import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -45,6 +47,7 @@ public class RPCGenericTests {
private Class<?> javaType;
private boolean isArray;
private boolean isMandatory;
+ private boolean isDeprecated;
private String setterName;
private String getterName1;
private String getterName2;
@@ -82,6 +85,11 @@ public class RPCGenericTests {
return this;
}
+ public Parameter setDeprecated(boolean deprecated) {
+ isDeprecated = deprecated;
+ return this;
+ }
+
public Parameter setSetterName(String setterName) {
this.setterName = setterName;
return this;
@@ -169,6 +177,7 @@ public class RPCGenericTests {
javaParamType = null;
skipParam = false;
boolean isMandatory = Boolean.valueOf(myParser.getAttributeValue(null, "mandatory"));
+ boolean isDeprecated = Boolean.valueOf(myParser.getAttributeValue(null, "deprecated"));
if (isMandatory || !includeMandatoryOnly) {
String paramName = myParser.getAttributeValue(null, "name");
String paramType = myParser.getAttributeValue(null, "type");
@@ -310,6 +319,7 @@ public class RPCGenericTests {
.setJavaType(javaParamType)
.setArray(isArray)
.setMandatory(isMandatory)
+ .setDeprecated(isDeprecated)
.setSkip(skipParam)
.setSetterName(setterMethodName)
.setGetterName1(getterMethodName1)
@@ -329,6 +339,15 @@ public class RPCGenericTests {
return rpcParamsMap;
}
+ private boolean isDeprecated (AnnotatedElement element) {
+ for (Annotation annotation : element.getDeclaredAnnotations()) {
+ if (annotation.annotationType().getSimpleName().equalsIgnoreCase("deprecated")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
// This method makes sure that for every RPC, there is a constructor that has all the mandatory params
// It also checks if there are RPC in the XML file that don't exist in the code
@Test
@@ -582,8 +601,9 @@ public class RPCGenericTests {
}
// Confirm that the setter is correct
+ Method setterMethod = null;
try {
- Method setterMethod = getMethod(aClass, parameter, parameter.setterName, false);
+ setterMethod = getMethod(aClass, parameter, parameter.setterName, false);
List<String> expectedReturnTypes = Arrays.asList(aClass.getName(), aClass.getSuperclass().getName());
String actualReturnType = setterMethod.getReturnType().getName();
if (!expectedReturnTypes.contains(actualReturnType)) {
@@ -594,6 +614,10 @@ public class RPCGenericTests {
String errMsg = rpcName + "." + parameter.setterName + "(" + parameter.type + ")" + " cannot be found. Make sure that the method exists. \n";
errors.add(errMsg);
}
+ if (setterMethod != null && isDeprecated(setterMethod) != parameter.isDeprecated) {
+ String errMsg = rpcName + "." + parameter.setterName + "()" + " deprecation status does not match RPC spec" + ". \n";
+ errors.add(errMsg);
+ }
// Confirm that the getter is correct
Method getterMethod = null;
@@ -608,6 +632,10 @@ public class RPCGenericTests {
errors.add(errMsg);
}
}
+ if (getterMethod != null && isDeprecated(getterMethod) != parameter.isDeprecated) {
+ String errMsg = rpcName + "." + parameter.getterName1 + "()" + " deprecation status does not match RPC spec" + ". \n";
+ errors.add(errMsg);
+ }
}
}