MessagingControllerUnitTests.java revision fa52e6c95674aef6461a5cfc670a052e1c5b7f2f
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
17package com.android.email;
18
19import com.android.email.mail.MockFolder;
20import com.android.email.provider.EmailContent;
21
22import android.content.ContentUris;
23import android.net.Uri;
24import android.test.AndroidTestCase;
25import 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
33public class MessagingControllerUnitTests extends AndroidTestCase {
34
35    private long mAccountId;
36    private EmailContent.Account mAccount;
37
38    /**
39     * Delete any dummy accounts we set up for this test
40     */
41    @Override
42    protected void tearDown() throws Exception {
43        super.tearDown();
44
45        if (mAccount != null) {
46            Uri uri = ContentUris.withAppendedId(
47                    EmailContent.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
59        public MyMockFolder(FolderRole role, String name) {
60            mRole = role;
61            mName = name;
62        }
63
64        public String getName() {
65            return mName;
66        }
67
68        @Override
69        public FolderRole getRole() {
70            return mRole;
71        }
72    }
73
74    /**
75     * Create a dummy account with minimal fields
76     */
77    private void createTestAccount() {
78        mAccount = new EmailContent.Account();
79        mAccount.save(getContext());
80
81        mAccountId = mAccount.mId;
82    }
83
84}
85