aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Faden <dfaden@google.com>2014-10-28 14:22:09 -0700
committerKen Wakasa <kwakasa@google.com>2014-10-31 06:18:35 +0000
commitd443146c343fd880eb6178bae94edec0865bce62 (patch)
treecd45ad9dbf88f50cac1839705a52db4eb4f759e4 /tests
parent0cd1f222fd837179f501651256bc15b42317edd0 (diff)
downloadlatinime-d443146c343fd880eb6178bae94edec0865bce62.tar.gz
latinime-d443146c343fd880eb6178bae94edec0865bce62.tar.xz
latinime-d443146c343fd880eb6178bae94edec0865bce62.zip
Add documentation for CollectionUtils#arrayAsList
(This is a cherrypick of http://ag/576739) Also, modify the IllegalArgumentException to capture the values passed for start, end, and array.length to make debugging easier in the unlikely event that it is thrown. Add corresponding tests for the exceptions. Tested: tapas LatinImeGoogle LatinImeGoogleTests userdebug make -j30 && \ adb install -r \ out/target/product/generic/data/app/LatinImeGoogleTests/LatinImeGoogleTests.apk && \ adb install -r \ out/target/product/generic/system/app/LatinImeGoogle/LatinImeGoogle.apk && \ adb shell am instrument -w -e class \ com.android.inputmethod.latin.utils.CollectionUtilsTests \ com.google.android.inputmethod.latin.tests/android.support.test.runner.AndroidJUnitRunner Change-Id: I0c579ca4f4f2a9b2575aa6f8fa75e3ee4a21cf8a
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
index a5979c3df..dc4e2e4bb 100644
--- a/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/CollectionUtilsTests.java
@@ -29,14 +29,45 @@ import java.util.Collections;
@SmallTest
public class CollectionUtilsTests extends AndroidTestCase {
/**
+ * Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} fails as expected
+ * with some invalid inputs.
+ */
+ public void testArrayAsListFailure() {
+ final String[] array = { "0", "1" };
+ // Negative start
+ try {
+ CollectionUtils.arrayAsList(array, -1, 1);
+ fail("Failed to catch start < 0");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Invalid start: -1 end: 1 with array.length: 2", e.getMessage());
+ }
+ // start > end
+ try {
+ CollectionUtils.arrayAsList(array, 1, -1);
+ fail("Failed to catch start > end");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Invalid start: 1 end: -1 with array.length: 2", e.getMessage());
+ }
+ // end > array.length
+ try {
+ CollectionUtils.arrayAsList(array, 1, 3);
+ fail("Failed to catch end > array.length");
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Invalid start: 1 end: 3 with array.length: 2", e.getMessage());
+ }
+ }
+
+ /**
* Tests that {@link CollectionUtils#arrayAsList(Object[],int,int)} gives the expected
* results for a few valid inputs.
*/
public void testArrayAsList() {
- final String[] array = { "0", "1", "2", "3", "4" };
final ArrayList<String> empty = new ArrayList<>();
+ assertEquals(empty, CollectionUtils.arrayAsList(new String[] { }, 0, 0));
+ final String[] array = { "0", "1", "2", "3", "4" };
assertEquals(empty, CollectionUtils.arrayAsList(array, 0, 0));
assertEquals(empty, CollectionUtils.arrayAsList(array, 1, 1));
+ assertEquals(empty, CollectionUtils.arrayAsList(array, array.length, array.length));
final ArrayList<String> expected123 = new ArrayList<>(Arrays.asList("1", "2", "3"));
assertEquals(expected123, CollectionUtils.arrayAsList(array, 1, 4));
}