summaryrefslogtreecommitdiff
path: root/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2016-03-22 14:56:26 +0000
committerPaul Duffin <paulduffin@google.com>2016-03-22 14:56:26 +0000
commitc92a5d28a28bee7a4d55423e0a2a48ea3c6fc007 (patch)
tree624fb03e128221bf9442e517885ac4d3c3777d43 /android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage
parent11bc9330131107580b9cf84037eee279b5b3dfd2 (diff)
downloadicu-c92a5d28a28bee7a4d55423e0a2a48ea3c6fc007.tar.gz
Added tests for uncovered UCharacter methods.
Bug: 22023363 Change-Id: Id1412232b35dda3ea9c96b0d6fee4ac89335753f
Diffstat (limited to 'android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage')
-rw-r--r--android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/lang/UCharacterTest.java28
-rw-r--r--android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/rules/ULocaleDefault.java35
-rw-r--r--android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/rules/ULocaleDefaultRule.java54
3 files changed, 117 insertions, 0 deletions
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
index f821e5a8a..0f24eaf06 100644
--- 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
@@ -15,7 +15,11 @@
*/
package android.icu.cts.coverage.lang;
+import android.icu.cts.coverage.rules.ULocaleDefault;
+import android.icu.cts.coverage.rules.ULocaleDefaultRule;
import android.icu.lang.UCharacter;
+import java.util.Locale;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -28,6 +32,9 @@ import static org.junit.Assert.assertEquals;
@RunWith(JUnit4.class)
public class UCharacterTest {
+ @Rule
+ public ULocaleDefaultRule uLocaleDefaultRule = new ULocaleDefaultRule();
+
@Test
public void testNameAliasing() {
int input = '\u01a2';
@@ -36,4 +43,25 @@ public class UCharacterTest {
int output = UCharacter.getCharFromNameAlias(alias);
assertEquals("alias for '" + input + "'", input, output);
}
+
+ @Test
+ public void testToTitleCase_Locale_String_BreakIterator_I() {
+ String titleCase = UCharacter.toTitleCase(Locale.forLanguageTag("nl"), "ijsland", null,
+ UCharacter.FOLD_CASE_DEFAULT);
+ assertEquals("IJsland", titleCase);
+ }
+
+ @ULocaleDefault(languageTag = "nl")
+ @Test
+ public void testToTitleCase_String_BreakIterator_nl() {
+ String titleCase = UCharacter.toTitleCase("ijsland", null);
+ assertEquals("IJsland", titleCase);
+ }
+
+ @ULocaleDefault(languageTag = "en")
+ @Test
+ public void testToTitleCase_String_BreakIterator_en() {
+ String titleCase = UCharacter.toTitleCase("ijsland", null);
+ assertEquals("Ijsland", titleCase);
+ }
}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/rules/ULocaleDefault.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/rules/ULocaleDefault.java
new file mode 100644
index 000000000..fc7187996
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/rules/ULocaleDefault.java
@@ -0,0 +1,35 @@
+/*
+ * 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.rules;
+
+import android.icu.util.ULocale;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Mark a test method that requires a new default {@link ULocale}
+ *
+ * <p>Sets the default to the {@link ULocale} obtained by calling
+ * {@link ULocale#forLanguageTag(String)} with the value returned from {@link #languageTag()}
+ * before executing the method and restores the previous default afterwards.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.METHOD})
+public @interface ULocaleDefault {
+ String languageTag();
+}
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/rules/ULocaleDefaultRule.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/rules/ULocaleDefaultRule.java
new file mode 100644
index 000000000..72b2d69f6
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/rules/ULocaleDefaultRule.java
@@ -0,0 +1,54 @@
+/*
+ * 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.rules;
+
+import android.icu.util.ULocale;
+import org.junit.rules.MethodRule;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+/**
+ * Add this as a rule to a JUnit 4 class to support switching the {@link ULocale#getDefault()} for
+ * the duration of the test method.
+ *
+ * <p>Only affects test methods that are annotated with {@link ULocaleDefault}.
+ *
+ * @see ULocaleDefault
+ */
+@SuppressWarnings("deprecation")
+public class ULocaleDefaultRule implements MethodRule {
+
+ @Override
+ public Statement apply(final Statement base, FrameworkMethod method, Object target) {
+ final ULocaleDefault annotation = method.getAnnotation(ULocaleDefault.class);
+ if (annotation == null) {
+ return base;
+ } else {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ ULocale previousDefault = ULocale.getDefault();
+ try {
+ ULocale.setDefault(ULocale.forLanguageTag(annotation.languageTag()));
+ base.evaluate();
+ } finally {
+ ULocale.setDefault(previousDefault);
+ }
+ }
+ };
+ }
+ }
+}