Merge "Rewrite testGetFirstRowLong/Int"
This commit is contained in:
commit
09ea19f184
|
@ -16,12 +16,13 @@
|
||||||
|
|
||||||
package com.android.email;
|
package com.android.email;
|
||||||
|
|
||||||
import com.android.email.provider.EmailProvider;
|
import com.android.email.provider.EmailContent;
|
||||||
import com.android.email.provider.ProviderTestUtils;
|
|
||||||
import com.android.email.provider.EmailContent.Account;
|
import com.android.email.provider.EmailContent.Account;
|
||||||
import com.android.email.provider.EmailContent.Attachment;
|
import com.android.email.provider.EmailContent.Attachment;
|
||||||
import com.android.email.provider.EmailContent.Mailbox;
|
import com.android.email.provider.EmailContent.Mailbox;
|
||||||
import com.android.email.provider.EmailContent.Message;
|
import com.android.email.provider.EmailContent.Message;
|
||||||
|
import com.android.email.provider.EmailProvider;
|
||||||
|
import com.android.email.provider.ProviderTestUtils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.test.ProviderTestCase2;
|
import android.test.ProviderTestCase2;
|
||||||
|
@ -118,4 +119,70 @@ public class UtilityMediumTests extends ProviderTestCase2<EmailProvider> {
|
||||||
// Now, this should return true
|
// Now, this should return true
|
||||||
assertTrue(Utility.attachmentExists(mMockContext, attachment));
|
assertTrue(Utility.attachmentExists(mMockContext, attachment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetFirstRowLong() {
|
||||||
|
Account account1 = ProviderTestUtils.setupAccount("1", true, mMockContext);
|
||||||
|
Account account2 = ProviderTestUtils.setupAccount("X1", true, mMockContext);
|
||||||
|
Account account3 = ProviderTestUtils.setupAccount("X2", true, mMockContext);
|
||||||
|
|
||||||
|
// case 1. Account found
|
||||||
|
assertEquals((Long) account2.mId, Utility.getFirstRowLong(
|
||||||
|
mMockContext, Account.CONTENT_URI, EmailContent.ID_PROJECTION,
|
||||||
|
Account.DISPLAY_NAME + " like :1", new String[] {"X%"},
|
||||||
|
Account.DISPLAY_NAME,
|
||||||
|
EmailContent.ID_PROJECTION_COLUMN));
|
||||||
|
// different sort order
|
||||||
|
assertEquals((Long) account3.mId, Utility.getFirstRowLong(
|
||||||
|
mMockContext, Account.CONTENT_URI, EmailContent.ID_PROJECTION,
|
||||||
|
Account.DISPLAY_NAME + " like :1", new String[] {"X%"},
|
||||||
|
Account.DISPLAY_NAME + " desc",
|
||||||
|
EmailContent.ID_PROJECTION_COLUMN));
|
||||||
|
|
||||||
|
// case 2. no row found
|
||||||
|
assertEquals(null, Utility.getFirstRowLong(
|
||||||
|
mMockContext, Account.CONTENT_URI, EmailContent.ID_PROJECTION,
|
||||||
|
Account.DISPLAY_NAME + " like :1", new String[] {"NO SUCH ACCOUNT"},
|
||||||
|
null,
|
||||||
|
EmailContent.ID_PROJECTION_COLUMN));
|
||||||
|
|
||||||
|
// case 3. no row found with default value
|
||||||
|
assertEquals((Long) (-1L), Utility.getFirstRowLong(
|
||||||
|
mMockContext, Account.CONTENT_URI, EmailContent.ID_PROJECTION,
|
||||||
|
Account.DISPLAY_NAME + " like :1", new String[] {"NO SUCH ACCOUNT"},
|
||||||
|
null,
|
||||||
|
EmailContent.ID_PROJECTION_COLUMN, -1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFirstRowInt() {
|
||||||
|
Account account1 = ProviderTestUtils.setupAccount("1", true, mMockContext);
|
||||||
|
Account account2 = ProviderTestUtils.setupAccount("X1", true, mMockContext);
|
||||||
|
Account account3 = ProviderTestUtils.setupAccount("X2", true, mMockContext);
|
||||||
|
|
||||||
|
// case 1. Account found
|
||||||
|
assertEquals((Integer)(int) account2.mId, Utility.getFirstRowInt(
|
||||||
|
mMockContext, Account.CONTENT_URI, EmailContent.ID_PROJECTION,
|
||||||
|
Account.DISPLAY_NAME + " like :1", new String[] {"X%"},
|
||||||
|
Account.DISPLAY_NAME,
|
||||||
|
EmailContent.ID_PROJECTION_COLUMN));
|
||||||
|
// different sort order
|
||||||
|
assertEquals((Integer)(int) account3.mId, Utility.getFirstRowInt(
|
||||||
|
mMockContext, Account.CONTENT_URI, EmailContent.ID_PROJECTION,
|
||||||
|
Account.DISPLAY_NAME + " like :1", new String[] {"X%"},
|
||||||
|
Account.DISPLAY_NAME + " desc",
|
||||||
|
EmailContent.ID_PROJECTION_COLUMN));
|
||||||
|
|
||||||
|
// case 2. no row found
|
||||||
|
assertEquals(null, Utility.getFirstRowInt(
|
||||||
|
mMockContext, Account.CONTENT_URI, EmailContent.ID_PROJECTION,
|
||||||
|
Account.DISPLAY_NAME + " like :1", new String[] {"NO SUCH ACCOUNT"},
|
||||||
|
null,
|
||||||
|
EmailContent.ID_PROJECTION_COLUMN));
|
||||||
|
|
||||||
|
// case 3. no row found with default value
|
||||||
|
assertEquals((Integer) (-1), Utility.getFirstRowInt(
|
||||||
|
mMockContext, Account.CONTENT_URI, EmailContent.ID_PROJECTION,
|
||||||
|
Account.DISPLAY_NAME + " like :1", new String[] {"NO SUCH ACCOUNT"},
|
||||||
|
null,
|
||||||
|
EmailContent.ID_PROJECTION_COLUMN, -1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,108 +356,6 @@ public class UtilityUnitTests extends AndroidTestCase {
|
||||||
assertTrue(Utility.isPortFieldValid(view));
|
assertTrue(Utility.isPortFieldValid(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFirstRowLong() {
|
|
||||||
DBTestHelper.MyContext context = new DBTestHelper.MyContext();
|
|
||||||
DBTestHelper.MyProvider provider = context.getMyProvider();
|
|
||||||
|
|
||||||
// Case 1: Row found
|
|
||||||
DBTestHelper.EasyMockCursor cursor = new DBTestHelper.EasyMockCursor(1) {
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLong(int index) {
|
|
||||||
assertEquals(1, index);
|
|
||||||
return 100;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
provider.mQueryPresetResult = cursor;
|
|
||||||
|
|
||||||
Long actual = Utility.getFirstRowLong(context, Account.CONTENT_URI,
|
|
||||||
new String[] {"p"}, "se", new String[] {"sa"}, "so", 1);
|
|
||||||
assertEquals(Long.valueOf(100), actual);
|
|
||||||
|
|
||||||
MoreAsserts.assertEquals(new String[] {"p"}, provider.mPassedProjection);
|
|
||||||
assertEquals("se", provider.mPassedSelection);
|
|
||||||
MoreAsserts.assertEquals(new String[] {"sa"}, provider.mPassedSelectionArgs);
|
|
||||||
assertEquals("so", provider.mPassedSortOrder);
|
|
||||||
|
|
||||||
assertTrue(cursor.mClosed);
|
|
||||||
|
|
||||||
// Case 2: No row found
|
|
||||||
cursor = new DBTestHelper.EasyMockCursor(0) {
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
provider.mQueryPresetResult = cursor;
|
|
||||||
|
|
||||||
actual = Utility.getFirstRowLong(context, Account.CONTENT_URI, new String[] {"p"},
|
|
||||||
null, null, null, 0);
|
|
||||||
assertEquals(null, actual);
|
|
||||||
assertTrue(cursor.mClosed);
|
|
||||||
|
|
||||||
// Test with a default value.
|
|
||||||
actual = Utility.getFirstRowLong(context, Account.CONTENT_URI, new String[] {"p"},
|
|
||||||
null, null, null, 0, Long.valueOf(-1));
|
|
||||||
assertEquals(Long.valueOf(-1), actual);
|
|
||||||
assertTrue(cursor.mClosed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetFirstRowInt() {
|
|
||||||
DBTestHelper.MyContext context = new DBTestHelper.MyContext();
|
|
||||||
DBTestHelper.MyProvider provider = context.getMyProvider();
|
|
||||||
|
|
||||||
// Case 1: Row found
|
|
||||||
DBTestHelper.EasyMockCursor cursor = new DBTestHelper.EasyMockCursor(1) {
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLong(int index) {
|
|
||||||
assertEquals(1, index);
|
|
||||||
return 100;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
provider.mQueryPresetResult = cursor;
|
|
||||||
|
|
||||||
Integer actual = Utility.getFirstRowInt(context, Account.CONTENT_URI,
|
|
||||||
new String[] {"p"}, "se", new String[] {"sa"}, "so", 1);
|
|
||||||
assertEquals(Integer.valueOf(100), actual);
|
|
||||||
|
|
||||||
MoreAsserts.assertEquals(new String[] {"p"}, provider.mPassedProjection);
|
|
||||||
assertEquals("se", provider.mPassedSelection);
|
|
||||||
MoreAsserts.assertEquals(new String[] {"sa"}, provider.mPassedSelectionArgs);
|
|
||||||
assertEquals("so", provider.mPassedSortOrder);
|
|
||||||
|
|
||||||
assertTrue(cursor.mClosed);
|
|
||||||
|
|
||||||
// Case 2: No row found
|
|
||||||
cursor = new DBTestHelper.EasyMockCursor(0) {
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
provider.mQueryPresetResult = cursor;
|
|
||||||
|
|
||||||
actual = Utility.getFirstRowInt(context, Account.CONTENT_URI, new String[] {"p"},
|
|
||||||
null, null, null, 0);
|
|
||||||
assertEquals(null, actual);
|
|
||||||
assertTrue(cursor.mClosed);
|
|
||||||
|
|
||||||
// Test with a default value.
|
|
||||||
actual = Utility.getFirstRowInt(context, Account.CONTENT_URI, new String[] {"p"},
|
|
||||||
null, null, null, 0, Integer.valueOf(-1));
|
|
||||||
assertEquals(Integer.valueOf(-1), actual);
|
|
||||||
assertTrue(cursor.mClosed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testListStateSaver() {
|
public void testListStateSaver() {
|
||||||
final String BUNDLE_KEY = "a";
|
final String BUNDLE_KEY = "a";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue