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 17 package com.android.exchange.provider; 18 19 import com.android.emailcommon.provider.Account; 20 import com.android.emailcommon.provider.EmailContent.Message; 21 import com.android.emailcommon.provider.Mailbox; 22 23 import android.content.Context; 24 25 /** 26 * Simplified EmailContent class setup (condensed from ProviderTestUtils in com.android.email) 27 */ 28 public class EmailContentSetupUtils { 29 30 /** 31 * No constructor - statics only 32 */ EmailContentSetupUtils()33 private EmailContentSetupUtils() { 34 } 35 36 /** 37 * Create an account for test purposes 38 */ setupAccount(String name, boolean saveIt, Context context)39 public static Account setupAccount(String name, boolean saveIt, Context context) { 40 Account account = new Account(); 41 42 account.mDisplayName = name; 43 account.mEmailAddress = name + "@android.com"; 44 account.mProtocolVersion = "2.5" + name; 45 if (saveIt) { 46 account.save(context); 47 } 48 return account; 49 } 50 51 /** 52 * Create a mailbox for test purposes 53 */ setupMailbox(String name, long accountId, boolean saveIt, Context context)54 public static Mailbox setupMailbox(String name, long accountId, boolean saveIt, 55 Context context) { 56 return setupMailbox(name, accountId, saveIt, context, Mailbox.TYPE_MAIL, null); 57 } 58 setupMailbox(String name, long accountId, boolean saveIt, Context context, int type)59 public static Mailbox setupMailbox(String name, long accountId, boolean saveIt, 60 Context context, int type) { 61 return setupMailbox(name, accountId, saveIt, context, type, null); 62 } 63 setupMailbox(String name, long accountId, boolean saveIt, Context context, int type, Mailbox parentBox)64 public static Mailbox setupMailbox(String name, long accountId, boolean saveIt, 65 Context context, int type, Mailbox parentBox) { 66 Mailbox box = new Mailbox(); 67 68 box.mDisplayName = name; 69 box.mAccountKey = accountId; 70 box.mSyncKey = "sync-key-" + name; 71 box.mSyncLookback = 2; 72 box.mSyncInterval = Account.CHECK_INTERVAL_NEVER; 73 box.mType = type; 74 box.mServerId = "serverid-" + name; 75 box.mParentServerId = parentBox != null ? parentBox.mServerId : "parent-serverid-" + name; 76 77 if (saveIt) { 78 box.save(context); 79 } 80 return box; 81 } 82 83 /** 84 * Create a message for test purposes 85 */ setupMessage(String name, long accountId, long mailboxId, boolean addBody, boolean saveIt, Context context)86 public static Message setupMessage(String name, long accountId, long mailboxId, 87 boolean addBody, boolean saveIt, Context context) { 88 // Default starred, read, (backword compatibility) 89 return setupMessage(name, accountId, mailboxId, addBody, saveIt, context, true, true); 90 } 91 92 /** 93 * Create a message for test purposes 94 */ setupMessage(String name, long accountId, long mailboxId, boolean addBody, boolean saveIt, Context context, boolean starred, boolean read)95 public static Message setupMessage(String name, long accountId, long mailboxId, 96 boolean addBody, boolean saveIt, Context context, boolean starred, boolean read) { 97 Message message = new Message(); 98 99 message.mDisplayName = name; 100 message.mMailboxKey = mailboxId; 101 message.mAccountKey = accountId; 102 message.mFlagRead = read; 103 message.mFlagLoaded = Message.FLAG_LOADED_UNLOADED; 104 message.mFlagFavorite = starred; 105 message.mServerId = "serverid " + name; 106 107 if (addBody) { 108 message.mText = "body text " + name; 109 message.mHtml = "body html " + name; 110 } 111 112 if (saveIt) { 113 message.save(context); 114 } 115 return message; 116 } 117 } 118