• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.setupwizardlib.test;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 
22 import android.support.test.InstrumentationRegistry;
23 import android.support.test.filters.SmallTest;
24 import android.support.test.runner.AndroidJUnit4;
25 import com.android.setupwizardlib.items.Item;
26 import com.android.setupwizardlib.items.ItemGroup;
27 import com.android.setupwizardlib.items.ItemHierarchy;
28 import com.android.setupwizardlib.items.ItemInflater;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 
32 @RunWith(AndroidJUnit4.class)
33 @SmallTest
34 public class ItemInflaterTest {
35 
36   @Test
testDefaultPackage()37   public void testDefaultPackage() {
38     ItemInflater inflater = new ItemInflater(InstrumentationRegistry.getContext());
39     assertEquals(
40         "Default package should be the one containing Item class",
41         "com.android.setupwizardlib.items.",
42         inflater.getDefaultPackage());
43   }
44 
45   @Test
testInflate()46   public void testInflate() {
47     ItemInflater inflater = new ItemInflater(InstrumentationRegistry.getContext());
48     ItemHierarchy item = inflater.inflate(R.xml.test_items);
49     assertTrue("Inflated item should be ItemGroup", item instanceof ItemGroup);
50     ItemGroup itemGroup = (ItemGroup) item;
51 
52     Item child0 = (Item) itemGroup.getItemAt(0);
53     Item child1 = (Item) itemGroup.getItemAt(1);
54     assertEquals("Title of first child should be Title1", "Title1", child0.getTitle());
55     assertEquals("ID of second child should be test_item_2", R.id.test_item_2, child1.getId());
56     assertEquals("Summary of second child should be Summary2", "Summary2", child1.getSummary());
57   }
58 }
59