SendersFormattingTests.java revision d8e5ff44a8a7405bb8891fb46570782138babbd1
1/******************************************************************************* 2 * Copyright (C) 2012 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 *******************************************************************************/ 17 18package com.android.mail.browse; 19 20import android.test.AndroidTestCase; 21import android.text.SpannableString; 22 23import com.android.mail.providers.ConversationInfo; 24import com.android.mail.providers.MessageInfo; 25 26public class SendersFormattingTests extends AndroidTestCase { 27 28 private static ConversationInfo createConversationInfo(int count) { 29 int draftCount = 5; 30 String first = "snippet", firstUnread = first, last = first; 31 String senders = "senders"; 32 return new ConversationInfo(count, draftCount, first, firstUnread, last, senders); 33 } 34 35 public void testMe() { 36 // Blank sender == from "me" 37 ConversationInfo conv = createConversationInfo(1); 38 boolean read = false, starred = false; 39 MessageInfo info = new MessageInfo(read, starred, null); 40 conv.addMessage(info); 41 SpannableString[] strings = SendersView.format(getContext(), conv); 42 assertEquals(strings.length, 1); 43 assertEquals(strings[0].toString(), "me"); 44 45 ConversationInfo conv2 = createConversationInfo(1); 46 MessageInfo info2 = new MessageInfo(read, starred, ""); 47 conv2.addMessage(info2); 48 strings = SendersView.format(getContext(), conv); 49 assertEquals(strings.length, 1); 50 assertEquals(strings[0].toString(), "me"); 51 52 ConversationInfo conv3 = createConversationInfo(2); 53 MessageInfo info3 = new MessageInfo(read, starred, ""); 54 conv3.addMessage(info3); 55 MessageInfo info4 = new MessageInfo(read, starred, ""); 56 conv3.addMessage(info4); 57 strings = SendersView.format(getContext(), conv); 58 assertEquals(strings.length, 1); 59 assertEquals(strings[0].toString(), "me"); 60 } 61 62 public void testDupes() { 63 // Duplicate sender; should only return 1 64 ConversationInfo conv = createConversationInfo(2); 65 boolean read = false, starred = false; 66 String sender = "sender@sender.com"; 67 MessageInfo info = new MessageInfo(read, starred, sender); 68 conv.addMessage(info); 69 MessageInfo info2 = new MessageInfo(read, starred, sender); 70 conv.addMessage(info2); 71 SpannableString[] strings = SendersView.format(getContext(), conv); 72 assertEquals(strings.length, 1); 73 assertEquals(strings[0].toString(), sender); 74 75 // Test that the 2nd instance of the duped sender shows and not the first. 76 ConversationInfo conv2 = createConversationInfo(3); 77 String sender2 = "sender2@sender.com"; 78 conv2.addMessage(info); 79 MessageInfo info3 = new MessageInfo(read, starred, sender2); 80 conv2.addMessage(info3); 81 conv2.addMessage(info2); 82 strings = SendersView.format(getContext(), conv2); 83 assertEquals(strings.length, 2); 84 assertEquals(strings[0].toString(), sender2); 85 assertEquals(strings[1].toString(), sender); 86 } 87} 88