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