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 17package com.android.email.activity; 18 19import com.android.email.DBTestHelper; 20import com.android.email.provider.ProviderTestUtils; 21import com.android.emailcommon.provider.Account; 22 23import android.content.Context; 24import android.content.Intent; 25import android.test.AndroidTestCase; 26 27public class MessageListTests extends AndroidTestCase { 28 29 private Context mMockContext; 30 31 public MessageListTests() { 32 } 33 34 @Override 35 public void setUp() throws Exception { 36 super.setUp(); 37 38 // ProviderTestCase2 can't be used. It creates a mock context that doesn't support 39 // some methods we need here, such as getPackageName. 40 mMockContext = DBTestHelper.ProviderContextSetupHelper.getProviderContext( 41 getContext()); 42 } 43 44 public void testGetAccountFromIntent() { 45 final Context c = mMockContext; 46 final Account a1 = ProviderTestUtils.setupAccount("a1", true, c); 47 final Account a2 = ProviderTestUtils.setupAccount("a2", true, c); 48 49 assertEquals(a1.mId, MessageList.getAccountFromIntent(c, 50 MessageList.createFroyoIntent(c, a1))); 51 assertEquals(a2.mId, MessageList.getAccountFromIntent(c, 52 MessageList.createFroyoIntent(c, a2))); 53 54 // Mixed -- UUID in the URI doesn't match the account ID in extra. 55 // It's a test for shortcuts for restored accounts. 56 final Intent i = MessageList.createFroyoIntent(c, a2); 57 i.putExtra(MessageList.EXTRA_ACCOUNT_ID, 12345); 58 assertEquals(a2.mId, MessageList.getAccountFromIntent(c, i)); 59 60 // Invalid intent -- no extra, no URI. 61 assertEquals(Account.NO_ACCOUNT, MessageList.getAccountFromIntent(c, 62 new Intent(c, MessageList.class))); 63 } 64} 65