Clean up reflection tests.

Change-Id: If90649345ed3f593bb6056f8840dff0bfde68064
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/canonicalization/DexItemBasedConstStringCanonicalizationTest.java b/src/test/java/com/android/tools/r8/ir/optimize/canonicalization/DexItemBasedConstStringCanonicalizationTest.java
index 895ff45..5f8e918 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/canonicalization/DexItemBasedConstStringCanonicalizationTest.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/canonicalization/DexItemBasedConstStringCanonicalizationTest.java
@@ -90,7 +90,7 @@
         testForD8()
             .debug()
             .addProgramClasses(MAIN, CanonicalizationTestClass.class)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -100,7 +100,7 @@
         testForD8()
             .release()
             .addProgramClasses(MAIN, CanonicalizationTestClass.class)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -114,7 +114,7 @@
             .addProgramClasses(MAIN, CanonicalizationTestClass.class)
             .addKeepMainRule(MAIN)
             .minification(enableMinification)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(enableMinification ? RENAMED_OUTPUT : JAVA_OUTPUT);
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/reflection/ForNameTest.java b/src/test/java/com/android/tools/r8/ir/optimize/reflection/ForNameTest.java
index 14cd360..dbcb237 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/reflection/ForNameTest.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/reflection/ForNameTest.java
@@ -80,7 +80,7 @@
 
   @Parameterized.Parameters(name = "{0}")
   public static TestParametersCollection data() {
-    return getTestParameters().withAllRuntimes().build();
+    return getTestParameters().withAllRuntimes().withAllApiLevels().build();
   }
 
   private final TestParameters parameters;
@@ -119,7 +119,7 @@
         testForD8()
             .debug()
             .addProgramClassesAndInnerClasses(MAIN)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
     test(result, 4, 0);
@@ -129,7 +129,7 @@
         testForD8()
             .release()
             .addProgramClassesAndInnerClasses(MAIN)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
     test(result, 4, 0);
@@ -146,7 +146,7 @@
             .addKeepAllClassesRule()
             .addKeepAttributes("EnclosingMethod", "InnerClasses")
             .noMinification()
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .run(parameters.getRuntime(), MAIN);
     test(result, 4, 0);
 
@@ -158,7 +158,7 @@
             .addKeepAllClassesRule()
             .addKeepAttributes("EnclosingMethod", "InnerClasses")
             .noMinification()
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
     test(result, 2, 2);
@@ -170,7 +170,7 @@
             .addKeepMainRule(MAIN)
             .addKeepAllClassesRuleWithAllowObfuscation()
             .addKeepAttributes("EnclosingMethod", "InnerClasses")
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             // We are not checking output because it can't be matched due to minification. Just run.
             .run(parameters.getRuntime(), MAIN);
     test(result, 2, 2);
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetClassTest.java b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetClassTest.java
index aa8e1d5..cf4a324 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetClassTest.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetClassTest.java
@@ -122,7 +122,7 @@
 
   @Parameterized.Parameters(name = "{0}")
   public static TestParametersCollection data() {
-    return getTestParameters().withAllRuntimes().build();
+    return getTestParameters().withAllRuntimes().withAllApiLevels().build();
   }
 
   private final TestParameters parameters;
@@ -183,7 +183,7 @@
             .debug()
             .addProgramClassesAndInnerClasses(MAIN)
             .addOptionsModification(this::configure)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
     test(result, false, false);
@@ -194,7 +194,7 @@
             .release()
             .addProgramClassesAndInnerClasses(MAIN)
             .addOptionsModification(this::configure)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
     test(result, false, true);
@@ -211,7 +211,7 @@
             .addKeepMainRule(MAIN)
             .noMinification()
             .addOptionsModification(this::configure)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .run(parameters.getRuntime(), MAIN);
     test(result, true, false);
 
@@ -223,7 +223,7 @@
             .addKeepMainRule(MAIN)
             .noMinification()
             .addOptionsModification(this::configure)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
     test(result, true, true);
@@ -235,7 +235,7 @@
             .enableInliningAnnotations()
             .addKeepMainRule(MAIN)
             .addOptionsModification(this::configure)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             // We are not checking output because it can't be matched due to minification. Just run.
             .run(parameters.getRuntime(), MAIN);
     test(result, true, true);
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameInClassInitializerTest.java b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameInClassInitializerTest.java
index 5e11c17..d8d0c47 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameInClassInitializerTest.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameInClassInitializerTest.java
@@ -69,7 +69,7 @@
         .addKeepMainRule(MAIN)
         .addKeepRules("-keep class **.GetNameClinit*")
         .minification(enableMinification)
-        .setMinApi(parameters.getRuntime())
+        .setMinApi(parameters.getApiLevel())
         .addOptionsModification(this::configure)
         .run(parameters.getRuntime(), MAIN)
         .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -85,7 +85,7 @@
             .addKeepMainRule(MAIN)
             .addKeepRules("-keep,allowobfuscation class **.GetNameClinit*")
             .minification(enableMinification)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .compile();
     result
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameTest.java b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameTest.java
index 50b19d2..6d9c2d7 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameTest.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameTest.java
@@ -243,7 +243,7 @@
         testForD8()
             .debug()
             .addProgramFiles(classPaths)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -253,7 +253,7 @@
         testForD8()
             .release()
             .addProgramFiles(classPaths)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -272,7 +272,7 @@
             .addKeepRules("-keepattributes InnerClasses,EnclosingMethod")
             .addKeepRules("-printmapping " + createNewMappingPath().toAbsolutePath().toString())
             .minification(enableMinification)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -290,7 +290,7 @@
             .addKeepRules("-keepattributes InnerClasses,EnclosingMethod")
             .addKeepRules("-printmapping " + createNewMappingPath().toAbsolutePath().toString())
             .minification(enableMinification)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN);
     if (enableMinification) {
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameTestBase.java b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameTestBase.java
index 9c0766c..dde75c4 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameTestBase.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetNameTestBase.java
@@ -29,7 +29,7 @@
   @Parameterized.Parameters(name = "{0} minification: {1}")
   public static Collection<Object[]> data() {
     return buildParameters(
-        getTestParameters().withAllRuntimes().build(), BooleanUtils.values());
+        getTestParameters().withAllRuntimes().withAllApiLevels().build(), BooleanUtils.values());
   }
 
   public GetNameTestBase(TestParameters parameters, boolean enableMinification) {
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetSimpleNameTest.java b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetSimpleNameTest.java
index ee1edd0..a16e8d5 100644
--- a/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetSimpleNameTest.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/reflection/GetSimpleNameTest.java
@@ -203,7 +203,7 @@
         testForD8()
             .debug()
             .addProgramFiles(classPaths)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -213,7 +213,7 @@
         testForD8()
             .release()
             .addProgramFiles(classPaths)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -233,7 +233,7 @@
             .addKeepAttributes("InnerClasses", "EnclosingMethod")
             .addKeepRules("-printmapping " + createNewMappingPath().toAbsolutePath().toString())
             .minification(enableMinification)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN)
             .assertSuccessWithOutput(JAVA_OUTPUT);
@@ -256,7 +256,7 @@
             .addKeepAttributes("InnerClasses", "EnclosingMethod")
             .addKeepRules("-printmapping " + createNewMappingPath().toAbsolutePath().toString())
             .minification(enableMinification)
-            .setMinApi(parameters.getRuntime())
+            .setMinApi(parameters.getApiLevel())
             .addOptionsModification(this::configure)
             .run(parameters.getRuntime(), MAIN);
     if (enableMinification) {
diff --git a/src/test/java/com/android/tools/r8/reflection/TestClassForNameWhenSplit.java b/src/test/java/com/android/tools/r8/ir/optimize/reflection/TestClassForNameWhenSplit.java
similarity index 71%
rename from src/test/java/com/android/tools/r8/reflection/TestClassForNameWhenSplit.java
rename to src/test/java/com/android/tools/r8/ir/optimize/reflection/TestClassForNameWhenSplit.java
index 50305fd..66ae08d 100644
--- a/src/test/java/com/android/tools/r8/reflection/TestClassForNameWhenSplit.java
+++ b/src/test/java/com/android/tools/r8/ir/optimize/reflection/TestClassForNameWhenSplit.java
@@ -2,16 +2,18 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-package com.android.tools.r8.reflection;
+package com.android.tools.r8.ir.optimize.reflection;
 
-import static org.junit.Assert.assertTrue;
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
 
-import com.android.tools.r8.TestBase;
+import com.android.tools.r8.NeverInline;
 import com.android.tools.r8.TestParameters;
 import com.android.tools.r8.TestParametersCollection;
 import com.android.tools.r8.dexsplitter.SplitterTestBase;
-import com.android.tools.r8.references.Reference;
-import com.google.common.collect.ImmutableSet;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import com.android.tools.r8.utils.codeinspector.MethodSubject;
 import java.nio.file.Path;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -19,7 +21,7 @@
 import org.junit.runners.Parameterized.Parameters;
 
 @RunWith(Parameterized.class)
-public class TestClassForNameWhenSplit extends TestBase {
+public class TestClassForNameWhenSplit extends ReflectionOptimizerTestBase {
 
   private final TestParameters parameters;
   private final String EXPECTED = "caught";
@@ -42,7 +44,7 @@
   }
 
   @Test
-  public void testClassForNameIsKeept() throws Exception {
+  public void testClassForNameIsKept() throws Exception {
     Path featurePath = temp.newFile("feature1.zip").toPath();
     testForR8(parameters.getBackend())
         .addProgramClasses(Main.class)
@@ -53,8 +55,15 @@
                     builder, featurePath, temp, Foobar.class))
         .addKeepMainRule(Main.class)
         .addKeepClassRules(Foobar.class)
+        .enableInliningAnnotations()
         .compile()
-        .disassemble()
+        .inspect(codeInspector -> {
+          ClassSubject mainClass = codeInspector.clazz(Main.class);
+          MethodSubject foo = mainClass.uniqueMethodWithName("foo");
+          assertThat(foo, isPresent());
+          // Make sure Class#forName is indeed kept.
+          assertEquals(1, countForName(foo));
+        })
         .run(parameters.getRuntime(), Main.class)
         .assertSuccessWithOutputLines(EXPECTED);
   }
@@ -73,16 +82,18 @@
       }
     }
 
+    @NeverInline
     private static void foo()
         throws ClassNotFoundException, IllegalAccessException, InstantiationException {
       try {
-        // Ensure cl init has been assumed triggered
+        // Ensure clinit has been assumed triggered
         new Foobar();
       } catch (NoClassDefFoundError e) { }
       // It is not valid to replace this with just classForName, even if we see that there is only
       // a trivial clinit or the fact that we have already triggered it above.
       Class<?> foobar =
-          Class.forName("com.android.tools.r8.reflection.TestClassForNameWhenSplit$Foobar");
+          Class.forName(
+              "com.android.tools.r8.ir.optimize.reflection.TestClassForNameWhenSplit$Foobar");
       foobar.newInstance();
     }
   }