MessageHeaderViewTest.java revision ff8553f20964f4c31b0c503a9e1daff6ae08a9c7
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,
30                null, null, null).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,
43                bcc, null, null).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 &amp; Garfunkel");
72    }
73
74    private static void assertSnippetEquals(final String expectedSnippet,
75            final String messageBody) {
76        assertEquals(expectedSnippet, MessageHeaderView.makeSnippet(messageBody));
77    }
78
79}
80