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.test.AndroidTestCase;
20import android.test.suitebuilder.annotation.SmallTest;
21
22import com.android.setupwizardlib.items.Item;
23import com.android.setupwizardlib.items.ItemGroup;
24import com.android.setupwizardlib.items.ItemHierarchy;
25import com.android.setupwizardlib.items.RecyclerItemAdapter;
26
27import java.util.Arrays;
28import java.util.HashSet;
29
30public class RecyclerItemAdapterTest extends AndroidTestCase {
31
32    private Item[] mItems = new Item[5];
33    private ItemGroup mItemGroup = new ItemGroup();
34
35    @Override
36    protected void setUp() throws Exception {
37        super.setUp();
38        for (int i = 0; i < 5; i++) {
39            Item item = new Item();
40            item.setTitle("TestTitle" + i);
41            item.setId(i);
42            // Layout resource: 0 -> 1, 1 -> 11, 2 -> 21, 3 -> 1, 4 -> 11.
43            // (Resource IDs cannot be 0)
44            item.setLayoutResource((i % 3) * 10 + 1);
45            mItems[i] = item;
46            mItemGroup.addChild(item);
47        }
48    }
49
50    @SmallTest
51    public void testAdapter() {
52        RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
53        assertEquals("Adapter should have 5 items", 5, adapter.getItemCount());
54        assertEquals("Adapter should return the first item", mItems[0], adapter.getItem(0));
55        assertEquals("ID should be same as position", 2, adapter.getItemId(2));
56
57        // ViewType is same as layout resource for RecyclerItemAdapter
58        assertEquals("Second item should have view type 21", 21, adapter.getItemViewType(2));
59    }
60
61    @SmallTest
62    public void testGetRootItemHierarchy() {
63        RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
64        ItemHierarchy root = adapter.getRootItemHierarchy();
65        assertSame("Root item hierarchy should be mItemGroup", mItemGroup, root);
66    }
67}
68