ConversationMessageDataTest.java revision 461a34b466cb4b13dbbc2ec6330b31e217b2ac4e
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.messaging.datamodel.data;
17
18import android.test.suitebuilder.annotation.SmallTest;
19
20import com.android.messaging.BugleTestCase;
21import com.android.messaging.FakeFactory;
22import com.android.messaging.datamodel.FakeCursor;
23import com.android.messaging.datamodel.data.ConversationMessageData;
24import com.android.messaging.datamodel.data.MessageData;
25import com.android.messaging.datamodel.data.ConversationMessageData.ConversationMessageViewColumns;
26
27@SmallTest
28public class ConversationMessageDataTest extends BugleTestCase {
29    @Override
30    protected void setUp() throws Exception {
31        super.setUp();
32        FakeFactory.register(getTestContext());
33    }
34
35    public void testBindFirstMessage() {
36        final FakeCursor testCursor = TestDataFactory.getConversationMessageCursor();
37        final ConversationMessageData data = new ConversationMessageData();
38        testCursor.moveToFirst();
39        data.bind(testCursor);
40        // TODO: Add before checking in all bound fields...
41        assertEquals(testCursor.getAt(ConversationMessageViewColumns.STATUS, 0).equals(
42                MessageData.BUGLE_STATUS_INCOMING_COMPLETE), data.getIsIncoming());
43        assertEquals(testCursor.getAt(ConversationMessageViewColumns.SENDER_PROFILE_PHOTO_URI,
44                0), data.getSenderProfilePhotoUri());
45        assertEquals(testCursor.getAt(ConversationMessageViewColumns.SENDER_FULL_NAME, 0),
46                data.getSenderFullName());
47    }
48
49    public void testBindTwice() {
50        final FakeCursor testCursor = TestDataFactory.getConversationMessageCursor();
51        final ConversationMessageData data = new ConversationMessageData();
52        testCursor.moveToPosition(1);
53        data.bind(testCursor);
54        assertEquals(TestDataFactory.getMessageText(testCursor, 1), data.getText());
55        assertEquals(testCursor.getAt(ConversationMessageViewColumns.RECEIVED_TIMESTAMP, 1),
56                data.getReceivedTimeStamp());
57        assertEquals(testCursor.getAt(ConversationMessageViewColumns.STATUS, 1).equals(
58                MessageData.BUGLE_STATUS_INCOMING_COMPLETE), data.getIsIncoming());
59        assertEquals(testCursor.getAt(ConversationMessageViewColumns.SENDER_PROFILE_PHOTO_URI,
60                1), data.getSenderProfilePhotoUri());
61        assertEquals(testCursor.getAt(ConversationMessageViewColumns.SENDER_FULL_NAME, 1),
62                data.getSenderFullName());
63        testCursor.moveToPosition(2);
64        data.bind(testCursor);
65        assertEquals(TestDataFactory.getMessageText(testCursor, 2), data.getText());
66        assertEquals(testCursor.getAt(ConversationMessageViewColumns.RECEIVED_TIMESTAMP, 2),
67                data.getReceivedTimeStamp());
68        assertEquals(testCursor.getAt(ConversationMessageViewColumns.STATUS, 2).equals(
69                MessageData.BUGLE_STATUS_INCOMING_COMPLETE), data.getIsIncoming());
70        assertEquals(testCursor.getAt(ConversationMessageViewColumns.SENDER_PROFILE_PHOTO_URI,
71                2), data.getSenderProfilePhotoUri());
72        assertEquals(testCursor.getAt(ConversationMessageViewColumns.SENDER_FULL_NAME, 2),
73                data.getSenderFullName());
74    }
75
76    public void testMessageClustering() {
77        final FakeCursor testCursor = TestDataFactory.getConversationMessageCursor();
78        final ConversationMessageData data = new ConversationMessageData();
79        testCursor.moveToPosition(0);
80        data.bind(testCursor);
81        assertFalse(data.getCanClusterWithPreviousMessage());
82        assertFalse(data.getCanClusterWithNextMessage());
83
84        testCursor.moveToPosition(1);
85        data.bind(testCursor);
86        assertFalse(data.getCanClusterWithPreviousMessage());
87        assertFalse(data.getCanClusterWithNextMessage());
88
89        testCursor.moveToPosition(2);
90        data.bind(testCursor);
91        assertFalse(data.getCanClusterWithPreviousMessage());
92        assertTrue(data.getCanClusterWithNextMessage());  // 2 and 3 can be clustered
93        testCursor.moveToPosition(3);
94
95        data.bind(testCursor);
96        assertTrue(data.getCanClusterWithPreviousMessage());  // 2 and 3 can be clustered
97        assertFalse(data.getCanClusterWithNextMessage());
98    }
99}
100