Add test for keeping base interface methods when keeping sub methods

Bug: 143590191
Change-Id: I35e032f083b4627fa1392be4c29e8ea5aae9d766
diff --git a/src/test/java/com/android/tools/r8/shaking/methods/interfaces/AbstractInterfaceMethodsTest.java b/src/test/java/com/android/tools/r8/shaking/methods/interfaces/AbstractInterfaceMethodsTest.java
new file mode 100644
index 0000000..442fda4
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/shaking/methods/interfaces/AbstractInterfaceMethodsTest.java
@@ -0,0 +1,80 @@
+// Copyright (c) 2019, 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.methods.interfaces;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assume.assumeTrue;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * This tests is showing the issue filed in b/143590191. The expectations for the test should
+ * reflect the decisions to keep the interface method or not in the super interface.
+ */
+@RunWith(Parameterized.class)
+public class AbstractInterfaceMethodsTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  public AbstractInterfaceMethodsTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testSingleInheritanceProguard()
+      throws CompilationFailedException, IOException, ExecutionException {
+    assumeTrue(parameters.isCfRuntime());
+    testForProguard()
+        .addProgramClasses(I.class, J.class)
+        .setMinApi(parameters.getApiLevel())
+        .addKeepMethodRules(J.class, "void foo()")
+        .addKeepRules("-dontwarn")
+        .compile()
+        .inspect(AbstractInterfaceMethodsTest::inspectBaseInterfaceRemove);
+  }
+
+  @Test
+  public void testSingleInheritanceR8()
+      throws CompilationFailedException, IOException, ExecutionException {
+    // TODO(b/143590191): Fix expectation when resolved.
+    testForR8(parameters.getBackend())
+        .addProgramClasses(I.class, J.class)
+        .setMinApi(parameters.getApiLevel())
+        .addKeepMethodRules(J.class, "void foo()")
+        .compile()
+        .inspect(AbstractInterfaceMethodsTest::inspectBaseInterfaceRemove);
+  }
+
+  private static void inspectBaseInterfaceRemove(CodeInspector inspector) {
+    ClassSubject clazz = inspector.clazz(J.class);
+    assertThat(clazz, isPresent());
+    assertThat(clazz.uniqueMethodWithName("foo"), not(isPresent()));
+    assertThat(inspector.clazz(I.class), not(isPresent()));
+  }
+
+  public interface I {
+    void foo();
+  }
+
+  public interface J extends I {}
+}
diff --git a/src/test/java/com/android/tools/r8/shaking/methods/interfaces/AbstractMethodsTest.java b/src/test/java/com/android/tools/r8/shaking/methods/interfaces/DefaultInterfaceMethodsTest.java
similarity index 93%
rename from src/test/java/com/android/tools/r8/shaking/methods/interfaces/AbstractMethodsTest.java
rename to src/test/java/com/android/tools/r8/shaking/methods/interfaces/DefaultInterfaceMethodsTest.java
index 808ae73..c6feb05 100644
--- a/src/test/java/com/android/tools/r8/shaking/methods/interfaces/AbstractMethodsTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/methods/interfaces/DefaultInterfaceMethodsTest.java
@@ -28,7 +28,7 @@
  * reflect the decisions to keep the interface method or not in the super interface.
  */
 @RunWith(Parameterized.class)
-public class AbstractMethodsTest extends TestBase {
+public class DefaultInterfaceMethodsTest extends TestBase {
 
   private final TestParameters parameters;
 
@@ -37,7 +37,7 @@
     return getTestParameters().withAllRuntimesAndApiLevels().build();
   }
 
-  public AbstractMethodsTest(TestParameters parameters) {
+  public DefaultInterfaceMethodsTest(TestParameters parameters) {
     this.parameters = parameters;
   }
 
@@ -51,7 +51,7 @@
         .addKeepMethodRules(J.class, "void foo()")
         .addKeepRules("-dontwarn")
         .compile()
-        .inspect(AbstractMethodsTest::inspectBaseInterfaceRemove);
+        .inspect(DefaultInterfaceMethodsTest::inspectBaseInterfaceRemove);
   }
 
   @Test
@@ -62,7 +62,7 @@
         .setMinApi(parameters.getApiLevel())
         .addKeepMethodRules(J.class, "void foo()")
         .compile()
-        .inspect(AbstractMethodsTest::inspectBaseInterfaceRemove);
+        .inspect(DefaultInterfaceMethodsTest::inspectBaseInterfaceRemove);
   }
 
   private static void inspectBaseInterfaceRemove(CodeInspector inspector) {