Cleanup InvalidTypesTest expectations

Change-Id: I02bb67e7370c73d5776d18dfde0d2daf595d0052
diff --git a/src/test/java/com/android/tools/r8/shaking/InvalidTypesTest.java b/src/test/java/com/android/tools/r8/shaking/InvalidTypesTest.java
index d59f3fa..ecb398a 100644
--- a/src/test/java/com/android/tools/r8/shaking/InvalidTypesTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/InvalidTypesTest.java
@@ -16,7 +16,7 @@
 import com.android.tools.r8.R8TestRunResult;
 import com.android.tools.r8.TestParameters;
 import com.android.tools.r8.TestRunResult;
-import com.android.tools.r8.ToolHelper.DexVm.Version;
+import com.android.tools.r8.TestRuntime;
 import com.android.tools.r8.errors.Unreachable;
 import com.android.tools.r8.jasmin.JasminBuilder;
 import com.android.tools.r8.jasmin.JasminBuilder.ClassBuilder;
@@ -45,25 +45,109 @@
   }
 
   private enum Mode {
-    NO_INVOKE,
-    INVOKE_UNVERIFIABLE_METHOD,
-    INVOKE_VERIFIABLE_METHOD_ON_UNVERIFIABLE_CLASS;
+    NO_INVOKE {
 
-    public String instruction() {
-      switch (this) {
-        case NO_INVOKE:
-          return "";
-
-        case INVOKE_UNVERIFIABLE_METHOD:
-          return "invokestatic UnverifiableClass/unverifiableMethod()V";
-
-        case INVOKE_VERIFIABLE_METHOD_ON_UNVERIFIABLE_CLASS:
-          return "invokestatic UnverifiableClass/verifiableMethod()V";
-
-        default:
-          throw new Unreachable();
+      @Override
+      public String getExpectedOutput(
+          Compiler compiler, TestRuntime runtime, boolean useInterface) {
+        return StringUtils.joinLines("Hello!", "Goodbye!", "");
       }
-    }
+
+      @Override
+      public String instruction() {
+        return "";
+      }
+    },
+    INVOKE_UNVERIFIABLE_METHOD {
+
+      @Override
+      public String getExpectedOutput(
+          Compiler compiler, TestRuntime runtime, boolean useInterface) {
+        if (!useInterface) {
+          return StringUtils.joinLines("Hello!", "");
+        }
+
+        switch (compiler) {
+          case D8:
+          case DX:
+            switch (runtime.asDex().getVm().getVersion()) {
+              case V4_0_4:
+              case V4_4_4:
+              case V10_0_0:
+                return StringUtils.joinLines("Hello!", "Goodbye!", "");
+
+              case V7_0_0:
+                return StringUtils.joinLines(
+                    "Hello!",
+                    "Unexpected outcome of checkcast",
+                    "Unexpected outcome of instanceof",
+                    "Goodbye!",
+                    "");
+
+              default:
+                // Fallthrough.
+            }
+
+          case R8:
+          case PROGUARD:
+            return StringUtils.joinLines(
+                "Hello!", "Unexpected outcome of checkcast", "Goodbye!", "");
+
+          case R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES:
+            return StringUtils.joinLines(
+                "Hello!",
+                "Unexpected outcome of getstatic",
+                "Unexpected outcome of checkcast",
+                "Goodbye!",
+                "");
+
+          case JAVAC:
+            return StringUtils.joinLines("Hello!", "Goodbye!", "");
+
+          default:
+            throw new Unreachable();
+        }
+      }
+
+      @Override
+      public String instruction() {
+          return "invokestatic UnverifiableClass/unverifiableMethod()V";
+      }
+    },
+    INVOKE_VERIFIABLE_METHOD_ON_UNVERIFIABLE_CLASS {
+
+      @Override
+      public String getExpectedOutput(
+          Compiler compiler, TestRuntime runtime, boolean useInterface) {
+        if (useInterface) {
+          return StringUtils.joinLines("Hello!", "In verifiable method!", "Goodbye!", "");
+        }
+
+        switch (compiler) {
+          case R8:
+          case R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES:
+          case PROGUARD:
+            // The unverifiable method has been removed as a result of tree shaking, so the code
+            // does not fail with a verification error when trying to load class UnverifiableClass.
+            return StringUtils.joinLines("Hello!", "In verifiable method!", "Goodbye!", "");
+
+          default:
+            // The code fails with a verification error because the verifiableMethod() is being
+            // called on UnverifiableClass, which does not verify due to unverifiableMethod().
+            return StringUtils.joinLines("Hello!", "");
+        }
+      }
+
+      @Override
+      public String instruction() {
+        return "invokestatic UnverifiableClass/verifiableMethod()V";
+      }
+    };
+
+    public abstract String getExpectedOutput(
+        Compiler compiler, TestRuntime runtime, boolean useInterface);
+
+    public abstract String instruction();
   }
 
   private final TestParameters parameters;
@@ -304,59 +388,7 @@
   }
 
   private String getExpectedOutput(Compiler compiler) {
-    if (mode == Mode.NO_INVOKE) {
-      return StringUtils.joinLines("Hello!", "Goodbye!", "");
-    }
-    if (mode == Mode.INVOKE_VERIFIABLE_METHOD_ON_UNVERIFIABLE_CLASS) {
-      if (useInterface) {
-        return StringUtils.joinLines("Hello!", "In verifiable method!", "Goodbye!", "");
-      } else {
-        if (compiler == Compiler.R8
-            || compiler == Compiler.R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES
-            || compiler == Compiler.PROGUARD) {
-          // The unverifiable method has been removed as a result of tree shaking, so the code does
-          // not fail with a verification error when trying to load class `UnverifiableClass`.
-          return StringUtils.joinLines("Hello!", "In verifiable method!", "Goodbye!", "");
-        } else {
-          // The code fails with a verification error because the verifiableMethod() is being called
-          // on `UnverifiableClass`, which does not verify due to unverifiableMethod().
-          return StringUtils.joinLines("Hello!", "");
-        }
-      }
-    }
-    assert mode == Mode.INVOKE_UNVERIFIABLE_METHOD;
-    if (useInterface) {
-      if (compiler == Compiler.R8_ENABLE_UNININSTANTATED_TYPE_OPTIMIZATION_FOR_INTERFACES) {
-        return StringUtils.joinLines(
-            "Hello!",
-            "Unexpected outcome of getstatic",
-            "Unexpected outcome of checkcast",
-            "Goodbye!",
-            "");
-      } else if (compiler == Compiler.R8 || compiler == Compiler.PROGUARD) {
-        return StringUtils.joinLines("Hello!", "Unexpected outcome of checkcast", "Goodbye!", "");
-      } else if (compiler == Compiler.DX || compiler == Compiler.D8) {
-        if (parameters.getRuntime().asDex().getVm().getVersion() == Version.V4_0_4
-            || parameters.getRuntime().asDex().getVm().getVersion() == Version.V4_4_4
-            || parameters.getRuntime().asDex().getVm().getVersion() == Version.V10_0_0) {
-          return StringUtils.joinLines("Hello!", "Goodbye!", "");
-        } else if (parameters.getRuntime().asDex().getVm().getVersion() == Version.V7_0_0) {
-          return StringUtils.joinLines(
-              "Hello!",
-              "Unexpected outcome of checkcast",
-              "Unexpected outcome of instanceof",
-              "Goodbye!",
-              "");
-        } else {
-          return StringUtils.joinLines("Hello!", "Unexpected outcome of checkcast", "Goodbye!", "");
-        }
-      } else {
-        assert compiler == Compiler.JAVAC;
-        return StringUtils.joinLines("Hello!", "Goodbye!", "");
-      }
-    } else {
-      return StringUtils.joinLines("Hello!", "");
-    }
+    return mode.getExpectedOutput(compiler, parameters.getRuntime(), useInterface);
   }
 
   private Matcher<String> getMatcherForExpectedError() {