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.assertNotNull; 20import static org.junit.Assert.assertTrue; 21import static org.junit.Assert.fail; 22 23import android.content.Context; 24import android.support.test.InstrumentationRegistry; 25import android.support.test.filters.SmallTest; 26import android.support.test.runner.AndroidJUnit4; 27import android.view.ContextThemeWrapper; 28import android.view.LayoutInflater; 29import android.view.View; 30import android.widget.ListView; 31import android.widget.ProgressBar; 32import android.widget.TextView; 33 34import com.android.setupwizardlib.SetupWizardLayout; 35import com.android.setupwizardlib.SetupWizardListLayout; 36import com.android.setupwizardlib.view.NavigationBar; 37 38import org.junit.Before; 39import org.junit.Test; 40import org.junit.runner.RunWith; 41 42@RunWith(AndroidJUnit4.class) 43@SmallTest 44public class SetupWizardListLayoutTest { 45 46 private Context mContext; 47 48 @Before 49 public void setUp() throws Exception { 50 mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(), 51 R.style.SuwThemeMaterial_Light); 52 } 53 54 @Test 55 public void testDefaultTemplate() { 56 SetupWizardListLayout layout = new SetupWizardListLayout(mContext); 57 assertListTemplateInflated(layout); 58 } 59 60 @Test 61 public void testAddView() { 62 SetupWizardListLayout layout = new SetupWizardListLayout(mContext); 63 TextView tv = new TextView(mContext); 64 try { 65 layout.addView(tv); 66 fail("Adding view to ListLayout should throw"); 67 } catch (UnsupportedOperationException e) { 68 // Expected exception 69 } 70 } 71 72 @Test 73 public void testInflateFromXml() { 74 LayoutInflater inflater = LayoutInflater.from(mContext); 75 SetupWizardListLayout layout = (SetupWizardListLayout) 76 inflater.inflate(R.layout.test_list_layout, null); 77 assertListTemplateInflated(layout); 78 } 79 80 @Test 81 public void testShowProgressBar() { 82 final SetupWizardListLayout layout = new SetupWizardListLayout(mContext); 83 layout.showProgressBar(); 84 assertTrue("Progress bar should be shown", layout.isProgressBarShown()); 85 final View progressBar = layout.findViewById(R.id.suw_layout_progress); 86 assertTrue("Progress bar view should be shown", 87 progressBar instanceof ProgressBar && progressBar.getVisibility() == View.VISIBLE); 88 } 89 90 private void assertListTemplateInflated(SetupWizardLayout layout) { 91 View decorView = layout.findViewById(R.id.suw_layout_decor); 92 View navbar = layout.findViewById(R.id.suw_layout_navigation_bar); 93 View title = layout.findViewById(R.id.suw_layout_title); 94 View list = layout.findViewById(android.R.id.list); 95 assertNotNull("@id/suw_layout_decor_view should not be null", decorView); 96 assertTrue("@id/suw_layout_navigation_bar should be an instance of NavigationBar", 97 navbar instanceof NavigationBar); 98 assertNotNull("@id/suw_layout_title should not be null", title); 99 assertTrue("@android:id/list should be an instance of ListView", list instanceof ListView); 100 } 101} 102