Reapply "Move backport test to java 11 package"

This reverts commit 732cc09c16ceb61a0b58a4f19daba7c2d5c1305d.


Reapply "Move Java 10 backport to Java 10 module"

This reverts commit 545813dfcaf71c177ca1ef7fba9172f6c528869f.


Reapply "Move Java9 backport test to java 9 module"

This reverts commit 0ff3415ebe3965d6ced3759dcf263f12fa2d0ec7.

Bug: b/380808556
Change-Id: I628f45b00b691126e25bc679889e88cf4fc22d16
diff --git a/src/test/examplesJava10/backport/ListBackportJava10Test.java b/src/test/examplesJava10/backport/ListBackportJava10Test.java
new file mode 100644
index 0000000..f8abd84
--- /dev/null
+++ b/src/test/examplesJava10/backport/ListBackportJava10Test.java
@@ -0,0 +1,101 @@
+// 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 backport;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestRuntime.CfVm;
+import com.android.tools.r8.desugar.backports.AbstractBackportTest;
+import com.android.tools.r8.utils.AndroidApiLevel;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class ListBackportJava10Test extends AbstractBackportTest {
+  @Parameters(name = "{0}")
+  public static Iterable<?> data() {
+    return getTestParameters()
+        .withCfRuntimesStartingFromIncluding(CfVm.JDK10)
+        .withDexRuntimes()
+        .withAllApiLevelsAlsoForCf()
+        .build();
+  }
+
+  public ListBackportJava10Test(TestParameters parameters) {
+    super(parameters, List.class, ListBackportJava10Main.class);
+    // Note: None of the methods in this test exist in the latest android.jar. If/when they ship in
+    // an actual API level, migrate these tests to ListBackportTest.
+
+    // Available since API 1 and used to test created lists.
+    ignoreInvokes("add");
+    ignoreInvokes("get");
+    ignoreInvokes("set");
+    ignoreInvokes("size");
+
+    // List.copyOf added in API 31.
+    registerTarget(AndroidApiLevel.S, 3);
+  }
+
+  public static class ListBackportJava10Main {
+
+    public static void main(String[] args) {
+      testCopyOf();
+    }
+
+    private static void testCopyOf() {
+      Object anObject0 = new Object();
+      Object anObject1 = new Object();
+      List<Object> original = Arrays.asList(anObject0, anObject1);
+      List<Object> copy = List.copyOf(original);
+      assertEquals(2, copy.size());
+      assertEquals(original, copy);
+      assertSame(anObject0, copy.get(0));
+      assertSame(anObject1, copy.get(1));
+      assertMutationNotAllowed(copy);
+
+      // Mutate the original backing collection and ensure it's not reflected in copy.
+      original.set(0, new Object());
+      assertSame(anObject0, copy.get(0));
+
+      try {
+        List.copyOf(null);
+        throw new AssertionError();
+      } catch (NullPointerException expected) {
+      }
+      try {
+        List.copyOf(Arrays.asList(1, null, 2));
+        throw new AssertionError();
+      } catch (NullPointerException expected) {
+      }
+    }
+
+    private static void assertMutationNotAllowed(List<Object> ofObject) {
+      try {
+        ofObject.add(new Object());
+        throw new AssertionError();
+      } catch (UnsupportedOperationException expected) {
+      }
+      try {
+        ofObject.set(0, new Object());
+        throw new AssertionError();
+      } catch (UnsupportedOperationException expected) {
+      }
+    }
+
+    private static void assertSame(Object expected, Object actual) {
+      if (expected != actual) {
+        throw new AssertionError("Expected <" + expected + "> but was <" + actual + ">");
+      }
+    }
+
+    private static void assertEquals(Object expected, Object actual) {
+      if (expected != actual && !expected.equals(actual)) {
+        throw new AssertionError("Expected <" + expected + "> but was <" + actual + ">");
+      }
+    }
+  }
+}