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