ItemTest.java revision c5bf1cb9cb52f95f862eedb8d4f2c71c1ff1a79f
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
17package com.android.setupwizardlib.test;
18
19import android.content.Context;
20import android.test.AndroidTestCase;
21import android.test.suitebuilder.annotation.SmallTest;
22import android.view.View;
23import android.view.ViewGroup;
24import android.widget.FrameLayout;
25import android.widget.TextView;
26
27import com.android.setupwizardlib.R;
28import com.android.setupwizardlib.items.Item;
29
30public class ItemTest extends AndroidTestCase {
31
32    private TextView mTitleView;
33    private TextView mSummaryView;
34
35    @SmallTest
36    public void testOnBindView() {
37        Item item = new TestItem(mContext);
38        View view = createLayout();
39
40        item.onBindView(view);
41
42        assertEquals("Title should be \"TestTitle\"", "TestTitle", mTitleView.getText().toString());
43        assertEquals("Summary should be \"TestSummary\"", "TestSummary",
44                mSummaryView.getText().toString());
45    }
46
47    @SmallTest
48    public void testSingleLineItem() {
49        Item item = new SingleLineTestItem(mContext);
50        View view = createLayout();
51
52        item.onBindView(view);
53
54        assertEquals("Title should be \"TestTitle\"", "TestTitle", mTitleView.getText().toString());
55        assertEquals("Summary should be gone", View.GONE, mSummaryView.getVisibility());
56    }
57
58    private ViewGroup createLayout() {
59        ViewGroup root = new FrameLayout(mContext);
60
61        mTitleView = new TextView(mContext);
62        mTitleView.setId(R.id.suw_items_title);
63        root.addView(mTitleView);
64        mSummaryView = new TextView(mContext);
65        mSummaryView.setId(R.id.suw_items_summary);
66        root.addView(mSummaryView);
67
68        return root;
69    }
70
71    private static class TestItem extends Item {
72
73        public TestItem(Context context) {
74            super(context, null);
75        }
76
77        @Override
78        public CharSequence getTitle() {
79            return "TestTitle";
80        }
81
82        @Override
83        public CharSequence getSummary() {
84            return "TestSummary";
85        }
86    }
87
88    private static class SingleLineTestItem extends Item {
89
90        public SingleLineTestItem(Context context) {
91            super(context, null);
92        }
93
94        @Override
95        public CharSequence getTitle() {
96            return "TestTitle";
97        }
98    }
99}
100