OSDN Git Service

Fork Search code to independantly develop and test search.
[android-x86/packages-apps-Settings.git] / tests / robotests / src / com / android / settings / search / IntentSearchViewHolderTest.java
1 /*
2  * Copyright (C) 2016 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
18 package com.android.settings.search;
19
20 import android.content.Context;
21 import android.graphics.drawable.Drawable;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import com.android.settings.R;
25 import com.android.settings.SettingsRobolectricTestRunner;
26 import com.android.settings.TestConfig;
27 import com.android.settings.search2.IntentPayload;
28 import com.android.settings.search2.IntentSearchViewHolder;
29 import com.android.settings.search2.SearchResult.Builder;
30 import com.android.settings.search2.SearchResult;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34
35 import org.robolectric.annotation.Config;
36 import org.robolectric.shadows.ShadowApplication;
37
38 import java.util.ArrayList;
39
40 import static com.google.common.truth.Truth.assertThat;
41
42 @RunWith(SettingsRobolectricTestRunner.class)
43 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
44 public class IntentSearchViewHolderTest {
45     private IntentSearchViewHolder mHolder;
46     private static Drawable mIcon;
47
48     private static final String TITLE = "title";
49     private static final String SUMMARY = "summary";
50
51
52     @Before
53     public void setUp() {
54         final Context context = ShadowApplication.getInstance().getApplicationContext();
55         View view = LayoutInflater.from(context).inflate(R.layout.search_intent_item, null);
56         mHolder = new IntentSearchViewHolder(view);
57
58         mIcon = context.getDrawable(R.drawable.ic_search_history);
59     }
60
61     @Test
62     public void testConstructor_MembersNotNull() {
63         assertThat(mHolder.titleView).isNotNull();
64         assertThat(mHolder.summaryView).isNotNull();
65         assertThat(mHolder.iconView).isNotNull();
66     }
67
68     @Test
69     public void testBindViewElements_AllUpdated() {
70         SearchResult result = getSearchResult();
71         mHolder.onBind(result);
72
73         assertThat(mHolder.titleView.getText()).isEqualTo(TITLE);
74         assertThat(mHolder.summaryView.getText()).isEqualTo(SUMMARY);
75         assertThat(mHolder.iconView.getDrawable()).isEqualTo(mIcon);
76     }
77
78     private SearchResult getSearchResult() {
79         Builder builder = new Builder();
80         builder.addTitle(TITLE)
81                 .addSummary(SUMMARY)
82                 .addRank(1)
83                 .addPayload(new IntentPayload(null))
84                 .addBreadcrumbs(new ArrayList<String>())
85                 .addIcon(mIcon);
86
87         return builder.build();
88     }
89 }