Move abstract-method-removal legacy example test.

Bug: b/167145686
Bug: b/227302144
Change-Id: I25bed35ef3c05d8cdca1b8c832373e3033527c5f
diff --git a/src/test/examples/abstractmethodremoval/keep-rules.txt b/src/test/examples/abstractmethodremoval/keep-rules.txt
deleted file mode 100644
index ec37858..0000000
--- a/src/test/examples/abstractmethodremoval/keep-rules.txt
+++ /dev/null
@@ -1 +0,0 @@
--keep public class abstractmethodremoval.AbstractMethodRemoval { public static void main(...); }
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
index 922f2d3..326b530 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
@@ -25,7 +25,6 @@
   @Parameters(name = "{0}_{1}_{2}_{3}_{5}_{6}")
   public static Collection<String[]> data() {
     String[] tests = {
-        "abstractmethodremoval.AbstractMethodRemoval",
         "arithmetic.Arithmetic",
         "arrayaccess.ArrayAccess",
         "barray.BArray",
diff --git a/src/test/examples/abstractmethodremoval/AbstractMethodRemoval.java b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/AbstractMethodRemoval.java
similarity index 73%
rename from src/test/examples/abstractmethodremoval/AbstractMethodRemoval.java
rename to src/test/java/com/android/tools/r8/examples/abstractmethodremoval/AbstractMethodRemoval.java
index 1da772d..3ecac10 100644
--- a/src/test/examples/abstractmethodremoval/AbstractMethodRemoval.java
+++ b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/AbstractMethodRemoval.java
@@ -1,12 +1,12 @@
 // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
 // 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 abstractmethodremoval;
+package com.android.tools.r8.examples.abstractmethodremoval;
 
-import abstractmethodremoval.a.PackageBase;
-import abstractmethodremoval.a.Public;
-import abstractmethodremoval.b.Impl1;
-import abstractmethodremoval.b.Impl2;
+import com.android.tools.r8.examples.abstractmethodremoval.a.PackageBase;
+import com.android.tools.r8.examples.abstractmethodremoval.a.Public;
+import com.android.tools.r8.examples.abstractmethodremoval.b.Impl1;
+import com.android.tools.r8.examples.abstractmethodremoval.b.Impl2;
 
 public class AbstractMethodRemoval {
 
diff --git a/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/AbstractMethodRemovalTestRunner.java b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/AbstractMethodRemovalTestRunner.java
new file mode 100644
index 0000000..20cda19
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/AbstractMethodRemovalTestRunner.java
@@ -0,0 +1,76 @@
+// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
+// 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.examples.abstractmethodremoval;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.ToolHelper.DexVm.Version;
+import com.android.tools.r8.examples.abstractmethodremoval.a.PackageBase;
+import com.android.tools.r8.examples.abstractmethodremoval.a.Public;
+import com.android.tools.r8.examples.abstractmethodremoval.b.Impl1;
+import com.android.tools.r8.examples.abstractmethodremoval.b.Impl2;
+import com.android.tools.r8.utils.StringUtils;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class AbstractMethodRemovalTestRunner extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  public AbstractMethodRemovalTestRunner(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  private Class<?> getMainClass() {
+    return AbstractMethodRemoval.class;
+  }
+
+  private List<Class<?>> getProgramClasses() {
+    return ImmutableList.of(
+        getMainClass(), Public.class, PackageBase.class, Impl1.class, Impl2.class);
+  }
+
+  private String getExpected() {
+    return StringUtils.lines(
+        "Impl1.foo(0)",
+        "Impl2.foo(0)",
+        "Impl2.foo(0)",
+        "Impl1.foo(0)",
+        "Impl2.foo(0)",
+        "Impl2.foo(0)");
+  }
+
+  @Test
+  public void testReference() throws Exception {
+    testForRuntime(parameters)
+        .addProgramClasses(getProgramClasses())
+        .run(parameters.getRuntime(), getMainClass())
+        .assertSuccessWithOutput(getExpected());
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    testForR8(parameters.getBackend())
+        .addProgramClasses(getProgramClasses())
+        .addKeepMainRule(getMainClass())
+        .setMinApi(parameters.getApiLevel())
+        .run(parameters.getRuntime(), getMainClass())
+        .applyIf(
+            // TODO(b/227302144): The program should not fail after R8.
+            parameters.isDexRuntime()
+                && parameters.asDexRuntime().getVersion().isNewerThanOrEqual(Version.V5_1_1),
+            r -> r.assertFailure(),
+            r -> r.assertSuccessWithOutput(getExpected()));
+  }
+}
diff --git a/src/test/examples/abstractmethodremoval/a/PackageBase.java b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/a/PackageBase.java
similarity index 84%
rename from src/test/examples/abstractmethodremoval/a/PackageBase.java
rename to src/test/java/com/android/tools/r8/examples/abstractmethodremoval/a/PackageBase.java
index 1075b57..6ca5d44 100644
--- a/src/test/examples/abstractmethodremoval/a/PackageBase.java
+++ b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/a/PackageBase.java
@@ -1,7 +1,7 @@
 // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
 // 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 abstractmethodremoval.a;
+package com.android.tools.r8.examples.abstractmethodremoval.a;
 
 public abstract class PackageBase {
   abstract void foo(int i);
diff --git a/src/test/examples/abstractmethodremoval/a/Public.java b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/a/Public.java
similarity index 83%
rename from src/test/examples/abstractmethodremoval/a/Public.java
rename to src/test/java/com/android/tools/r8/examples/abstractmethodremoval/a/Public.java
index 492ab87..db5cdd9 100644
--- a/src/test/examples/abstractmethodremoval/a/Public.java
+++ b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/a/Public.java
@@ -1,7 +1,7 @@
 // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
 // 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 abstractmethodremoval.a;
+package com.android.tools.r8.examples.abstractmethodremoval.a;
 
 public abstract class Public extends PackageBase {
   @Override
diff --git a/src/test/examples/abstractmethodremoval/b/Impl1.java b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/b/Impl1.java
similarity index 72%
rename from src/test/examples/abstractmethodremoval/b/Impl1.java
rename to src/test/java/com/android/tools/r8/examples/abstractmethodremoval/b/Impl1.java
index bfdf4d1..a1b5f7a 100644
--- a/src/test/examples/abstractmethodremoval/b/Impl1.java
+++ b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/b/Impl1.java
@@ -1,9 +1,9 @@
 // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
 // 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 abstractmethodremoval.b;
+package com.android.tools.r8.examples.abstractmethodremoval.b;
 
-import abstractmethodremoval.a.Public;
+import com.android.tools.r8.examples.abstractmethodremoval.a.Public;
 
 public class Impl1 extends Public {
   @Override
diff --git a/src/test/examples/abstractmethodremoval/b/Impl2.java b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/b/Impl2.java
similarity index 72%
rename from src/test/examples/abstractmethodremoval/b/Impl2.java
rename to src/test/java/com/android/tools/r8/examples/abstractmethodremoval/b/Impl2.java
index a92e2a1..b21c5da 100644
--- a/src/test/examples/abstractmethodremoval/b/Impl2.java
+++ b/src/test/java/com/android/tools/r8/examples/abstractmethodremoval/b/Impl2.java
@@ -1,9 +1,9 @@
 // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
 // 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 abstractmethodremoval.b;
+package com.android.tools.r8.examples.abstractmethodremoval.b;
 
-import abstractmethodremoval.a.Public;
+import com.android.tools.r8.examples.abstractmethodremoval.a.Public;
 
 public class Impl2 extends Public {
   @Override
diff --git a/src/test/java/com/android/tools/r8/shaking/examples/TreeShakingAbstractMethodRemovalTest.java b/src/test/java/com/android/tools/r8/shaking/examples/TreeShakingAbstractMethodRemovalTest.java
deleted file mode 100644
index b008254..0000000
--- a/src/test/java/com/android/tools/r8/shaking/examples/TreeShakingAbstractMethodRemovalTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
-// 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.shaking.examples;
-
-import com.android.tools.r8.TestParameters;
-import com.android.tools.r8.shaking.TreeShakingTest;
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-@RunWith(Parameterized.class)
-public class TreeShakingAbstractMethodRemovalTest extends TreeShakingTest {
-
-  @Parameters(name = "mode:{0}-{1} minify:{2}")
-  public static List<Object[]> data() {
-    return defaultTreeShakingParameters();
-  }
-
-  public TreeShakingAbstractMethodRemovalTest(
-      Frontend frontend, TestParameters parameters, MinifyMode minify) {
-    super(frontend, parameters, minify);
-  }
-
-  @Override
-  protected String getName() {
-    return "examples/abstractmethodremoval";
-  }
-
-  @Override
-  protected String getMainClass() {
-    return "abstractmethodremoval.AbstractMethodRemoval";
-  }
-
-  @Test
-  public void test() throws Exception {
-    runTest(
-        null,
-        null,
-        null,
-        ImmutableList.of("src/test/examples/abstractmethodremoval/keep-rules.txt"));
-  }
-}