Added some tests to improve CTS ICU4J coverage

The main purpose of this is to add the infrastructure necessary
to add additional CTS coverage tests to ICU4J, a couple of tests
are provided because otherwise the code will not build.

(cherry picked from commit 11bc9330131107580b9cf84037eee279b5b3dfd2)

Bug: 22023363
Change-Id: Iefe35bd1c3ecb74c99ab9c50f0e8969c40cb76db
diff --git a/android_icu4j/Android.mk b/android_icu4j/Android.mk
index 4c06a5a..a1641be 100644
--- a/android_icu4j/Android.mk
+++ b/android_icu4j/Android.mk
@@ -36,6 +36,7 @@
 LOCAL_MODULE_TAGS := tests
 LOCAL_SRC_FILES := \
     $(call all-java-files-under,src/main/tests) \
+    $(call all-java-files-under,cts-coverage/src/main/tests) \
     $(call all-java-files-under,runner/src/main/java)
 LOCAL_JAVA_RESOURCE_DIRS := src/main/tests runner/src/main/java
 LOCAL_STATIC_JAVA_LIBRARIES := \
diff --git a/android_icu4j/cts-coverage/README.android b/android_icu4j/cts-coverage/README.android
new file mode 100644
index 0000000..e996c7c
--- /dev/null
+++ b/android_icu4j/cts-coverage/README.android
@@ -0,0 +1,3 @@
+This directory contains additional tests written for Android that ensure that the entire
+Android public ICU4J API has coverage. These tests will be added to ICU in a future release,
+at which point these tests can be deleted.
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/TestAll.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/TestAll.java
new file mode 100644
index 0000000..cb32763
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/TestAll.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.icu.cts.coverage;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * A suite of all the tests in this package and child packages.
+ */
+@RunWith(Suite.class)
+// Add classes in alphabetical order with a trailing comma even if it's the last entry.
+@Suite.SuiteClasses({
+        android.icu.cts.coverage.lang.TestAll.class,
+        android.icu.cts.coverage.text.TestAll.class,
+        android.icu.cts.coverage.util.TestAll.class,
+})
+public class TestAll {
+}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/lang/TestAll.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/lang/TestAll.java
new file mode 100644
index 0000000..2856244
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/lang/TestAll.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.icu.cts.coverage.lang;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * A suite of all the tests in this package.
+ */
+@RunWith(Suite.class)
+// Add classes in alphabetical order with a trailing comma even if it's the last entry.
+@Suite.SuiteClasses({
+        UCharacterTest.class,
+})
+public class TestAll {
+}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/lang/UCharacterTest.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/lang/UCharacterTest.java
new file mode 100644
index 0000000..f821e5a
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/lang/UCharacterTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.icu.cts.coverage.lang;
+
+import android.icu.lang.UCharacter;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Extra tests to improve CTS Test Coverage.
+ */
+@RunWith(JUnit4.class)
+public class UCharacterTest {
+
+    @Test
+    public void testNameAliasing() {
+        int input = '\u01a2';
+        String alias = UCharacter.getNameAlias(input);
+        assertEquals("LATIN CAPITAL LETTER GHA", alias);
+        int output = UCharacter.getCharFromNameAlias(alias);
+        assertEquals("alias for '" + input + "'", input, output);
+    }
+}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/RelativeDateTimeFormatterTest.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/RelativeDateTimeFormatterTest.java
new file mode 100644
index 0000000..9fc5044
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/RelativeDateTimeFormatterTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.icu.cts.coverage.text;
+
+import android.icu.text.RelativeDateTimeFormatter;
+import android.icu.util.ULocale;
+import java.util.Locale;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Extra tests to improve CTS Test Coverage.
+ */
+@RunWith(JUnit4.class)
+public class RelativeDateTimeFormatterTest {
+
+    /**
+     * Ensure that it behaves the same with an implicit default locale as it does with explicitly
+     * specifying the default locale.
+     */
+    @Test
+    public void testGetInstance() {
+        RelativeDateTimeFormatter withImplicitDefaultLocale
+                = RelativeDateTimeFormatter.getInstance(Locale.CANADA);
+        RelativeDateTimeFormatter withExplicitDefaultLocale
+                = RelativeDateTimeFormatter.getInstance(ULocale.getDefault());
+
+        String formatWithImplicitDefaultLocale =
+                withImplicitDefaultLocale.format(5,
+                        RelativeDateTimeFormatter.Direction.NEXT,
+                        RelativeDateTimeFormatter.RelativeUnit.MINUTES);
+
+        String formatWithExplicitDefaultLocale =
+                withExplicitDefaultLocale.format(5,
+                        RelativeDateTimeFormatter.Direction.NEXT,
+                        RelativeDateTimeFormatter.RelativeUnit.MINUTES);
+
+        assertEquals(formatWithExplicitDefaultLocale, formatWithImplicitDefaultLocale);
+    }
+}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TestAll.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TestAll.java
new file mode 100644
index 0000000..5938896
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TestAll.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.icu.cts.coverage.text;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * A suite of all the tests in this package.
+ */
+@RunWith(Suite.class)
+// Add classes in alphabetical order with a trailing comma even if it's the last entry.
+@Suite.SuiteClasses({
+        RelativeDateTimeFormatterTest.class,
+        TimeZoneNamesTest.class,
+})
+public class TestAll {
+}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TimeZoneNamesTest.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TimeZoneNamesTest.java
new file mode 100644
index 0000000..5af46b9
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TimeZoneNamesTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.icu.cts.coverage.text;
+
+import android.icu.text.TimeZoneNames;
+import android.icu.util.ULocale;
+import java.util.Locale;
+import java.util.Set;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Extra tests to improve CTS Test Coverage.
+ */
+@RunWith(JUnit4.class)
+public class TimeZoneNamesTest {
+
+    @Test
+    public void testGetInstance_Locale() {
+        TimeZoneNames uLocaleInstance = TimeZoneNames.getInstance(ULocale.CANADA);
+        TimeZoneNames localeInstance = TimeZoneNames.getInstance(Locale.CANADA);
+
+        Set<String> uLocaleAvailableIds = uLocaleInstance.getAvailableMetaZoneIDs();
+        Set<String> localeAvailableIds = localeInstance.getAvailableMetaZoneIDs();
+        assertEquals("Available ids", uLocaleAvailableIds, localeAvailableIds);
+
+        for (String availableId : uLocaleAvailableIds) {
+            long date = 1458385200000L;
+            TimeZoneNames.NameType nameType = TimeZoneNames.NameType.SHORT_GENERIC;
+            String uLocaleName = uLocaleInstance.getDisplayName(availableId, nameType, date);
+            String localeName = localeInstance.getDisplayName(availableId, nameType, date);
+            assertEquals("Id: " + availableId, uLocaleName, localeName);
+        }
+    }
+}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/util/CurrencyTest.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/util/CurrencyTest.java
new file mode 100644
index 0000000..26f530f
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/util/CurrencyTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.icu.cts.coverage.util;
+
+import android.icu.util.Currency;
+import android.icu.util.ULocale;
+import java.util.Locale;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Extra tests to improve CTS Test Coverage.
+ */
+@RunWith(JUnit4.class)
+public class CurrencyTest {
+
+    @Test
+    public void testGetName_Locale_Int_String_BooleanArray() {
+        Currency currency = Currency.getInstance(ULocale.CHINA);
+        boolean[] isChoiceFormat = new boolean[1];
+        int nameStyle = Currency.LONG_NAME;
+        String pluralCount = "";
+        String ulocaleName =
+                currency.getName(ULocale.CANADA, nameStyle, pluralCount, isChoiceFormat);
+        assertEquals("Chinese Yuan", ulocaleName);
+        String localeName = currency.getName(Locale.CANADA, nameStyle, pluralCount, isChoiceFormat);
+        assertEquals("currency name mismatch", ulocaleName, localeName);
+    }
+
+    @Test
+    public void testGetDefaultFractionDigits_CurrencyUsage() {
+        Currency currency = Currency.getInstance(ULocale.CHINA);
+        int cashFractionDigits = currency.getDefaultFractionDigits(Currency.CurrencyUsage.CASH);
+        assertEquals(2, cashFractionDigits);
+    }
+
+    @Test
+    public void testGetRoundingIncrement() {
+        Currency currency = Currency.getInstance(ULocale.JAPAN);
+        // It appears as though this always returns 0 irrespective of the currency.
+        double roundingIncrement = currency.getRoundingIncrement();
+        assertEquals(0, roundingIncrement, 0);
+    }
+
+    @Test
+    public void testGetRoundingIncrement_CurrencyUsage() {
+        Currency currency = Currency.getInstance(ULocale.JAPAN);
+        // It appears as though this always returns 0 irrespective of the currency or usage.
+        double roundingIncrement = currency.getRoundingIncrement(Currency.CurrencyUsage.CASH);
+        assertEquals(0, roundingIncrement, 0);
+    }
+}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/util/TestAll.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/util/TestAll.java
new file mode 100644
index 0000000..d1e78d2
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/util/TestAll.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.icu.cts.coverage.util;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * A suite of all the tests in this package.
+ */
+@RunWith(Suite.class)
+// Add classes in alphabetical order with a trailing comma even if it's the last entry.
+@Suite.SuiteClasses({
+        CurrencyTest.class,
+})
+public class TestAll {
+}
diff --git a/android_icu4j/runner/src/main/java/android/icu/junit/IcuTestRunnerBuilder.java b/android_icu4j/runner/src/main/java/android/icu/junit/IcuTestRunnerBuilder.java
index 5602bb8..82c3044 100644
--- a/android_icu4j/runner/src/main/java/android/icu/junit/IcuTestRunnerBuilder.java
+++ b/android_icu4j/runner/src/main/java/android/icu/junit/IcuTestRunnerBuilder.java
@@ -18,6 +18,7 @@
 
 import android.icu.dev.test.TestFmwk;
 import android.support.test.internal.util.AndroidRunnerParams;
+import org.junit.internal.builders.AnnotatedBuilder;
 import org.junit.runner.Runner;
 import org.junit.runners.model.RunnerBuilder;
 
@@ -28,8 +29,11 @@
 
     private final AndroidRunnerParams runnerParams;
 
+    private final AnnotatedBuilder annotatedBuilder;
+
     public IcuTestRunnerBuilder(AndroidRunnerParams runnerParams) {
         this.runnerParams = runnerParams;
+        annotatedBuilder = new AnnotatedBuilder(this);
     }
 
     @Override
@@ -44,6 +48,7 @@
             return new IcuTestFmwkRunner(testClass.asSubclass(TestFmwk.class), runnerParams);
         }
 
-        return null;
+        // Fallback to using the annotation builder to support the extra icu cts tests.
+        return annotatedBuilder.safeRunnerForClass(testClass);
     }
 }