Test that javac will compile strings expecting an UTF-8 encoding

This was the problem in b/119097175, where javac assume strings being
encoded in UTF-16.

Bug: 148986159
Change-Id: Ib2b59cdeb152c7ec9d7275a1b60f350aaf04ecba
diff --git a/src/test/java/com/android/tools/r8/testing/UnicodeUtf8Test.java b/src/test/java/com/android/tools/r8/testing/UnicodeUtf8Test.java
new file mode 100644
index 0000000..85264d1
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/testing/UnicodeUtf8Test.java
@@ -0,0 +1,51 @@
+// Copyright (c) 2020, 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.testing;
+
+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 java.io.IOException;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+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 test is ensuring that javac will compile expecting an UTF-8 encoding of the test. */
+@RunWith(Parameterized.class)
+public class UnicodeUtf8Test extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  public UnicodeUtf8Test(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testRuntime() throws ExecutionException, CompilationFailedException, IOException {
+    testForRuntime(parameters)
+        .addProgramClasses(Main.class)
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines("\uD83C\uDCA1");
+  }
+
+  public static class Main {
+
+    private static final String MOTOR_HEAD = "🂡";
+
+    public static void main(String[] args) throws UnsupportedEncodingException {
+      (new PrintStream(System.out, true, "UTF-8")).println(MOTOR_HEAD);
+    }
+  }
+}