Move java 9 tests to java 9 module

Change-Id: I97b09d8a6b09f504872cb8debf6dff7179e3b28a
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/jdk11/InputStreamTransferToTest.java b/src/test/examplesJava9/desugaredlib/InputStreamTransferToTest.java
similarity index 67%
rename from src/test/java/com/android/tools/r8/desugar/desugaredlibrary/jdk11/InputStreamTransferToTest.java
rename to src/test/examplesJava9/desugaredlib/InputStreamTransferToTest.java
index 130cce2..720dcfd 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/jdk11/InputStreamTransferToTest.java
+++ b/src/test/examplesJava9/desugaredlib/InputStreamTransferToTest.java
@@ -2,7 +2,7 @@
 // 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.desugaredlibrary.jdk11;
+package desugaredlib;
 
 import static com.android.tools.r8.desugar.desugaredlibrary.test.CompilationSpecification.SPECIFICATIONS_WITH_CF2CF;
 import static com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification.JDK11_PATH;
@@ -16,8 +16,11 @@
 import com.android.tools.r8.utils.AndroidApiLevel;
 import com.android.tools.r8.utils.StringUtils;
 import com.google.common.collect.ImmutableList;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.List;
 import org.junit.Assume;
 import org.junit.Test;
@@ -32,11 +35,9 @@
   private final LibraryDesugaringSpecification libraryDesugaringSpecification;
   private final CompilationSpecification compilationSpecification;
 
-  private static final Path INPUT_JAR =
-      Paths.get(ToolHelper.EXAMPLES_JAVA9_BUILD_DIR + "transferto.jar");
   private static final String EXPECTED_OUTPUT =
       StringUtils.lines("Hello World!", "Hello World!", "Hello World!", "$Hello World!");
-  private static final String MAIN_CLASS = "transferto.TestClass";
+  private static final Class<?> MAIN_CLASS = TestClass.class;
 
   @Parameters(name = "{0}, spec: {1}, {2}")
   public static List<Object[]> data() {
@@ -63,7 +64,7 @@
             && !libraryDesugaringSpecification.hasNioFileDesugaring(parameters)
             && compilationSpecification.isCfToCf());
     testForDesugaredLibrary(parameters, libraryDesugaringSpecification, compilationSpecification)
-        .addProgramFiles(INPUT_JAR)
+        .addInnerClassesAndStrippedOuter(getClass())
         .addKeepMainRule(MAIN_CLASS)
         .run(parameters.getRuntime(), MAIN_CLASS)
         .assertSuccessWithOutput(EXPECTED_OUTPUT);
@@ -81,10 +82,54 @@
             && !libraryDesugaringSpecification.hasNioFileDesugaring(parameters)
             && compilationSpecification.isCfToCf());
     testForDesugaredLibrary(parameters, libraryDesugaringSpecification, compilationSpecification)
-        .addProgramFiles(INPUT_JAR)
+        .addInnerClassesAndStrippedOuter(getClass())
         .addKeepMainRule(MAIN_CLASS)
         .overrideLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.T))
         .run(parameters.getRuntime(), MAIN_CLASS)
         .assertSuccessWithOutput(EXPECTED_OUTPUT);
   }
+
+  public static class MyInputStream extends ByteArrayInputStream {
+
+    public MyInputStream(byte[] buf) {
+      super(buf);
+    }
+
+    @Override
+    public long transferTo(OutputStream out) throws IOException {
+      out.write((int) '$');
+      return super.transferTo(out);
+    }
+  }
+
+  public static class TestClass {
+    public static void main(String[] args) throws IOException {
+      transferTo();
+      transferToOverride();
+    }
+
+    public static void transferTo() throws IOException {
+      String initialString = "Hello World!";
+      System.out.println(initialString);
+
+      try (InputStream inputStream = new ByteArrayInputStream(initialString.getBytes());
+          ByteArrayOutputStream targetStream = new ByteArrayOutputStream()) {
+        inputStream.transferTo(targetStream);
+        String copied = new String(targetStream.toByteArray());
+        System.out.println(copied);
+      }
+    }
+
+    public static void transferToOverride() throws IOException {
+      String initialString = "Hello World!";
+      System.out.println(initialString);
+
+      try (MyInputStream inputStream = new MyInputStream(initialString.getBytes());
+          ByteArrayOutputStream targetStream = new ByteArrayOutputStream()) {
+        inputStream.transferTo(targetStream);
+        String copied = new String(targetStream.toByteArray());
+        System.out.println(copied);
+      }
+    }
+  }
 }
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/ProgramRewritingTest.java b/src/test/examplesJava9/desugaredlib/ProgramRewritingTest.java
similarity index 71%
rename from src/test/java/com/android/tools/r8/desugar/desugaredlibrary/ProgramRewritingTest.java
rename to src/test/examplesJava9/desugaredlib/ProgramRewritingTest.java
index dd9fe54..3333f39 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/ProgramRewritingTest.java
+++ b/src/test/examplesJava9/desugaredlib/ProgramRewritingTest.java
@@ -2,7 +2,7 @@
 // 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.desugaredlibrary;
+package desugaredlib;
 
 import static com.android.tools.r8.ToolHelper.DESUGARED_JDK_8_LIB_JAR;
 import static com.android.tools.r8.desugar.desugaredlibrary.test.CompilationSpecification.DEFAULT_SPECIFICATIONS;
@@ -20,6 +20,7 @@
 import com.android.tools.r8.TestParameters;
 import com.android.tools.r8.ToolHelper;
 import com.android.tools.r8.ToolHelper.DexVm;
+import com.android.tools.r8.desugar.desugaredlibrary.DesugaredLibraryTestBase;
 import com.android.tools.r8.desugar.desugaredlibrary.test.CompilationSpecification;
 import com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification;
 import com.android.tools.r8.utils.AndroidApiLevel;
@@ -30,9 +31,19 @@
 import com.android.tools.r8.utils.codeinspector.InstructionSubject;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
-import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
 import java.util.List;
+import java.util.Queue;
+import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -41,7 +52,7 @@
 @RunWith(Parameterized.class)
 public class ProgramRewritingTest extends DesugaredLibraryTestBase {
 
-  private static final String TEST_CLASS = "stream.ProgramRewritingTestClass";
+  private static final Class<?> TEST_CLASS = ProgramRewritingTestClass.class;
 
   private final TestParameters parameters;
   private final LibraryDesugaringSpecification libraryDesugaringSpecification;
@@ -92,7 +103,7 @@
     SingleTestRunResult<?> run =
         testForDesugaredLibrary(
                 parameters, libraryDesugaringSpecification, compilationSpecification)
-            .addProgramFiles(Paths.get(ToolHelper.EXAMPLES_JAVA9_BUILD_DIR + "stream.jar"))
+            .addInnerClassesAndStrippedOuter(getClass())
             .addKeepMainRule(TEST_CLASS)
             .compile()
             .inspect(this::checkRewrittenInvokes)
@@ -236,4 +247,66 @@
     }
     assertEquals(expectedResult.trim(), keepRules.trim());
   }
+
+  public static class ProgramRewritingTestClass {
+
+    // Each print to the console is immediately followed by the expected result so the tests
+    // can assert the results by checking the lines 2 by 2.
+    public static void main(String[] args) {
+      Set<Object> set = new HashSet<>();
+      List<Object> list = new ArrayList<>();
+      ArrayList<Object> aList = new ArrayList<>();
+      Queue<Object> queue = new LinkedList<>();
+      LinkedHashSet<Object> lhs = new LinkedHashSet<>();
+      // Following should be rewritten to invokeStatic to the dispatch class.
+      System.out.println(set.spliterator().getClass().getName());
+      System.out.println("j$.util.Spliterators$IteratorSpliterator");
+      // Following should be rewritten to invokeStatic to Collection dispatch class.
+      System.out.println(set.stream().getClass().getName());
+      System.out.println("j$.util.stream.ReferencePipeline$Head");
+      // Following should not be rewritten.
+      System.out.println(set.iterator().getClass().getName());
+      System.out.println("java.util.HashMap$KeyIterator");
+      // Following should be rewritten to invokeStatic to Collection dispatch class.
+      System.out.println(queue.stream().getClass().getName());
+      System.out.println("j$.util.stream.ReferencePipeline$Head");
+      // Following should be rewritten as retarget core lib member.
+      System.out.println(lhs.spliterator().getClass().getName());
+      System.out.println("j$.util.Spliterators$IteratorSpliterator");
+      // Remove follows the don't rewrite rule.
+      list.add(new Object());
+      Iterator iterator = list.iterator();
+      iterator.next();
+      iterator.remove();
+      // Static methods (same name, different signatures).
+      System.out.println(Arrays.spliterator(new Object[] {new Object()}).getClass().getName());
+      System.out.println("j$.util.Spliterators$ArraySpliterator");
+      System.out.println(
+          Arrays.spliterator(new Object[] {new Object()}, 0, 0).getClass().getName());
+      System.out.println("j$.util.Spliterators$ArraySpliterator");
+      System.out.println(Arrays.stream(new Object[] {new Object()}).getClass().getName());
+      System.out.println("j$.util.stream.ReferencePipeline$Head");
+      System.out.println(Arrays.stream(new Object[] {new Object()}, 0, 0).getClass().getName());
+      System.out.println("j$.util.stream.ReferencePipeline$Head");
+      // Following should be rewritten to invokeStatic to dispatch class.
+      System.out.println(list.stream().getClass().getName());
+      System.out.println("j$.util.stream.ReferencePipeline$Head");
+      // Following should call companion method (desugared library class).
+      System.out.println(IntStream.range(0, 5).getClass().getName());
+      System.out.println("j$.util.stream.IntPipeline$Head");
+      // Following should call List dispatch (sort), rewritten from invoke interface.
+      // Comparator.comparingInt should call companion method (desugared library class).
+      Collections.addAll(list, new Object(), new Object());
+      list.sort(Comparator.comparingInt(Object::hashCode));
+      // Following  should call List dispatch (sort), rewritten from invoke virtual.
+      // Comparator.comparingInt should call companion method (desugared library class).
+      Collections.addAll(aList, new Object(), new Object());
+      aList.sort(Comparator.comparingInt(Object::hashCode));
+      // Following should be rewritten to invokeStatic to Collection dispatch class.
+      System.out.println(list.stream().getClass().getName());
+      System.out.println("j$.util.stream.ReferencePipeline$Head");
+      // Following should call companion method (desugared library class) [Java 9].
+      // System.out.println(Stream.iterate(0,x->x<10,x->x+1).getClass().getName());
+    }
+  }
 }
diff --git a/src/test/examplesJava9/stream/ProgramRewritingTestClass.java b/src/test/examplesJava9/stream/ProgramRewritingTestClass.java
deleted file mode 100644
index 6bf4f12..0000000
--- a/src/test/examplesJava9/stream/ProgramRewritingTestClass.java
+++ /dev/null
@@ -1,79 +0,0 @@
-// 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 stream;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.Set;
-import java.util.stream.IntStream;
-
-public class ProgramRewritingTestClass {
-
-  // Each print to the console is immediately followed by the expected result so the tests
-  // can assert the results by checking the lines 2 by 2.
-  public static void main(String[] args) {
-    Set<Object> set = new HashSet<>();
-    List<Object> list = new ArrayList<>();
-    ArrayList<Object> aList = new ArrayList<>();
-    Queue<Object> queue = new LinkedList<>();
-    LinkedHashSet<Object> lhs = new LinkedHashSet<>();
-    // Following should be rewritten to invokeStatic to the dispatch class.
-    System.out.println(set.spliterator().getClass().getName());
-    System.out.println("j$.util.Spliterators$IteratorSpliterator");
-    // Following should be rewritten to invokeStatic to Collection dispatch class.
-    System.out.println(set.stream().getClass().getName());
-    System.out.println("j$.util.stream.ReferencePipeline$Head");
-    // Following should not be rewritten.
-    System.out.println(set.iterator().getClass().getName());
-    System.out.println("java.util.HashMap$KeyIterator");
-    // Following should be rewritten to invokeStatic to Collection dispatch class.
-    System.out.println(queue.stream().getClass().getName());
-    System.out.println("j$.util.stream.ReferencePipeline$Head");
-    // Following should be rewritten as retarget core lib member.
-    System.out.println(lhs.spliterator().getClass().getName());
-    System.out.println("j$.util.Spliterators$IteratorSpliterator");
-    // Remove follows the don't rewrite rule.
-    list.add(new Object());
-    Iterator iterator = list.iterator();
-    iterator.next();
-    iterator.remove();
-    // Static methods (same name, different signatures).
-    System.out.println(Arrays.spliterator(new Object[]{new Object()}).getClass().getName());
-    System.out.println("j$.util.Spliterators$ArraySpliterator");
-    System.out.println(Arrays.spliterator(new Object[]{new Object()}, 0, 0).getClass().getName());
-    System.out.println("j$.util.Spliterators$ArraySpliterator");
-    System.out.println(Arrays.stream(new Object[]{new Object()}).getClass().getName());
-    System.out.println("j$.util.stream.ReferencePipeline$Head");
-    System.out.println(Arrays.stream(new Object[]{new Object()}, 0, 0).getClass().getName());
-    System.out.println("j$.util.stream.ReferencePipeline$Head");
-    // Following should be rewritten to invokeStatic to dispatch class.
-    System.out.println(list.stream().getClass().getName());
-    System.out.println("j$.util.stream.ReferencePipeline$Head");
-    // Following should call companion method (desugared library class).
-    System.out.println(IntStream.range(0, 5).getClass().getName());
-    System.out.println("j$.util.stream.IntPipeline$Head");
-    // Following should call List dispatch (sort), rewritten from invoke interface.
-    // Comparator.comparingInt should call companion method (desugared library class).
-    Collections.addAll(list, new Object(), new Object());
-    list.sort(Comparator.comparingInt(Object::hashCode));
-    // Following  should call List dispatch (sort), rewritten from invoke virtual.
-    // Comparator.comparingInt should call companion method (desugared library class).
-    Collections.addAll(aList, new Object(), new Object());
-    aList.sort(Comparator.comparingInt(Object::hashCode));
-    // Following should be rewritten to invokeStatic to Collection dispatch class.
-    System.out.println(list.stream().getClass().getName());
-    System.out.println("j$.util.stream.ReferencePipeline$Head");
-    // Following should call companion method (desugared library class) [Java 9].
-    // System.out.println(Stream.iterate(0,x->x<10,x->x+1).getClass().getName());
-  }
-}
diff --git a/src/test/examplesJava9/transferto/MyInputStream.java b/src/test/examplesJava9/transferto/MyInputStream.java
deleted file mode 100644
index 36a5e8b..0000000
--- a/src/test/examplesJava9/transferto/MyInputStream.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// 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 transferto;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class MyInputStream extends ByteArrayInputStream {
-
-  public MyInputStream(byte[] buf) {
-    super(buf);
-  }
-
-  @Override
-  public long transferTo(OutputStream out) throws IOException {
-    out.write((int) '$');
-    return super.transferTo(out);
-  }
-}
diff --git a/src/test/examplesJava9/transferto/TestClass.java b/src/test/examplesJava9/transferto/TestClass.java
deleted file mode 100644
index fd3c91b..0000000
--- a/src/test/examplesJava9/transferto/TestClass.java
+++ /dev/null
@@ -1,41 +0,0 @@
-// 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 transferto;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-public class TestClass {
-  public static void main(String[] args) throws IOException {
-    transferTo();
-    transferToOverride();
-  }
-
-  public static void transferTo() throws IOException {
-    String initialString = "Hello World!";
-    System.out.println(initialString);
-
-    try (InputStream inputStream = new ByteArrayInputStream(initialString.getBytes());
-        ByteArrayOutputStream targetStream = new ByteArrayOutputStream()) {
-      inputStream.transferTo(targetStream);
-      String copied = new String(targetStream.toByteArray());
-      System.out.println(copied);
-    }
-  }
-
-  public static void transferToOverride() throws IOException {
-    String initialString = "Hello World!";
-    System.out.println(initialString);
-
-    try (MyInputStream inputStream = new MyInputStream(initialString.getBytes());
-        ByteArrayOutputStream targetStream = new ByteArrayOutputStream()) {
-      inputStream.transferTo(targetStream);
-      String copied = new String(targetStream.toByteArray());
-      System.out.println(copied);
-    }
-  }
-}