MessageHeaderViewTest.java revision 24b2641bf314de5393f47fbcd298475f2d1fd418
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.test.suitebuilder.annotation.SmallTest; 22 23public class MessageHeaderViewTest extends AndroidTestCase { 24 25 @SmallTest 26 public void testRecipientSummaryLongTo() { 27 String[] to = makeRecipientArray("TO", 60); 28 String[] cc = makeRecipientArray("CC", 60); 29 String summary = MessageHeaderView.getRecipientSummaryText(getContext(), "", to, cc, null) 30 .toString(); 31 32 assertTrue(summary.contains("TO00")); 33 assertTrue(summary.contains("TO49")); 34 assertFalse(summary.contains("TO50")); 35 } 36 37 @SmallTest 38 public void testRecipientSummaryLongMultipleLists() { 39 String[] to = makeRecipientArray("TO", 20); 40 String[] cc = makeRecipientArray("CC", 10); 41 String[] bcc = makeRecipientArray("BB", 60); 42 String summary = MessageHeaderView.getRecipientSummaryText(getContext(), "", to, cc, bcc) 43 .toString(); 44 45 assertTrue(summary.contains("TO00")); 46 assertTrue(summary.contains("TO19")); 47 assertTrue(summary.contains("CC00")); 48 assertTrue(summary.contains("CC09")); 49 assertTrue(summary.contains("BB00")); 50 assertTrue(summary.contains("BB19")); 51 assertFalse(summary.contains("BB20")); 52 } 53 54 private static String[] makeRecipientArray(String prefix, int len) { 55 String[] arr = new String[len]; 56 for (int i=0; i < arr.length; i++) { 57 arr[i] = String.format("\"%s%02d\" <foo@bar.com>", prefix, i); 58 } 59 return arr; 60 } 61 62 @SmallTest 63 public void testMakeSnippet() { 64 assertSnippetEquals("Hello, world!", 65 "Hello, world!"); 66 assertSnippetEquals(" Foo Bar ", 67 "\nFoo\n \nBar\t "); 68 assertSnippetEquals("Hello, World...", 69 "<p><span style=\"color:red\">Hello, <b>World</b></span>...</p>"); 70 assertSnippetEquals("Simon & Garfunkel", 71 "Simon & Garfunkel"); 72 } 73 74 private void assertSnippetEquals(String expectedSnippet, String messageBody) { 75 assertEquals(expectedSnippet, MessageHeaderView.makeSnippet(messageBody)); 76 } 77 78} 79