Update RewriteSwitchMapsTest after moving switchmaps example.

Bug: b/167145686
Change-Id: Id776e971ed97c253b85aae330e364fb88443f098
diff --git a/src/test/java/com/android/tools/r8/examples/switchmaps/SwitchMapsTestRunner.java b/src/test/java/com/android/tools/r8/examples/switchmaps/SwitchMapsTestRunner.java
index 1fb0770..2936fd8 100644
--- a/src/test/java/com/android/tools/r8/examples/switchmaps/SwitchMapsTestRunner.java
+++ b/src/test/java/com/android/tools/r8/examples/switchmaps/SwitchMapsTestRunner.java
@@ -17,6 +17,34 @@
 @RunWith(Parameterized.class)
 public class SwitchMapsTestRunner extends ExamplesTestBase {
 
+  public static final String EXPECTED =
+      StringUtils.lines(
+          "other",
+          "1, 3 or 4",
+          "2 or 5",
+          "other",
+          "2 or 5",
+          "3 or 5",
+          "1, 3 or 4",
+          "2 or 5",
+          "other",
+          "1, 3 or 4",
+          "2 or 5",
+          "3 or 5",
+          "2 or 5",
+          "other",
+          "6",
+          "7",
+          "7",
+          "rar",
+          "colorful",
+          "blew",
+          "colorful",
+          "soylent",
+          "sooo green",
+          "fifty",
+          "not really");
+
   @Parameterized.Parameters(name = "{0}")
   public static TestParametersCollection data() {
     return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
@@ -42,32 +70,7 @@
 
   @Override
   public String getExpected() {
-    return StringUtils.lines(
-        "other",
-        "1, 3 or 4",
-        "2 or 5",
-        "other",
-        "2 or 5",
-        "3 or 5",
-        "1, 3 or 4",
-        "2 or 5",
-        "other",
-        "1, 3 or 4",
-        "2 or 5",
-        "3 or 5",
-        "2 or 5",
-        "other",
-        "6",
-        "7",
-        "7",
-        "rar",
-        "colorful",
-        "blew",
-        "colorful",
-        "soylent",
-        "sooo green",
-        "fifty",
-        "not really");
+    return EXPECTED;
   }
 
   @Test
diff --git a/src/test/java/com/android/tools/r8/rewrite/switchmaps/RewriteSwitchMapsTest.java b/src/test/java/com/android/tools/r8/rewrite/switchmaps/RewriteSwitchMapsTest.java
index 98d8604..ab4a619 100644
--- a/src/test/java/com/android/tools/r8/rewrite/switchmaps/RewriteSwitchMapsTest.java
+++ b/src/test/java/com/android/tools/r8/rewrite/switchmaps/RewriteSwitchMapsTest.java
@@ -4,16 +4,17 @@
 package com.android.tools.r8.rewrite.switchmaps;
 
 import static com.android.tools.r8.utils.codeinspector.Matchers.isAbsent;
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
 import static org.hamcrest.MatcherAssert.assertThat;
 
 import com.android.tools.r8.TestBase;
 import com.android.tools.r8.TestParameters;
 import com.android.tools.r8.TestParametersCollection;
-import com.android.tools.r8.ToolHelper;
+import com.android.tools.r8.examples.switchmaps.Colors;
+import com.android.tools.r8.examples.switchmaps.Days;
+import com.android.tools.r8.examples.switchmaps.SwitchMapsTestRunner;
+import com.android.tools.r8.examples.switchmaps.Switches;
 import com.android.tools.r8.utils.AndroidApiLevel;
-import com.google.common.collect.ImmutableList;
-import java.nio.file.Paths;
-import java.util.List;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -31,20 +32,29 @@
     return getTestParameters().withDefaultRuntimes().withApiLevel(AndroidApiLevel.B).build();
   }
 
-  private static final String JAR_FILE = "switchmaps.jar";
-  private static final String SWITCHMAP_CLASS_NAME = "switchmaps.Switches$1";
-  private static final List<String> PG_CONFIG = ImmutableList.of(
-      "-keep class switchmaps.Switches { public static void main(...); }",
-      "-dontobfuscate",
-      "-keepattributes *");
+  private static final String SWITCHMAP_CLASS_NAME = typeName(Switches.class) + "$1";
+
+  @Test
+  public void testReference() throws Exception {
+    testForRuntime(parameters)
+        .addProgramClassesAndInnerClasses(Switches.class)
+        .addProgramClasses(Colors.class, Days.class)
+        .run(parameters.getRuntime(), Switches.class)
+        .assertSuccessWithOutput(SwitchMapsTestRunner.EXPECTED)
+        .inspect(inspector -> assertThat(inspector.clazz(SWITCHMAP_CLASS_NAME), isPresent()));
+  }
 
   @Test
   public void checkSwitchMapsRemoved() throws Exception {
     testForR8(parameters.getBackend())
-        .addProgramFiles(Paths.get(ToolHelper.EXAMPLES_BUILD_DIR).resolve(JAR_FILE))
-        .addKeepRules(PG_CONFIG)
+        .addProgramClassesAndInnerClasses(Switches.class)
+        .addProgramClasses(Colors.class, Days.class)
+        .addKeepMainRule(Switches.class)
+        .addDontObfuscate()
+        .addKeepAllAttributes()
         .setMinApi(parameters)
-        .compile()
+        .run(parameters.getRuntime(), Switches.class)
+        .assertSuccessWithOutput(SwitchMapsTestRunner.EXPECTED)
         .inspect(inspector -> assertThat(inspector.clazz(SWITCHMAP_CLASS_NAME), isAbsent()));
   }
 }