diff options
author | Anthony Lee <anthonylee@google.com> | 2014-02-04 13:49:37 -0800 |
---|---|---|
committer | Yu Ping Hu <yph@google.com> | 2014-03-19 23:41:30 +0000 |
commit | 674df0303129dcfa54a2cee2bf7e11195986220b (patch) | |
tree | 38993fb18f2a4028cf7f4304067d0b3f4dcebc9b /tests/src | |
parent | a5fd5a343a8698978a88c7d8907de19a07fce2ab (diff) | |
download | android_packages_apps_Exchange-674df0303129dcfa54a2cee2bf7e11195986220b.tar.gz android_packages_apps_Exchange-674df0303129dcfa54a2cee2bf7e11195986220b.tar.bz2 android_packages_apps_Exchange-674df0303129dcfa54a2cee2bf7e11195986220b.zip |
NPE fix in NameComparator when null strings are provided by the
caller. b/12894779
This is the integration of an Exchange fix from Motorola. As part
of this fix, unit tests have been introduced to verify that we
are experiencing the correct behavior. Writing these unit tests
required some factoring/unwrapped to make the code easier to test.
Change-Id: I3fe8278c56fb13e2e43f32c3eeba1cbe01ea3b8b
(cherry picked from commit 6fd3b6c35d930ee045cb6cfe3d6770d450b7b523)
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/exchange/provider/ExchangeDirectoryProviderTests.java | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/src/com/android/exchange/provider/ExchangeDirectoryProviderTests.java b/tests/src/com/android/exchange/provider/ExchangeDirectoryProviderTests.java index 64b7fa20..ff351f83 100644 --- a/tests/src/com/android/exchange/provider/ExchangeDirectoryProviderTests.java +++ b/tests/src/com/android/exchange/provider/ExchangeDirectoryProviderTests.java @@ -143,4 +143,110 @@ public class ExchangeDirectoryProviderTests extends ExchangeTestCase { assertEquals((Long)acctFoo.mId, provider.mAccountIdMap.get("foo@android.com")); assertEquals((Long)acctBar.mId, provider.mAccountIdMap.get("bar@android.com")); } + + /** + * The purpose of these next tests are to test the ExchangeDirectoryProvider. NameComparator comparison function + * and not the Collator class. This means that we can test only with Western strings. + * Note that there is a loose assumption that IDs always exist. If this is a valid + * assumption, we should enforce it in the ExchangeDirectoryProvider.GalSortKey class or in the compare function. + */ + public void testNameComparatorEqualsStringLhsIdGreater() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey("A", 2); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey("A", 1); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, 1); + } + + public void testNameComparatorEqualsStringRhsIdGreater() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey("A", 1); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey("A", 2); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, -1); + } + + public void testNameComparatorEqualsEverythingEqual() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey("A", 1); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey("A", 1); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, 0); + } + + public void testNameComparatorLhsGreaterString() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey("B", 1); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey("A", 2); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, 1); + } + + public void testNameComparatorRhsGreaterString() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey("A", 1); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey("B", 2); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, -1); + } + + public void testNameComparatorLhsNoStringLhsWins() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey(null, 2); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey("A", 1); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, 1); + } + + public void testNameComparatorLhsNoStringRhsWins() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey(null, 1); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey("A", 2); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, -1); + } + + public void testNameComparatorRhsNoStringLhsWins() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey("A", 2); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey(null, 1); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, 1); + } + + public void testNameComparatorRhsNoStringRhsWins() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey("A", 1); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey(null, 2); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, -1); + } + + public void testNameComparatorNoStringsLhsWins() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey(null, 2); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey(null, 1); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, 1); + } + + public void testNameComparatorNoStringsRhsWins() { + final ExchangeDirectoryProvider.GalSortKey lhs = new ExchangeDirectoryProvider.GalSortKey(null, 1); + final ExchangeDirectoryProvider.GalSortKey rhs = new ExchangeDirectoryProvider.GalSortKey(null, 2); + + final ExchangeDirectoryProvider. NameComparator comparator = new ExchangeDirectoryProvider. NameComparator(); + final int ret = comparator.compare(lhs, rhs); + assertEquals(ret, -1); + } + } |