Home | History | Annotate | Download | only in provider
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.emailcommon.provider;
     18 
     19 import android.content.ContentUris;
     20 import android.content.ContentValues;
     21 import android.content.Context;
     22 import android.net.Uri;
     23 import android.os.Parcel;
     24 import android.test.MoreAsserts;
     25 import android.test.ProviderTestCase2;
     26 import android.test.suitebuilder.annotation.SmallTest;
     27 import android.test.suitebuilder.annotation.Suppress;
     28 
     29 import com.android.email.provider.ContentCache;
     30 import com.android.email.provider.EmailProvider;
     31 import com.android.email.provider.ProviderTestUtils;
     32 import com.android.emailcommon.provider.EmailContent.MailboxColumns;
     33 import com.android.emailcommon.provider.EmailContent.Message;
     34 import com.android.emailcommon.provider.EmailContent.MessageColumns;
     35 import com.android.emailcommon.utility.Utility;
     36 
     37 import java.util.Arrays;
     38 
     39 /**
     40  * Unit tests for the Mailbox inner class.
     41  * These tests must be locally complete - no server(s) required.
     42  */
     43 @Suppress
     44 @SmallTest
     45 public class MailboxTests extends ProviderTestCase2<EmailProvider> {
     46     private static final String TEST_DISPLAY_NAME = "display-name";
     47     private static final String TEST_PARENT_SERVER_ID = "parent-server-id";
     48     private static final String TEST_SERVER_ID = "server-id";
     49     private static final String TEST_SYNC_KEY = "sync-key";
     50     private static final String TEST_SYNC_STATUS = "sync-status";
     51 
     52     private Context mMockContext;
     53     private EmailProvider mProvider;
     54 
     55     public MailboxTests() {
     56         super(EmailProvider.class, EmailContent.AUTHORITY);
     57     }
     58 
     59     @Override
     60     public void setUp() throws Exception {
     61         super.setUp();
     62         mMockContext = getMockContext();
     63         mProvider = getProvider();
     64         // Invalidate all caches, since we reset the database for each test
     65         ContentCache.invalidateAllCaches();
     66     }
     67 
     68     //////////////////////////////////////////////////////////
     69     ////// Utility methods
     70     //////////////////////////////////////////////////////////
     71 
     72     /** Returns the number of messages in a mailbox. */
     73     private int getMessageCount(long mailboxId) {
     74         return Utility.getFirstRowInt(mMockContext,
     75                 ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId),
     76                 new String[] {MailboxColumns.MESSAGE_COUNT}, null, null, null, 0);
     77     }
     78 
     79     /** Creates a new message. */
     80     private static Message createMessage(Context c, Mailbox b, boolean starred, boolean read,
     81             int flagLoaded) {
     82         Message message = ProviderTestUtils.setupMessage(
     83                 "1", b.mAccountKey, b.mId, true, false, c, starred, read);
     84         message.mFlagLoaded = flagLoaded;
     85         message.save(c);
     86         return message;
     87     }
     88 
     89     //////////////////////////////////////////////////////////
     90     ////// The tests
     91     //////////////////////////////////////////////////////////
     92 
     93     /**
     94      * Test simple mailbox save/retrieve
     95      */
     96     public void testSave() {
     97         final Context c = mMockContext;
     98 
     99         Account account1 = ProviderTestUtils.setupAccount("mailbox-save", true, c);
    100         long account1Id = account1.mId;
    101         Mailbox box1 = ProviderTestUtils.setupMailbox("box1", account1Id, true, c);
    102         long box1Id = box1.mId;
    103 
    104         Mailbox box2 = Mailbox.restoreMailboxWithId(c, box1Id);
    105 
    106         ProviderTestUtils.assertMailboxEqual("testMailboxSave", box1, box2);
    107     }
    108 
    109     /**
    110      * Test delete mailbox
    111      */
    112     public void testDelete() {
    113         final Context c = mMockContext;
    114 
    115         Account account1 = ProviderTestUtils.setupAccount("mailbox-delete", true, c);
    116         long account1Id = account1.mId;
    117         Mailbox box1 = ProviderTestUtils.setupMailbox("box1", account1Id, true, c);
    118         long box1Id = box1.mId;
    119         Mailbox box2 = ProviderTestUtils.setupMailbox("box2", account1Id, true, c);
    120         long box2Id = box2.mId;
    121 
    122         String selection = EmailContent.MailboxColumns.ACCOUNT_KEY + "=?";
    123         String[] selArgs = new String[] { String.valueOf(account1Id) };
    124 
    125         // make sure there are two mailboxes
    126         int numBoxes = EmailContent.count(c, Mailbox.CONTENT_URI, selection, selArgs);
    127         assertEquals(2, numBoxes);
    128 
    129         // now delete one of them
    130         Uri uri = ContentUris.withAppendedId(Mailbox.CONTENT_URI, box1Id);
    131         c.getContentResolver().delete(uri, null, null);
    132 
    133         // make sure there's only one mailbox now
    134         numBoxes = EmailContent.count(c, Mailbox.CONTENT_URI, selection, selArgs);
    135         assertEquals(1, numBoxes);
    136 
    137         // now delete the other one
    138         uri = ContentUris.withAppendedId(Mailbox.CONTENT_URI, box2Id);
    139         c.getContentResolver().delete(uri, null, null);
    140 
    141         // make sure there are no mailboxes now
    142         numBoxes = EmailContent.count(c, Mailbox.CONTENT_URI, selection, selArgs);
    143         assertEquals(0, numBoxes);
    144     }
    145 
    146     public void testGetMailboxType() {
    147         final Context c = mMockContext;
    148 
    149         Account a = ProviderTestUtils.setupAccount("acct1", true, c);
    150         Mailbox bi = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_INBOX);
    151         Mailbox bm = ProviderTestUtils.setupMailbox("b2", a.mId, true, c, Mailbox.TYPE_MAIL);
    152 
    153         assertEquals(Mailbox.TYPE_INBOX, Mailbox.getMailboxType(c, bi.mId));
    154         assertEquals(Mailbox.TYPE_MAIL, Mailbox.getMailboxType(c, bm.mId));
    155         assertEquals(-1, Mailbox.getMailboxType(c, 999999)); // mailbox not found
    156     }
    157 
    158     public void testGetDisplayName() {
    159         final Context c = mMockContext;
    160 
    161         Account a = ProviderTestUtils.setupAccount("acct1", true, c);
    162         Mailbox bi = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_INBOX);
    163         Mailbox bm = ProviderTestUtils.setupMailbox("b2", a.mId, true, c, Mailbox.TYPE_MAIL);
    164 
    165         assertEquals("b1", Mailbox.getDisplayName(c, bi.mId));
    166         assertEquals("b2", Mailbox.getDisplayName(c, bm.mId));
    167         assertEquals(null, Mailbox.getDisplayName(c, 999999)); // mailbox not found
    168     }
    169 
    170     public void testIsRefreshable() {
    171         final Context c = mMockContext;
    172 
    173         Account a = ProviderTestUtils.setupAccount("acct1", true, c);
    174         Mailbox bi = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_INBOX);
    175         Mailbox bm = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_MAIL);
    176         Mailbox bd = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_DRAFTS);
    177         Mailbox bo = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_OUTBOX);
    178 
    179         assertTrue(Mailbox.isRefreshable(c, bi.mId));
    180         assertTrue(Mailbox.isRefreshable(c, bm.mId));
    181         assertFalse(Mailbox.isRefreshable(c, bd.mId));
    182         assertFalse(Mailbox.isRefreshable(c, bo.mId));
    183 
    184         // No such mailbox
    185         assertFalse(Mailbox.isRefreshable(c, 9999999));
    186 
    187         // Magic mailboxes can't be refreshed.
    188         assertFalse(Mailbox.isRefreshable(c, Mailbox.QUERY_ALL_DRAFTS));
    189         assertFalse(Mailbox.isRefreshable(c, Mailbox.QUERY_ALL_INBOXES));
    190     }
    191 
    192     public void testCanMoveFrom() {
    193         final Context c = mMockContext;
    194 
    195         Account a = ProviderTestUtils.setupAccount("acct1", true, c);
    196         Mailbox bi = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_INBOX);
    197         Mailbox bm = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_MAIL);
    198         Mailbox bd = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_DRAFTS);
    199         Mailbox bo = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_OUTBOX);
    200 
    201         assertTrue(bi.canHaveMessagesMoved());
    202         assertTrue(bm.canHaveMessagesMoved());
    203         assertFalse(bd.canHaveMessagesMoved());
    204         assertFalse(bo.canHaveMessagesMoved());
    205     }
    206 
    207     public void testGetMailboxForMessageId() {
    208         final Context c = mMockContext;
    209         Mailbox b1 = ProviderTestUtils.setupMailbox("box1", 1, true, c, Mailbox.TYPE_MAIL);
    210         Mailbox b2 = ProviderTestUtils.setupMailbox("box2", 1, true, c, Mailbox.TYPE_MAIL);
    211         Message m1 = ProviderTestUtils.setupMessage("1", b1.mAccountKey, b1.mId,
    212                 true, true, c, false, false);
    213         Message m2 = ProviderTestUtils.setupMessage("1", b2.mAccountKey, b2.mId,
    214                 true, true, c, false, false);
    215         ProviderTestUtils.assertMailboxEqual("x", b1, Mailbox.getMailboxForMessageId(c, m1.mId));
    216         ProviderTestUtils.assertMailboxEqual("x", b2, Mailbox.getMailboxForMessageId(c, m2.mId));
    217     }
    218 
    219     public void testRestoreMailboxWithId() {
    220         final Context c = mMockContext;
    221         Mailbox testMailbox;
    222 
    223         testMailbox = ProviderTestUtils.setupMailbox("box1", 1, true, c, Mailbox.TYPE_MAIL);
    224         ProviderTestUtils.assertMailboxEqual(
    225                 "x", testMailbox, Mailbox.restoreMailboxWithId(c, testMailbox.mId));
    226         testMailbox = ProviderTestUtils.setupMailbox("box2", 1, true, c, Mailbox.TYPE_MAIL);
    227         ProviderTestUtils.assertMailboxEqual(
    228                 "x", testMailbox, Mailbox.restoreMailboxWithId(c, testMailbox.mId));
    229         // Unknown IDs
    230         assertNull(Mailbox.restoreMailboxWithId(c, 8));
    231         assertNull(Mailbox.restoreMailboxWithId(c, -1));
    232         assertNull(Mailbox.restoreMailboxWithId(c, Long.MAX_VALUE));
    233     }
    234 
    235     public void testRestoreMailboxForPath() {
    236         final Context c = mMockContext;
    237         Mailbox testMailbox;
    238         testMailbox = ProviderTestUtils.setupMailbox("a/b/c/box", 1, true, c, Mailbox.TYPE_MAIL);
    239         ProviderTestUtils.assertMailboxEqual(
    240                 "x", testMailbox, Mailbox.restoreMailboxForPath(c, 1, "a/b/c/box"));
    241         // Same name, different account; no match
    242         assertNull(Mailbox.restoreMailboxForPath(c, 2, "a/b/c/box"));
    243         // Substring; no match
    244         assertNull(Mailbox.restoreMailboxForPath(c, 1, "a/b/c"));
    245         // Wild cards not supported; no match
    246         assertNull(Mailbox.restoreMailboxForPath(c, 1, "a/b/c/%"));
    247     }
    248 
    249     public void testFindMailboxOfType() {
    250         final Context context = mMockContext;
    251 
    252         // Create two accounts and a variety of mailbox types
    253         Account acct1 = ProviderTestUtils.setupAccount("acct1", true, context);
    254         Mailbox acct1Inbox =
    255             ProviderTestUtils.setupMailbox("Inbox1", acct1.mId, true, context, Mailbox.TYPE_INBOX);
    256         Mailbox acct1Calendar =
    257             ProviderTestUtils.setupMailbox("Cal1", acct1.mId, true, context, Mailbox.TYPE_CALENDAR);
    258         Mailbox acct1Contacts =
    259             ProviderTestUtils.setupMailbox("Con1", acct1.mId, true, context, Mailbox.TYPE_CONTACTS);
    260         Account acct2 = ProviderTestUtils.setupAccount("acct1", true, context);
    261         Mailbox acct2Inbox =
    262             ProviderTestUtils.setupMailbox("Inbox2", acct2.mId, true, context, Mailbox.TYPE_INBOX);
    263         Mailbox acct2Calendar =
    264             ProviderTestUtils.setupMailbox("Cal2", acct2.mId, true, context, Mailbox.TYPE_CALENDAR);
    265         Mailbox acct2Contacts =
    266             ProviderTestUtils.setupMailbox("Con2", acct2.mId, true, context, Mailbox.TYPE_CONTACTS);
    267 
    268         // Check that we can find them by type
    269         assertEquals(acct1Inbox.mId,
    270                 Mailbox.findMailboxOfType(context, acct1.mId, Mailbox.TYPE_INBOX));
    271         assertEquals(acct2Inbox.mId,
    272                 Mailbox.findMailboxOfType(context, acct2.mId, Mailbox.TYPE_INBOX));
    273         assertEquals(acct1Calendar.mId,
    274                 Mailbox.findMailboxOfType(context, acct1.mId, Mailbox.TYPE_CALENDAR));
    275         assertEquals(acct2Calendar.mId,
    276                 Mailbox.findMailboxOfType(context, acct2.mId, Mailbox.TYPE_CALENDAR));
    277         assertEquals(acct1Contacts.mId,
    278                 Mailbox.findMailboxOfType(context, acct1.mId, Mailbox.TYPE_CONTACTS));
    279         assertEquals(acct2Contacts.mId,
    280                 Mailbox.findMailboxOfType(context, acct2.mId, Mailbox.TYPE_CONTACTS));
    281 
    282         // Check that nonexistent mailboxes are not returned
    283         assertEquals(Mailbox.NO_MAILBOX,
    284                 Mailbox.findMailboxOfType(context, acct1.mId, Mailbox.TYPE_DRAFTS));
    285         assertEquals(Mailbox.NO_MAILBOX,
    286                 Mailbox.findMailboxOfType(context, acct1.mId, Mailbox.TYPE_OUTBOX));
    287 
    288         // delete account 1 and confirm no mailboxes are returned
    289         context.getContentResolver().delete(
    290                 ContentUris.withAppendedId(Account.CONTENT_URI, acct1.mId), null, null);
    291         assertEquals(Mailbox.NO_MAILBOX,
    292                 Mailbox.findMailboxOfType(context, acct1.mId, Mailbox.TYPE_INBOX));
    293         assertEquals(Mailbox.NO_MAILBOX,
    294                 Mailbox.findMailboxOfType(context, acct1.mId, Mailbox.TYPE_CALENDAR));
    295         assertEquals(Mailbox.NO_MAILBOX,
    296                 Mailbox.findMailboxOfType(context, acct1.mId, Mailbox.TYPE_CONTACTS));
    297     }
    298 
    299     public void testRestoreMailboxOfType() {
    300         final Context context = getMockContext();
    301 
    302         // Create two accounts and a variety of mailbox types
    303         Account acct1 = ProviderTestUtils.setupAccount("acct1", true, context);
    304         Mailbox acct1Inbox =
    305             ProviderTestUtils.setupMailbox("Inbox1", acct1.mId, true, context, Mailbox.TYPE_INBOX);
    306         Mailbox acct1Calendar =
    307             ProviderTestUtils.setupMailbox("Cal1", acct1.mId, true, context, Mailbox.TYPE_CALENDAR);
    308         Mailbox acct1Contacts =
    309             ProviderTestUtils.setupMailbox("Con1", acct1.mId, true, context, Mailbox.TYPE_CONTACTS);
    310         Account acct2 =ProviderTestUtils.setupAccount("acct1", true, context);
    311         Mailbox acct2Inbox =
    312             ProviderTestUtils.setupMailbox("Inbox2", acct2.mId, true, context, Mailbox.TYPE_INBOX);
    313         Mailbox acct2Calendar =
    314             ProviderTestUtils.setupMailbox("Cal2", acct2.mId, true, context, Mailbox.TYPE_CALENDAR);
    315         Mailbox acct2Contacts =
    316             ProviderTestUtils.setupMailbox("Con2", acct2.mId, true, context, Mailbox.TYPE_CONTACTS);
    317 
    318         // Check that we can find them by type
    319         ProviderTestUtils.assertMailboxEqual("testRestoreMailboxOfType", acct1Inbox,
    320                 Mailbox.restoreMailboxOfType(context, acct1.mId, Mailbox.TYPE_INBOX));
    321         ProviderTestUtils.assertMailboxEqual("testRestoreMailboxOfType", acct2Inbox,
    322                 Mailbox.restoreMailboxOfType(context, acct2.mId, Mailbox.TYPE_INBOX));
    323         ProviderTestUtils.assertMailboxEqual("testRestoreMailboxOfType", acct1Calendar,
    324                 Mailbox.restoreMailboxOfType(context, acct1.mId, Mailbox.TYPE_CALENDAR));
    325         ProviderTestUtils.assertMailboxEqual("testRestoreMailboxOfType", acct2Calendar,
    326                 Mailbox.restoreMailboxOfType(context, acct2.mId, Mailbox.TYPE_CALENDAR));
    327         ProviderTestUtils.assertMailboxEqual("testRestoreMailboxOfType", acct1Contacts,
    328                 Mailbox.restoreMailboxOfType(context, acct1.mId, Mailbox.TYPE_CONTACTS));
    329         ProviderTestUtils.assertMailboxEqual("testRestoreMailboxOfType", acct2Contacts,
    330                 Mailbox.restoreMailboxOfType(context, acct2.mId, Mailbox.TYPE_CONTACTS));
    331     }
    332 
    333     /**
    334      * Test for the message count triggers (insert/delete/move mailbox), and also
    335      * {@link EmailProvider#recalculateMessageCount}.
    336      *
    337      * It also covers:
    338      * - {@link Message#getFavoriteMessageCount(Context)}
    339      * - {@link Message#getFavoriteMessageCount(Context, long)}
    340      */
    341     public void testMessageCount() {
    342         final Context c = mMockContext;
    343 
    344         // Create 2 accounts
    345         Account a1 = ProviderTestUtils.setupAccount("holdflag-1", true, c);
    346         Account a2 = ProviderTestUtils.setupAccount("holdflag-2", true, c);
    347 
    348         // Create 2 mailboxes for each account
    349         Mailbox b1 = ProviderTestUtils.setupMailbox("box1", a1.mId, true, c, Mailbox.TYPE_INBOX);
    350         Mailbox b2 = ProviderTestUtils.setupMailbox("box2", a1.mId, true, c, Mailbox.TYPE_OUTBOX);
    351         Mailbox b3 = ProviderTestUtils.setupMailbox("box3", a2.mId, true, c, Mailbox.TYPE_INBOX);
    352         Mailbox b4 = ProviderTestUtils.setupMailbox("box4", a2.mId, true, c, Mailbox.TYPE_OUTBOX);
    353         Mailbox bt = ProviderTestUtils.setupMailbox("boxT", a2.mId, true, c, Mailbox.TYPE_TRASH);
    354 
    355         // 0. Check the initial values, just in case.
    356 
    357         assertEquals(0, getMessageCount(b1.mId));
    358         assertEquals(0, getMessageCount(b2.mId));
    359         assertEquals(0, getMessageCount(b3.mId));
    360         assertEquals(0, getMessageCount(b4.mId));
    361         assertEquals(0, getMessageCount(bt.mId));
    362 
    363         assertEquals(0, Message.getFavoriteMessageCount(c));
    364         assertEquals(0, Message.getFavoriteMessageCount(c, a1.mId));
    365         assertEquals(0, Message.getFavoriteMessageCount(c, a2.mId));
    366 
    367         // 1. Test for insert triggers.
    368 
    369         // Create some messages
    370         // b1 (account 1, inbox): 1 message, including 1 starred
    371         Message m11 = createMessage(c, b1, true, false, Message.FLAG_LOADED_COMPLETE);
    372 
    373         // b2 (account 1, outbox): 2 message, including 1 starred
    374         Message m21 = createMessage(c, b2, false, false, Message.FLAG_LOADED_COMPLETE);
    375         Message m22 = createMessage(c, b2, true, true, Message.FLAG_LOADED_COMPLETE);
    376 
    377         // b3 (account 2, inbox): 3 message, including 1 starred
    378         Message m31 = createMessage(c, b3, false, false, Message.FLAG_LOADED_COMPLETE);
    379         Message m32 = createMessage(c, b3, false, false, Message.FLAG_LOADED_COMPLETE);
    380         Message m33 = createMessage(c, b3, true, true, Message.FLAG_LOADED_COMPLETE);
    381 
    382         // b4 (account 2, outbox) has no messages.
    383 
    384         // bt (account 2, trash) has 3 messages, including 2 starred
    385         Message mt1 = createMessage(c, bt, true, false, Message.FLAG_LOADED_COMPLETE);
    386         Message mt2 = createMessage(c, bt, true, false, Message.FLAG_LOADED_COMPLETE);
    387         Message mt3 = createMessage(c, bt, false, false, Message.FLAG_LOADED_COMPLETE);
    388 
    389         // Check message counts
    390         assertEquals(1, getMessageCount(b1.mId));
    391         assertEquals(2, getMessageCount(b2.mId));
    392         assertEquals(3, getMessageCount(b3.mId));
    393         assertEquals(0, getMessageCount(b4.mId));
    394         assertEquals(3, getMessageCount(bt.mId));
    395 
    396         // Check the simple counting methods.
    397         assertEquals(3, Message.getFavoriteMessageCount(c)); // excludes starred in trash
    398         assertEquals(2, Message.getFavoriteMessageCount(c, a1.mId));
    399         assertEquals(1, Message.getFavoriteMessageCount(c, a2.mId)); // excludes starred in trash
    400 
    401         // 2. Check the "move mailbox" trigger.
    402 
    403         // Move m32 (in mailbox 3) to mailbox 4.
    404         ContentValues values = new ContentValues();
    405         values.put(MessageColumns.MAILBOX_KEY, b4.mId);
    406 
    407         getProvider().update(Message.CONTENT_URI, values, EmailContent.ID_SELECTION,
    408                 new String[] {"" + m32.mId});
    409 
    410         // Check message counts
    411         assertEquals(1, getMessageCount(b1.mId));
    412         assertEquals(2, getMessageCount(b2.mId));
    413         assertEquals(2, getMessageCount(b3.mId));
    414         assertEquals(1, getMessageCount(b4.mId));
    415 
    416         // 3. Check the delete trigger.
    417 
    418         // Delete m11 (in mailbox 1)
    419         getProvider().delete(Message.CONTENT_URI, EmailContent.ID_SELECTION,
    420                 new String[] {"" + m11.mId});
    421         // Delete m21 (in mailbox 2)
    422         getProvider().delete(Message.CONTENT_URI, EmailContent.ID_SELECTION,
    423                 new String[] {"" + m21.mId});
    424 
    425         // Check message counts
    426         assertEquals(0, getMessageCount(b1.mId));
    427         assertEquals(1, getMessageCount(b2.mId));
    428         assertEquals(2, getMessageCount(b3.mId));
    429         assertEquals(1, getMessageCount(b4.mId));
    430     }
    431 
    432     private Mailbox buildTestMailbox(String serverId) {
    433         return buildTestMailbox(serverId, null);
    434     }
    435 
    436     private Mailbox buildTestMailbox(String serverId, String name) {
    437         Mailbox testMailbox = new Mailbox();
    438         testMailbox.mServerId = serverId;
    439         testMailbox.mDisplayName = (name == null) ? TEST_DISPLAY_NAME : name;
    440         testMailbox.mParentServerId = TEST_PARENT_SERVER_ID;
    441         testMailbox.mSyncKey = TEST_SYNC_KEY;
    442         testMailbox.mSyncStatus = TEST_SYNC_STATUS;
    443         testMailbox.mAccountKey = 1L;
    444         testMailbox.mDelimiter = '/';
    445         testMailbox.mFlags = 2;
    446         testMailbox.mFlagVisible = true;
    447         testMailbox.mParentKey = 3L;
    448         testMailbox.mSyncInterval = 4;
    449         testMailbox.mSyncLookback = 5;
    450         testMailbox.mSyncTime = 6L;
    451         testMailbox.mType = 7;
    452         testMailbox.mLastTouchedTime = 10L;
    453 
    454         return testMailbox;
    455     }
    456 
    457     public void testGetHashes() {
    458         final Context c = mMockContext;
    459         Mailbox testMailbox = buildTestMailbox(TEST_SERVER_ID);
    460         testMailbox.save(c);
    461 
    462         Object[] testHash;
    463         testHash = new Object[] {
    464                 testMailbox.mId, TEST_DISPLAY_NAME, TEST_SERVER_ID,
    465                 TEST_PARENT_SERVER_ID, 1L /*mAccountKey*/, 7 /*mType */,
    466                 (int)'/' /*mDelimiter */, TEST_SYNC_KEY, 5 /*mSyncLookback*/,
    467                 4 /*mSyncInterval*/,  6L /*mSyncTime*/, true /*mFlagVisible*/, 2 /*mFlags*/,
    468                 8 /*mVisibleLimit*/, TEST_SYNC_STATUS, 3L /*mParentKey*/, 9L /*mLastSeen*/,
    469                 10L /*mLastTouchedTime*/,
    470         };
    471         MoreAsserts.assertEquals(testHash, testMailbox.getHashes());
    472 
    473         // Verify null checks happen correctly
    474         testMailbox.mDisplayName = null;
    475         testMailbox.mParentServerId = null;
    476         testMailbox.mServerId = null;
    477         testMailbox.mSyncKey = null;
    478         testMailbox.mSyncStatus = null;
    479         testMailbox.mFlagVisible = false;
    480 
    481         testHash = new Object[] {
    482                 testMailbox.mId, null /*mDisplayname*/, null /*mServerId*/,
    483                 null /*mParentServerId*/, 1L /*mAccountKey*/, 7 /*mType */,
    484                 (int)'/' /*mDelimiter */, null /*mSyncKey*/, 5 /*mSyncLookback*/,
    485                 4 /*mSyncInterval*/,  6L /*mSyncTime*/, false /*mFlagVisible*/, 2 /*mFlags*/,
    486                 8 /*mVisibleLimit*/, null /*mSyncStatus*/, 3L /*mParentKey*/, 9L /*mLastSeen*/,
    487                 10L /*mLastTouchedTime*/,
    488         };
    489         MoreAsserts.assertEquals(testHash, testMailbox.getHashes());
    490     }
    491 
    492     public void testParcelling() {
    493         Mailbox original = buildTestMailbox("serverId", "display name for mailbox");
    494 
    495         Parcel p = Parcel.obtain();
    496         original.writeToParcel(p, 0 /* flags */);
    497 
    498         // Reset.
    499         p.setDataPosition(0);
    500 
    501         Mailbox unparcelled = Mailbox.CREATOR.createFromParcel(p);
    502         MoreAsserts.assertEquals(original.getHashes(), unparcelled.getHashes());
    503 
    504         Mailbox phony = buildTestMailbox("different ID", "display name for mailbox");
    505         assertFalse(Arrays.equals(phony.getHashes(), unparcelled.getHashes()));
    506 
    507         p.recycle();
    508     }
    509 
    510     public void testParcellingWithPartialMailbox() {
    511         Mailbox unpopulated = new Mailbox();
    512         unpopulated.mDisplayName = "the only thing filled in for some reason";
    513 
    514         Parcel p = Parcel.obtain();
    515         unpopulated.writeToParcel(p, 0 /* flags */);
    516 
    517         // Reset.
    518         p.setDataPosition(0);
    519 
    520         Mailbox unparcelled = Mailbox.CREATOR.createFromParcel(p);
    521         MoreAsserts.assertEquals(unpopulated.getHashes(), unparcelled.getHashes());
    522 
    523         p.recycle();
    524     }
    525 }
    526 
    527