Use gradle for running some java 17 tests

Introduces the build steps and changes 3 backport tests to use this directly.

Still use the old setup for the remaining examples 17 tests

Change-Id: I6d940df13e6f5e588fbbb69193191579238ed3b7
diff --git a/src/test/examplesJava17/backport/MathBackportJava17Main.java b/src/test/examplesJava17/backport/MathBackportJava17Main.java
deleted file mode 100644
index 7eeed95..0000000
--- a/src/test/examplesJava17/backport/MathBackportJava17Main.java
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2023, 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 backport;
-
-public class MathBackportJava17Main {
-
-  public static void main(String[] args) {
-    // The methods are actually from Java 15, but we can test them from Java 17.
-    testAbsExactInteger();
-    testAbsExactLong();
-  }
-
-  private static void testAbsExactInteger() {
-    assertEquals(42, Math.absExact(42));
-    assertEquals(42, Math.absExact(-42));
-    assertEquals(Integer.MAX_VALUE, Math.absExact(Integer.MAX_VALUE));
-    try {
-      throw new AssertionError(Math.absExact(Integer.MIN_VALUE));
-    } catch (ArithmeticException expected) {
-
-    }
-  }
-
-  private static void testAbsExactLong() {
-    assertEquals(42L, Math.absExact(42L));
-    assertEquals(42L, Math.absExact(-42L));
-    assertEquals(Long.MAX_VALUE, Math.absExact(Long.MAX_VALUE));
-    try {
-      throw new AssertionError(Math.absExact(Long.MIN_VALUE));
-    } catch (ArithmeticException expected) {
-
-    }
-  }
-
-  private static void assertEquals(int expected, int actual) {
-    if (expected != actual) {
-      throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
-    }
-  }
-
-  private static void assertEquals(long expected, long actual) {
-    if (expected != actual) {
-      throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
-    }
-  }
-}
diff --git a/src/test/examplesJava17/backport/MathBackportJava17Test.java b/src/test/examplesJava17/backport/MathBackportJava17Test.java
new file mode 100644
index 0000000..bc6e800
--- /dev/null
+++ b/src/test/examplesJava17/backport/MathBackportJava17Test.java
@@ -0,0 +1,81 @@
+// Copyright (c) 2024, 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 backport;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.TestRuntime.CfVm;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class MathBackportJava17Test extends TestBase {
+
+  @Parameter(0)
+  public TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection parameters() {
+    return getTestParameters()
+        .withDexRuntimes()
+        .withCfRuntimesStartingFromIncluding(CfVm.JDK17)
+        .withAllApiLevelsAlsoForCf()
+        .build();
+  }
+
+  @Test
+  public void test() throws Exception {
+    testForDesugaring(parameters)
+        .addInnerClassesAndStrippedOuter(getClass())
+        .run(parameters.getRuntime(), TestClass.class)
+        .assertSuccess();
+  }
+
+  public static class TestClass {
+    public static void main(String[] args) {
+      // The methods are actually from Java 15, but we can test them from Java 17.
+      testAbsExactInteger();
+      testAbsExactLong();
+    }
+
+    private static void testAbsExactInteger() {
+      assertEquals(42, Math.absExact(42));
+      assertEquals(42, Math.absExact(-42));
+      assertEquals(Integer.MAX_VALUE, Math.absExact(Integer.MAX_VALUE));
+      try {
+        throw new AssertionError(Math.absExact(Integer.MIN_VALUE));
+      } catch (ArithmeticException expected) {
+
+      }
+    }
+
+    private static void testAbsExactLong() {
+      assertEquals(42L, Math.absExact(42L));
+      assertEquals(42L, Math.absExact(-42L));
+      assertEquals(Long.MAX_VALUE, Math.absExact(Long.MAX_VALUE));
+      try {
+        throw new AssertionError(Math.absExact(Long.MIN_VALUE));
+      } catch (ArithmeticException expected) {
+
+      }
+    }
+
+    private static void assertEquals(int expected, int actual) {
+      if (expected != actual) {
+        throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
+      }
+    }
+
+    private static void assertEquals(long expected, long actual) {
+      if (expected != actual) {
+        throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
+      }
+    }
+  }
+}
diff --git a/src/test/examplesJava17/backport/ObjectsBackportJava17Main.java b/src/test/examplesJava17/backport/ObjectsBackportJava17Main.java
deleted file mode 100644
index b950c17..0000000
--- a/src/test/examplesJava17/backport/ObjectsBackportJava17Main.java
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright (c) 2023, 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 backport;
-
-import java.util.Objects;
-
-public class ObjectsBackportJava17Main {
-
-  public static void main(String[] args) {
-    // The methods are actually from Java 16, but we can test them from Java 17.
-    testCheckIndex();
-    testCheckFromToIndex();
-    testCheckFromIndexSize();
-  }
-
-  private static void testCheckIndex() {
-    for (long i = 0L; i < 10L; i++) {
-      assertEquals(i, Objects.checkIndex(i, 10L));
-    }
-
-    try {
-      throw new AssertionError(Objects.checkIndex(-1L, 10L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkIndex(10L, 0L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkIndex(0L, 0L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-  }
-
-  private static void testCheckFromToIndex() {
-    for (long i = 0L; i <= 10L; i++) {
-      for (long j = i; j <= 10L; j++) {
-        assertEquals(i, Objects.checkFromToIndex(i, j, 10L));
-      }
-    }
-    assertEquals(0L, Objects.checkFromToIndex(0L, 0L, 0L));
-
-    try {
-      throw new AssertionError(Objects.checkFromToIndex(4L, 2L, 10L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromToIndex(-1L, 5L, 10L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromToIndex(0L, -1L, 10L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromToIndex(11L, 11L, 10L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromToIndex(0L, 1L, 0L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromToIndex(1L, 1L, 0L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-  }
-
-  private static void testCheckFromIndexSize() {
-    for (long i = 0L; i <= 10L; i++) {
-      for (long j = 10L - i; j >= 0L; j--) {
-        assertEquals(i, Objects.checkFromIndexSize(i, j, 10L));
-      }
-    }
-    assertEquals(0, Objects.checkFromIndexSize(0L, 0L, 0L));
-
-    try {
-      throw new AssertionError(Objects.checkFromIndexSize(8L, 4L, 10L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromIndexSize(-1L, 5L, 10L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromIndexSize(11L, 0L, 10L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromIndexSize(0L, 1L, 0L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromIndexSize(1L, 1L, 0L));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-
-    // Check for cases where overflow might occur producing incorrect results.
-    try {
-      throw new AssertionError(Objects.checkFromIndexSize(Long.MAX_VALUE, 1L, Long.MAX_VALUE));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-    try {
-      throw new AssertionError(Objects.checkFromIndexSize(0L, 1L, Long.MIN_VALUE));
-    } catch (IndexOutOfBoundsException expected) {
-    }
-  }
-
-  private static void assertEquals(long expected, long actual) {
-    if (expected != actual) {
-      throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
-    }
-  }
-}
diff --git a/src/test/examplesJava17/backport/ObjectsBackportJava17Test.java b/src/test/examplesJava17/backport/ObjectsBackportJava17Test.java
new file mode 100644
index 0000000..32ba077
--- /dev/null
+++ b/src/test/examplesJava17/backport/ObjectsBackportJava17Test.java
@@ -0,0 +1,148 @@
+// Copyright (c) 2024, 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 backport;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestRuntime.CfVm;
+import java.util.Objects;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class ObjectsBackportJava17Test extends TestBase {
+
+  @Parameter(0)
+  public TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static Iterable<?> data() {
+    return getTestParameters()
+        .withDexRuntimes()
+        .withCfRuntimesStartingFromIncluding(CfVm.JDK17)
+        .withAllApiLevelsAlsoForCf()
+        .build();
+  }
+
+  @Test
+  public void test() throws Exception {
+    testForDesugaring(parameters)
+        .addInnerClassesAndStrippedOuter(getClass())
+        .run(parameters.getRuntime(), TestClass.class)
+        .assertSuccess();
+  }
+
+  public static class TestClass {
+
+    public static void main(String[] args) {
+      // The methods are actually from Java 16, but we can test them from Java 17.
+      testCheckIndex();
+      testCheckFromToIndex();
+      testCheckFromIndexSize();
+    }
+
+    private static void testCheckIndex() {
+      for (long i = 0L; i < 10L; i++) {
+        assertEquals(i, Objects.checkIndex(i, 10L));
+      }
+
+      try {
+        throw new AssertionError(Objects.checkIndex(-1L, 10L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkIndex(10L, 0L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkIndex(0L, 0L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+    }
+
+    private static void testCheckFromToIndex() {
+      for (long i = 0L; i <= 10L; i++) {
+        for (long j = i; j <= 10L; j++) {
+          assertEquals(i, Objects.checkFromToIndex(i, j, 10L));
+        }
+      }
+      assertEquals(0L, Objects.checkFromToIndex(0L, 0L, 0L));
+
+      try {
+        throw new AssertionError(Objects.checkFromToIndex(4L, 2L, 10L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromToIndex(-1L, 5L, 10L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromToIndex(0L, -1L, 10L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromToIndex(11L, 11L, 10L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromToIndex(0L, 1L, 0L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromToIndex(1L, 1L, 0L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+    }
+
+    private static void testCheckFromIndexSize() {
+      for (long i = 0L; i <= 10L; i++) {
+        for (long j = 10L - i; j >= 0L; j--) {
+          assertEquals(i, Objects.checkFromIndexSize(i, j, 10L));
+        }
+      }
+      assertEquals(0, Objects.checkFromIndexSize(0L, 0L, 0L));
+
+      try {
+        throw new AssertionError(Objects.checkFromIndexSize(8L, 4L, 10L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromIndexSize(-1L, 5L, 10L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromIndexSize(11L, 0L, 10L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromIndexSize(0L, 1L, 0L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromIndexSize(1L, 1L, 0L));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+
+      // Check for cases where overflow might occur producing incorrect results.
+      try {
+        throw new AssertionError(Objects.checkFromIndexSize(Long.MAX_VALUE, 1L, Long.MAX_VALUE));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+      try {
+        throw new AssertionError(Objects.checkFromIndexSize(0L, 1L, Long.MIN_VALUE));
+      } catch (IndexOutOfBoundsException expected) {
+      }
+    }
+
+    private static void assertEquals(long expected, long actual) {
+      if (expected != actual) {
+        throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
+      }
+    }
+  }
+}
diff --git a/src/test/examplesJava17/backport/StrictMathBackportJava17Main.java b/src/test/examplesJava17/backport/StrictMathBackportJava17Main.java
deleted file mode 100644
index 028e24f..0000000
--- a/src/test/examplesJava17/backport/StrictMathBackportJava17Main.java
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright (c) 2023, 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 backport;
-
-public class StrictMathBackportJava17Main {
-
-  public static void main(String[] args) {
-    // The methods are actually from Java 15, but we can test them from Java 17.
-    testAbsExactInteger();
-    testAbsExactLong();
-    // The methods are actually from Java 14, but we can test them from Java 17.
-    testDecrementExactInteger();
-    testDecrementExactLong();
-    testIncrementExactInteger();
-    testIncrementExactLong();
-    testNegateExactInteger();
-    testNegateExactLong();
-  }
-
-  private static void testAbsExactInteger() {
-    assertEquals(42, StrictMath.absExact(42));
-    assertEquals(42, StrictMath.absExact(-42));
-    assertEquals(Integer.MAX_VALUE, StrictMath.absExact(Integer.MAX_VALUE));
-    try {
-      throw new AssertionError(StrictMath.absExact(Integer.MIN_VALUE));
-    } catch (ArithmeticException expected) {
-
-    }
-  }
-
-  private static void testAbsExactLong() {
-    assertEquals(42L, StrictMath.absExact(42L));
-    assertEquals(42L, StrictMath.absExact(-42L));
-    assertEquals(Long.MAX_VALUE, StrictMath.absExact(Long.MAX_VALUE));
-    try {
-      throw new AssertionError(StrictMath.absExact(Long.MIN_VALUE));
-    } catch (ArithmeticException expected) {
-
-    }
-  }
-
-  private static void testDecrementExactInteger() {
-    assertEquals(-1, StrictMath.decrementExact(0));
-    assertEquals(Integer.MIN_VALUE, StrictMath.decrementExact(Integer.MIN_VALUE + 1));
-
-    try {
-      throw new AssertionError(StrictMath.decrementExact(Integer.MIN_VALUE));
-    } catch (ArithmeticException expected) {
-    }
-  }
-
-  private static void testDecrementExactLong() {
-    assertEquals(-1L, StrictMath.decrementExact(0L));
-    assertEquals(Long.MIN_VALUE, StrictMath.decrementExact(Long.MIN_VALUE + 1L));
-
-    try {
-      throw new AssertionError(StrictMath.decrementExact(Long.MIN_VALUE));
-    } catch (ArithmeticException expected) {
-    }
-  }
-
-  private static void testIncrementExactInteger() {
-    assertEquals(1, StrictMath.incrementExact(0));
-    assertEquals(Integer.MAX_VALUE, StrictMath.incrementExact(Integer.MAX_VALUE - 1));
-
-    try {
-      throw new AssertionError(StrictMath.incrementExact(Integer.MAX_VALUE));
-    } catch (ArithmeticException expected) {
-    }
-  }
-
-  private static void testIncrementExactLong() {
-    assertEquals(1L, StrictMath.incrementExact(0L));
-    assertEquals(Long.MAX_VALUE, StrictMath.incrementExact(Long.MAX_VALUE - 1L));
-
-    try {
-      throw new AssertionError(StrictMath.incrementExact(Long.MAX_VALUE));
-    } catch (ArithmeticException expected) {
-    }
-  }
-
-  private static void testNegateExactInteger() {
-    assertEquals(0, StrictMath.negateExact(0));
-    assertEquals(-1, StrictMath.negateExact(1));
-    assertEquals(1, StrictMath.negateExact(-1));
-    assertEquals(-2_147_483_647, StrictMath.negateExact(Integer.MAX_VALUE));
-
-    try {
-      throw new AssertionError(StrictMath.negateExact(Integer.MIN_VALUE));
-    } catch (ArithmeticException expected) {
-    }
-  }
-
-  private static void testNegateExactLong() {
-    assertEquals(0L, StrictMath.negateExact(0L));
-    assertEquals(-1L, StrictMath.negateExact(1L));
-    assertEquals(1L, StrictMath.negateExact(-1L));
-    assertEquals(-9_223_372_036_854_775_807L, StrictMath.negateExact(Long.MAX_VALUE));
-
-    try {
-      throw new AssertionError(StrictMath.negateExact(Long.MIN_VALUE));
-    } catch (ArithmeticException expected) {
-    }
-  }
-
-  private static void assertEquals(int expected, int actual) {
-    if (expected != actual) {
-      throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
-    }
-  }
-
-  private static void assertEquals(long expected, long actual) {
-    if (expected != actual) {
-      throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
-    }
-  }
-}
diff --git a/src/test/examplesJava17/backport/StrictMathBackportJava17Test.java b/src/test/examplesJava17/backport/StrictMathBackportJava17Test.java
new file mode 100644
index 0000000..0f71867
--- /dev/null
+++ b/src/test/examplesJava17/backport/StrictMathBackportJava17Test.java
@@ -0,0 +1,152 @@
+// Copyright (c) 2024, 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 backport;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestRuntime.CfVm;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class StrictMathBackportJava17Test extends TestBase {
+
+  @Parameter(0)
+  public TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static Iterable<?> data() {
+    return getTestParameters()
+        .withDexRuntimes()
+        .withCfRuntimesStartingFromIncluding(CfVm.JDK17)
+        .withAllApiLevelsAlsoForCf()
+        .build();
+  }
+
+  @Test
+  public void test() throws Exception {
+    testForDesugaring(parameters)
+        .addInnerClassesAndStrippedOuter(getClass())
+        .run(parameters.getRuntime(), TestClass.class)
+        .assertSuccess();
+  }
+
+  public static class TestClass {
+
+    public static void main(String[] args) {
+      // The methods are actually from Java 15, but we can test them from Java 17.
+      testAbsExactInteger();
+      testAbsExactLong();
+      // The methods are actually from Java 14, but we can test them from Java 17.
+      testDecrementExactInteger();
+      testDecrementExactLong();
+      testIncrementExactInteger();
+      testIncrementExactLong();
+      testNegateExactInteger();
+      testNegateExactLong();
+    }
+
+    private static void testAbsExactInteger() {
+      assertEquals(42, StrictMath.absExact(42));
+      assertEquals(42, StrictMath.absExact(-42));
+      assertEquals(Integer.MAX_VALUE, StrictMath.absExact(Integer.MAX_VALUE));
+      try {
+        throw new AssertionError(StrictMath.absExact(Integer.MIN_VALUE));
+      } catch (ArithmeticException expected) {
+
+      }
+    }
+
+    private static void testAbsExactLong() {
+      assertEquals(42L, StrictMath.absExact(42L));
+      assertEquals(42L, StrictMath.absExact(-42L));
+      assertEquals(Long.MAX_VALUE, StrictMath.absExact(Long.MAX_VALUE));
+      try {
+        throw new AssertionError(StrictMath.absExact(Long.MIN_VALUE));
+      } catch (ArithmeticException expected) {
+
+      }
+    }
+
+    private static void testDecrementExactInteger() {
+      assertEquals(-1, StrictMath.decrementExact(0));
+      assertEquals(Integer.MIN_VALUE, StrictMath.decrementExact(Integer.MIN_VALUE + 1));
+
+      try {
+        throw new AssertionError(StrictMath.decrementExact(Integer.MIN_VALUE));
+      } catch (ArithmeticException expected) {
+      }
+    }
+
+    private static void testDecrementExactLong() {
+      assertEquals(-1L, StrictMath.decrementExact(0L));
+      assertEquals(Long.MIN_VALUE, StrictMath.decrementExact(Long.MIN_VALUE + 1L));
+
+      try {
+        throw new AssertionError(StrictMath.decrementExact(Long.MIN_VALUE));
+      } catch (ArithmeticException expected) {
+      }
+    }
+
+    private static void testIncrementExactInteger() {
+      assertEquals(1, StrictMath.incrementExact(0));
+      assertEquals(Integer.MAX_VALUE, StrictMath.incrementExact(Integer.MAX_VALUE - 1));
+
+      try {
+        throw new AssertionError(StrictMath.incrementExact(Integer.MAX_VALUE));
+      } catch (ArithmeticException expected) {
+      }
+    }
+
+    private static void testIncrementExactLong() {
+      assertEquals(1L, StrictMath.incrementExact(0L));
+      assertEquals(Long.MAX_VALUE, StrictMath.incrementExact(Long.MAX_VALUE - 1L));
+
+      try {
+        throw new AssertionError(StrictMath.incrementExact(Long.MAX_VALUE));
+      } catch (ArithmeticException expected) {
+      }
+    }
+
+    private static void testNegateExactInteger() {
+      assertEquals(0, StrictMath.negateExact(0));
+      assertEquals(-1, StrictMath.negateExact(1));
+      assertEquals(1, StrictMath.negateExact(-1));
+      assertEquals(-2_147_483_647, StrictMath.negateExact(Integer.MAX_VALUE));
+
+      try {
+        throw new AssertionError(StrictMath.negateExact(Integer.MIN_VALUE));
+      } catch (ArithmeticException expected) {
+      }
+    }
+
+    private static void testNegateExactLong() {
+      assertEquals(0L, StrictMath.negateExact(0L));
+      assertEquals(-1L, StrictMath.negateExact(1L));
+      assertEquals(1L, StrictMath.negateExact(-1L));
+      assertEquals(-9_223_372_036_854_775_807L, StrictMath.negateExact(Long.MAX_VALUE));
+
+      try {
+        throw new AssertionError(StrictMath.negateExact(Long.MIN_VALUE));
+      } catch (ArithmeticException expected) {
+      }
+    }
+
+    private static void assertEquals(int expected, int actual) {
+      if (expected != actual) {
+        throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
+      }
+    }
+
+    private static void assertEquals(long expected, long actual) {
+      if (expected != actual) {
+        throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
+      }
+    }
+  }
+}
diff --git a/src/test/java/com/android/tools/r8/desugar/backports/MathBackportJava17Test.java b/src/test/java/com/android/tools/r8/desugar/backports/MathBackportJava17Test.java
deleted file mode 100644
index c612792..0000000
--- a/src/test/java/com/android/tools/r8/desugar/backports/MathBackportJava17Test.java
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) 2023, 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.desugar.backports;
-
-import static com.android.tools.r8.utils.FileUtils.JAR_EXTENSION;
-
-import com.android.tools.r8.TestParameters;
-import com.android.tools.r8.TestRuntime.CfVm;
-import com.android.tools.r8.ToolHelper;
-import com.android.tools.r8.utils.AndroidApiLevel;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-@RunWith(Parameterized.class)
-public final class MathBackportJava17Test extends AbstractBackportTest {
-  @Parameters(name = "{0}")
-  public static Iterable<?> data() {
-    return getTestParameters()
-        .withDexRuntimes()
-        .withCfRuntimesStartingFromIncluding(CfVm.JDK17)
-        .withAllApiLevelsAlsoForCf()
-        .build();
-  }
-
-  private static final Path TEST_JAR =
-      Paths.get(ToolHelper.TESTS_BUILD_DIR).resolve("examplesJava17/backport" + JAR_EXTENSION);
-
-  public MathBackportJava17Test(TestParameters parameters) {
-    super(parameters, Math.class, TEST_JAR, "backport.MathBackportJava17Main");
-
-    // Math.absExact.
-    registerTarget(AndroidApiLevel.U, 8);
-  }
-}
diff --git a/src/test/java/com/android/tools/r8/desugar/backports/ObjectsBackportJava17Test.java b/src/test/java/com/android/tools/r8/desugar/backports/ObjectsBackportJava17Test.java
deleted file mode 100644
index af9af9d..0000000
--- a/src/test/java/com/android/tools/r8/desugar/backports/ObjectsBackportJava17Test.java
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 2023, 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.desugar.backports;
-
-import static com.android.tools.r8.utils.FileUtils.JAR_EXTENSION;
-
-import com.android.tools.r8.TestParameters;
-import com.android.tools.r8.TestRuntime.CfVm;
-import com.android.tools.r8.ToolHelper;
-import com.android.tools.r8.utils.AndroidApiLevel;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Objects;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-@RunWith(Parameterized.class)
-public final class ObjectsBackportJava17Test extends AbstractBackportTest {
-  @Parameters(name = "{0}")
-  public static Iterable<?> data() {
-    return getTestParameters()
-        .withDexRuntimes()
-        .withCfRuntimesStartingFromIncluding(CfVm.JDK17)
-        .withAllApiLevelsAlsoForCf()
-        .build();
-  }
-
-  private static final Path TEST_JAR =
-      Paths.get(ToolHelper.TESTS_BUILD_DIR).resolve("examplesJava17/backport" + JAR_EXTENSION);
-  private static final String TEST_CLASS = "backport.ObjectsBackportJava17Main";
-
-  public ObjectsBackportJava17Test(TestParameters parameters) {
-    super(parameters, Objects.class, TEST_JAR, TEST_CLASS);
-    // Objects.checkFromIndexSize, Objects.checkFromToIndex, Objects.checkIndex.
-    registerTarget(AndroidApiLevel.U, 21);
-  }
-}
diff --git a/src/test/java/com/android/tools/r8/desugar/backports/StrictMathBackportJava17Test.java b/src/test/java/com/android/tools/r8/desugar/backports/StrictMathBackportJava17Test.java
deleted file mode 100644
index f180eab..0000000
--- a/src/test/java/com/android/tools/r8/desugar/backports/StrictMathBackportJava17Test.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2023, 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.desugar.backports;
-
-import static com.android.tools.r8.utils.FileUtils.JAR_EXTENSION;
-
-import com.android.tools.r8.TestParameters;
-import com.android.tools.r8.TestRuntime.CfVm;
-import com.android.tools.r8.ToolHelper;
-import com.android.tools.r8.utils.AndroidApiLevel;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-@RunWith(Parameterized.class)
-public final class StrictMathBackportJava17Test extends AbstractBackportTest {
-
-  @Parameters(name = "{0}")
-  public static Iterable<?> data() {
-    return getTestParameters()
-        .withDexRuntimes()
-        .withCfRuntimesStartingFromIncluding(CfVm.JDK17)
-        .withAllApiLevelsAlsoForCf()
-        .build();
-  }
-
-  private static final Path TEST_JAR =
-      Paths.get(ToolHelper.TESTS_BUILD_DIR).resolve("examplesJava17/backport" + JAR_EXTENSION);
-
-  public StrictMathBackportJava17Test(TestParameters parameters) {
-    super(parameters, StrictMath.class, TEST_JAR, "backport.StrictMathBackportJava17Main");
-    registerTarget(AndroidApiLevel.U, 30);
-  }
-}
diff --git a/src/test/testbase/java/com/android/tools/r8/TestBuilder.java b/src/test/testbase/java/com/android/tools/r8/TestBuilder.java
index 84ccfd9..02d0e06 100644
--- a/src/test/testbase/java/com/android/tools/r8/TestBuilder.java
+++ b/src/test/testbase/java/com/android/tools/r8/TestBuilder.java
@@ -3,11 +3,14 @@
 // BSD-style license that can be found in the LICENSE file.
 package com.android.tools.r8;
 
+import static com.android.tools.r8.TestBase.descriptor;
+
 import com.android.tools.r8.ClassFileConsumer.ArchiveConsumer;
 import com.android.tools.r8.TestBase.Backend;
-import com.android.tools.r8.androidresources.AndroidResourceTestingUtils.AndroidTestResource;
 import com.android.tools.r8.debug.DebugTestConfig;
 import com.android.tools.r8.errors.Unimplemented;
+import com.android.tools.r8.transformers.ClassFileTransformer.FieldPredicate;
+import com.android.tools.r8.transformers.ClassFileTransformer.MethodPredicate;
 import com.android.tools.r8.utils.AndroidApiLevel;
 import com.android.tools.r8.utils.ListUtils;
 import com.android.tools.r8.utils.structural.Ordered;
@@ -144,6 +147,18 @@
     return addProgramFiles(getFilesForInnerClasses(classes));
   }
 
+  public T addInnerClassesAndStrippedOuter(Class<?> clazz) throws IOException {
+    return addProgramClassFileData(
+            TestBase.transformer(clazz)
+                .removeFields(FieldPredicate.all())
+                .removeMethods(MethodPredicate.all())
+                .removeAllAnnotations()
+                .setSuper(descriptor(Object.class))
+                .setImplements()
+                .transform())
+        .addInnerClasses(ImmutableList.of(clazz));
+  }
+
   public abstract T addLibraryFiles(Collection<Path> files);
 
   public T addLibraryClasses(Class<?>... classes) {