1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.android.email; 18 19 import android.content.Context; 20 import android.test.ProviderTestCase2; 21 import android.test.suitebuilder.annotation.Suppress; 22 23 import com.android.email.provider.ContentCache; 24 import com.android.email.provider.EmailProvider; 25 import com.android.emailcommon.provider.EmailContent; 26 import com.android.emailcommon.provider.Mailbox; 27 28 import java.util.Locale; 29 30 /** 31 * Tests of the Controller class that depend on the underlying provider. 32 * 33 * NOTE: It would probably make sense to rewrite this using a MockProvider, instead of the 34 * ProviderTestCase (which is a real provider running on a temp database). This would be more of 35 * a true "unit test". 36 * 37 * You can run this entire test case with: 38 * runtest -c com.android.email.ControllerProviderOpsTests email 39 */ 40 @Suppress 41 public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider> { 42 private Context mProviderContext; 43 private Context mContext; 44 ControllerProviderOpsTests()45 public ControllerProviderOpsTests() { 46 super(EmailProvider.class, EmailContent.AUTHORITY); 47 } 48 49 @Override setUp()50 public void setUp() throws Exception { 51 super.setUp(); 52 mProviderContext = getMockContext(); 53 mContext = getContext(); 54 // Invalidate all caches, since we reset the database for each test 55 ContentCache.invalidateAllCaches(); 56 } 57 58 @Override tearDown()59 public void tearDown() throws Exception { 60 super.tearDown(); 61 } 62 63 /** 64 * These are strings that should not change per locale. 65 */ testGetMailboxServerName()66 public void testGetMailboxServerName() { 67 try { 68 Mailbox.getSystemMailboxName(mContext, -1); 69 fail("Mailbox.getSystemMailboxName(mContext, -1) succeeded without an exception"); 70 } catch (IllegalArgumentException e) { 71 // we expect an exception, so do nothing 72 } 73 74 assertEquals("Inbox", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_INBOX)); 75 assertEquals("Outbox", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_OUTBOX)); 76 assertEquals("Trash", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_TRASH)); 77 assertEquals("Sent", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_SENT)); 78 assertEquals("Junk", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_JUNK)); 79 80 // Now try again with translation 81 Locale savedLocale = Locale.getDefault(); 82 Locale.setDefault(Locale.FRANCE); 83 assertEquals("Inbox", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_INBOX)); 84 assertEquals("Outbox", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_OUTBOX)); 85 assertEquals("Trash", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_TRASH)); 86 assertEquals("Sent", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_SENT)); 87 assertEquals("Junk", Mailbox.getSystemMailboxName(mContext, Mailbox.TYPE_JUNK)); 88 Locale.setDefault(savedLocale); 89 } 90 91 /** 92 * TODO: releasing associated data (e.g. attachments, embedded images) 93 */ 94 } 95