ItemTest.java revision 5bf291fde3dfd64f264d525534730514a279c8fc
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    private ViewGroup createLayout() {
48        ViewGroup root = new FrameLayout(mContext);
49
50        mTitleView = new TextView(mContext);
51        mTitleView.setId(R.id.suw_items_title);
52        root.addView(mTitleView);
53        mSummaryView = new TextView(mContext);
54        mSummaryView.setId(R.id.suw_items_summary);
55        root.addView(mSummaryView);
56
57        return root;
58    }
59
60    private static class TestItem extends Item {
61
62        public TestItem(Context context) {
63            super(context, null);
64        }
65
66        @Override
67        public CharSequence getTitle() {
68            return "TestTitle";
69        }
70
71        @Override
72        public CharSequence getSummary() {
73            return "TestSummary";
74        }
75    }
76}
77