Version.LABEL API test.
Bug: 157980664
Change-Id: I0b1e72d2962118953c2d96a1545ad9d31bce50de
diff --git a/src/test/apiUsageSample/com/android/tools/apiusagesample/R8ApiUsageSample.java b/src/test/apiUsageSample/com/android/tools/apiusagesample/R8ApiUsageSample.java
index 2061722..febd5e6 100644
--- a/src/test/apiUsageSample/com/android/tools/apiusagesample/R8ApiUsageSample.java
+++ b/src/test/apiUsageSample/com/android/tools/apiusagesample/R8ApiUsageSample.java
@@ -25,6 +25,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -559,6 +561,26 @@
}
private static void checkVersionApi() {
+ String labelValue;
+ int labelAccess;
+ try {
+ Field field = Version.class.getDeclaredField("LABEL");
+ labelAccess = field.getModifiers();
+ labelValue = (String) field.get(Version.class);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ if (!Modifier.isPublic(labelAccess)
+ || !Modifier.isStatic(labelAccess)
+ || !Modifier.isFinal(labelAccess)) {
+ throw new RuntimeException("Expected public static final LABEL");
+ }
+ if (labelValue.isEmpty()) {
+ throw new RuntimeException("Expected LABEL constant");
+ }
+ if (Version.LABEL.isEmpty()) {
+ throw new RuntimeException("Expected LABEL constant");
+ }
if (Version.getVersionString() == null) {
throw new RuntimeException("Expected getVersionString API");
}