1 /*
2  * Copyright (C) 2009 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;
18 
19 import com.android.emailcommon.mail.MockFolder;
20 import com.android.emailcommon.provider.Account;
21 
22 import android.content.ContentUris;
23 import android.net.Uri;
24 import android.test.AndroidTestCase;
25 import android.test.suitebuilder.annotation.SmallTest;
26 
27 /**
28  * This is a series of unit tests for the MessagingController class.
29  *
30  * Technically these are functional because they use the underlying provider framework.
31  */
32 @SmallTest
33 public class MessagingControllerUnitTests extends AndroidTestCase {
34 
35     private long mAccountId;
36     private Account mAccount;
37 
38     /**
39      * Delete any dummy accounts we set up for this test
40      */
41     @Override
tearDown()42     protected void tearDown() throws Exception {
43         super.tearDown();
44 
45         if (mAccount != null) {
46             Uri uri = ContentUris.withAppendedId(
47                     Account.CONTENT_URI, mAccountId);
48             getContext().getContentResolver().delete(uri, null, null);
49         }
50     }
51 
52     /**
53      * MockFolder allows setting and retrieving role & name
54      */
55     private static class MyMockFolder extends MockFolder {
56         private FolderRole mRole;
57         private String mName;
58 
MyMockFolder(FolderRole role, String name)59         public MyMockFolder(FolderRole role, String name) {
60             mRole = role;
61             mName = name;
62         }
63 
64         @Override
getName()65         public String getName() {
66             return mName;
67         }
68 
69         @Override
getRole()70         public FolderRole getRole() {
71             return mRole;
72         }
73     }
74 
75     /**
76      * Create a dummy account with minimal fields
77      */
createTestAccount()78     private void createTestAccount() {
79         mAccount = new Account();
80         mAccount.save(getContext());
81 
82         mAccountId = mAccount.mId;
83     }
84 
85 }
86