Home | History | Annotate | Download | only in activity
      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.email.activity;
     18 
     19 import com.android.email.DBTestHelper;
     20 import com.android.email.provider.ProviderTestUtils;
     21 import com.android.emailcommon.provider.Account;
     22 
     23 import android.content.Context;
     24 import android.test.AndroidTestCase;
     25 
     26 public class WelcomeTests extends AndroidTestCase {
     27 
     28     private Context mProviderContext;
     29 
     30     @Override
     31     protected void setUp() throws Exception {
     32         super.setUp();
     33         mProviderContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext(
     34                 getContext());
     35     }
     36 
     37     public void testResolveAccountId() {
     38         final Context c = mProviderContext;
     39         final Account account1 = ProviderTestUtils.setupAccount("account-1", true, c);
     40         final long id1 = account1.mId;
     41         final Account account2 = ProviderTestUtils.setupAccount("account-2", true, c);
     42         final long id2 = account2.mId;
     43         final Account account3 = ProviderTestUtils.setupAccount("account-3", true, c);
     44         final long id3 = account3.mId;
     45 
     46         // Make sure the last one created (account 3) is the default.
     47         assertTrue(Account.getDefaultAccountId(c) == id3);
     48 
     49         // No account specified -- should return the default account.
     50         assertEquals(id3, Welcome.resolveAccountId(c, -1, null));
     51 
     52         // Invalid account id -- should return the default account.
     53         assertEquals(id3, Welcome.resolveAccountId(c, 12345, null));
     54 
     55         // Valid ID
     56         assertEquals(id1, Welcome.resolveAccountId(c, id1, null));
     57 
     58         // Invalid UUID -- should return the default account.
     59         assertEquals(id3, Welcome.resolveAccountId(c, -1, "xxx"));
     60 
     61         // Valid UUID
     62         assertEquals(id1, Welcome.resolveAccountId(c, -1, account1.mCompatibilityUuid));
     63     }
     64 }
     65