103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank/*
203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * Copyright (C) 2009 The Android Open Source Project
303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank *
403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * Licensed under the Apache License, Version 2.0 (the "License");
503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * you may not use this file except in compliance with the License.
603cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * You may obtain a copy of the License at
703cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank *
803cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank *      http://www.apache.org/licenses/LICENSE-2.0
903cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank *
1003cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * Unless required by applicable law or agreed to in writing, software
1103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * distributed under the License is distributed on an "AS IS" BASIS,
1203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * See the License for the specific language governing permissions and
1403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * limitations under the License.
1503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank */
1603cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
1703cd72805dab0379ed255d151f1c17cc60655fc3Marc Blankpackage com.android.email;
1803cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
1903cd72805dab0379ed255d151f1c17cc60655fc3Marc Blankimport com.android.emailcommon.mail.MockFolder;
2003cd72805dab0379ed255d151f1c17cc60655fc3Marc Blankimport com.android.emailcommon.provider.Account;
2103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
2203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blankimport android.content.ContentUris;
2303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blankimport android.net.Uri;
2403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blankimport android.test.AndroidTestCase;
2503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blankimport android.test.suitebuilder.annotation.SmallTest;
2603cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
2703cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank/**
2803cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * This is a series of unit tests for the MessagingController class.
2903cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank *
3003cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank * Technically these are functional because they use the underlying provider framework.
3103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank */
3203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank@SmallTest
3303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blankpublic class MessagingControllerUnitTests extends AndroidTestCase {
3403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
3503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    private long mAccountId;
3603cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    private Account mAccount;
3703cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
3803cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    /**
3903cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank     * Delete any dummy accounts we set up for this test
4003cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank     */
4103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    @Override
4203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    protected void tearDown() throws Exception {
4303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        super.tearDown();
4403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
4503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        if (mAccount != null) {
4603cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank            Uri uri = ContentUris.withAppendedId(
4703cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank                    Account.CONTENT_URI, mAccountId);
4803cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank            getContext().getContentResolver().delete(uri, null, null);
4903cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        }
5003cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    }
5103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
5203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    /**
5303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank     * MockFolder allows setting and retrieving role & name
5403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank     */
5503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    private static class MyMockFolder extends MockFolder {
5603cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        private FolderRole mRole;
5703cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        private String mName;
5803cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
5903cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        public MyMockFolder(FolderRole role, String name) {
6003cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank            mRole = role;
6103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank            mName = name;
6203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        }
6303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
6403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        @Override
6503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        public String getName() {
6603cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank            return mName;
6703cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        }
6803cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
6903cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        @Override
7003cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        public FolderRole getRole() {
7103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank            return mRole;
7203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        }
7303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    }
7403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
7503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    /**
7603cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank     * Create a dummy account with minimal fields
7703cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank     */
7803cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    private void createTestAccount() {
7903cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        mAccount = new Account();
8003cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        mAccount.save(getContext());
8103cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
8203cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank        mAccountId = mAccount.mId;
8303cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank    }
8403cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank
8503cd72805dab0379ed255d151f1c17cc60655fc3Marc Blank}
86