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 static org.junit.Assert.assertEquals; 20import static org.junit.Assert.assertTrue; 21 22import android.support.test.InstrumentationRegistry; 23import android.support.test.filters.SmallTest; 24import android.support.test.runner.AndroidJUnit4; 25 26import com.android.setupwizardlib.items.Item; 27import com.android.setupwizardlib.items.ItemGroup; 28import com.android.setupwizardlib.items.ItemHierarchy; 29import com.android.setupwizardlib.items.ItemInflater; 30 31import org.junit.Test; 32import org.junit.runner.RunWith; 33 34@RunWith(AndroidJUnit4.class) 35@SmallTest 36public class ItemInflaterTest { 37 38 @Test 39 public void testDefaultPackage() { 40 ItemInflater inflater = new ItemInflater(InstrumentationRegistry.getContext()); 41 assertEquals("Default package should be the one containing Item class", 42 "com.android.setupwizardlib.items.", inflater.getDefaultPackage()); 43 } 44 45 @Test 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", 57 child1.getSummary()); 58 } 59} 60