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 */ 16 17 package com.android.messaging.datamodel; 18 19 import android.test.suitebuilder.annotation.SmallTest; 20 21 import com.android.messaging.BugleTestCase; 22 import com.android.messaging.FakeFactory; 23 import com.android.messaging.datamodel.data.ConversationData; 24 import com.android.messaging.datamodel.data.ConversationListData; 25 import com.android.messaging.datamodel.data.ConversationData.ConversationDataListener; 26 import com.android.messaging.datamodel.data.ConversationListData.ConversationListDataListener; 27 28 import org.mockito.Mock; 29 30 public class DataModelTest extends BugleTestCase { 31 32 DataModel dataModel; 33 @Mock protected ConversationDataListener mockConversationDataListener; 34 @Mock protected ConversationListDataListener mockConversationListDataListener; 35 36 @Override setUp()37 protected void setUp() throws Exception { 38 super.setUp(); 39 dataModel = new DataModelImpl(getTestContext()); 40 FakeFactory.register(mContext) 41 .withDataModel(dataModel); 42 } 43 44 @SmallTest testCreateConversationList()45 public void testCreateConversationList() { 46 final ConversationListData list = dataModel.createConversationListData(getContext(), 47 mockConversationListDataListener, true); 48 assertTrue(list instanceof ConversationListData); 49 final ConversationData conv = dataModel.createConversationData(getContext(), 50 mockConversationDataListener, "testConversation"); 51 assertTrue(conv instanceof ConversationData); 52 } 53 54 private static final String FOCUSED_CONV_ID = "focused_conv_id"; 55 56 @SmallTest testFocusedConversationIsObservable()57 public void testFocusedConversationIsObservable() { 58 dataModel.setFocusedConversation(FOCUSED_CONV_ID); 59 assertTrue(dataModel.isNewMessageObservable(FOCUSED_CONV_ID)); 60 dataModel.setFocusedConversation(null); 61 assertFalse(dataModel.isNewMessageObservable(FOCUSED_CONV_ID)); 62 } 63 64 @SmallTest testConversationIsObservableInList()65 public void testConversationIsObservableInList() { 66 dataModel.setConversationListScrolledToNewestConversation(true); 67 assertTrue(dataModel.isNewMessageObservable(FOCUSED_CONV_ID)); 68 dataModel.setConversationListScrolledToNewestConversation(false); 69 assertFalse(dataModel.isNewMessageObservable(FOCUSED_CONV_ID)); 70 } 71 } 72