summaryrefslogtreecommitdiff
path: root/android_icu4j/cts-coverage/src/main/tests/android/icu/cts
diff options
context:
space:
mode:
authorJoachim Sauer <jsauer@google.com>2016-03-23 12:30:51 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-03-23 12:30:51 +0000
commit6bc23597acc2ac8ff81f0995216e222cc28b7ec2 (patch)
tree33552fe0a3771f2eb614a43872847447961672ed /android_icu4j/cts-coverage/src/main/tests/android/icu/cts
parent48f19117b2aa7c33c34372d2210259699961a3fe (diff)
parentdf947073ad7804b975610cbcd98bde07d3d5b861 (diff)
downloadicu-6bc23597acc2ac8ff81f0995216e222cc28b7ec2.tar.gz
Merge "ICU4J AlphabeticIndex tests to improve coverage." into nyc-dev
Diffstat (limited to 'android_icu4j/cts-coverage/src/main/tests/android/icu/cts')
-rw-r--r--android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/AlphabeticIndexTest.java101
-rw-r--r--android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/TestAll.java1
2 files changed, 102 insertions, 0 deletions
diff --git a/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/AlphabeticIndexTest.java b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/AlphabeticIndexTest.java
new file mode 100644
index 000000000..ed45929e5
--- /dev/null
+++ b/android_icu4j/cts-coverage/src/main/tests/android/icu/cts/coverage/text/AlphabeticIndexTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.AlphabeticIndex;
+import android.icu.util.ULocale;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.Locale;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+@RunWith(JUnit4.class)
+public class AlphabeticIndexTest {
+ @Test
+ public void testAddLabels_Locale() {
+ AlphabeticIndex<?> ulocaleIndex = new AlphabeticIndex<>(ULocale.CANADA);
+ AlphabeticIndex<?> localeIndex = new AlphabeticIndex<>(Locale.CANADA);
+
+ ulocaleIndex.addLabels(ULocale.SIMPLIFIED_CHINESE);
+ localeIndex.addLabels(Locale.SIMPLIFIED_CHINESE);
+
+ assertEquals(ulocaleIndex.getBucketLabels(), localeIndex.getBucketLabels());
+ }
+
+ @Test
+ public void testGetRecordCount_empty() {
+ assertEquals(0, new AlphabeticIndex<>(ULocale.CANADA).getRecordCount());
+ }
+
+ @Test
+ public void testGetRecordCount_withRecords() {
+ assertEquals(1, new AlphabeticIndex<>(ULocale.CANADA).addRecord("foo", null)
+ .getRecordCount());
+ }
+
+ /**
+ * Check that setUnderflowLabel/setOverflowLabel/setInflowLabel correctly influence the name of
+ * generated labels.
+ */
+ @Test
+ public void testFlowLabels() {
+ AlphabeticIndex<?> index = new AlphabeticIndex<>(ULocale.ENGLISH)
+ .addLabels(ULocale.forLanguageTag("ru"));
+ index.setUnderflowLabel("underflow");
+ index.setOverflowLabel("overflow");
+ index.setInflowLabel("inflow");
+ index.addRecord("!", null);
+ index.addRecord("\u03B1", null); // GREEK SMALL LETTER ALPHA
+ index.addRecord("\uab70", null); // CHEROKEE SMALL LETTER A
+
+
+ AlphabeticIndex.Bucket<?> underflowBucket = null;
+ AlphabeticIndex.Bucket<?> overflowBucket = null;
+ AlphabeticIndex.Bucket<?> inflowBucket = null;
+ for (AlphabeticIndex.Bucket<?> bucket : index) {
+ switch (bucket.getLabelType()) {
+ case UNDERFLOW:
+ assertNull(underflowBucket);
+ underflowBucket = bucket;
+ break;
+ case OVERFLOW:
+ assertNull(overflowBucket);
+ overflowBucket = bucket;
+ break;
+ case INFLOW:
+ assertNull(inflowBucket);
+ inflowBucket = bucket;
+ break;
+ }
+ }
+ assertNotNull(underflowBucket);
+ assertEquals("underflow", underflowBucket.getLabel());
+ assertEquals(1, underflowBucket.size());
+
+ assertNotNull(overflowBucket);
+ assertEquals("overflow", overflowBucket.getLabel());
+ assertEquals(1, overflowBucket.size());
+
+ assertNotNull(inflowBucket);
+ assertEquals("inflow", inflowBucket.getLabel());
+ assertEquals(1, inflowBucket.size());
+ }
+}
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
index 142460676..20a0e1d8b 100644
--- 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
@@ -24,6 +24,7 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
// Add classes in alphabetical order with a trailing comma even if it's the last entry.
@Suite.SuiteClasses({
+ AlphabeticIndexTest.class,
RelativeDateTimeFormatterTest.class,
TimeZoneNamesTest.class,
UnicodeSetTest.class,