AbsSpinnerBindingAdapterTest.java revision 4d4979490e1fa374c0d7f3599fed0a9e83a579d0
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 */ 16package android.databinding.testapp; 17 18import android.databinding.testapp.databinding.AbsSpinnerAdapterTestBinding; 19import android.databinding.testapp.vo.AbsSpinnerBindingObject; 20 21import android.os.Build; 22import android.widget.Spinner; 23import android.widget.SpinnerAdapter; 24 25public class AbsSpinnerBindingAdapterTest 26 extends BindingAdapterTestBase<AbsSpinnerAdapterTestBinding, AbsSpinnerBindingObject> { 27 28 Spinner mView; 29 30 public AbsSpinnerBindingAdapterTest() { 31 super(AbsSpinnerAdapterTestBinding.class, AbsSpinnerBindingObject.class, 32 R.layout.abs_spinner_adapter_test); 33 } 34 35 @Override 36 protected void setUp() throws Exception { 37 super.setUp(); 38 mView = mBinder.view; 39 } 40 41 public void testEntries() throws Throwable { 42 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 43 validateEntries(); 44 45 changeValues(); 46 47 validateEntries(); 48 } 49 } 50 51 private void validateEntries() { 52 assertEquals(mBindingObject.getEntries().length, mView.getAdapter().getCount()); 53 CharSequence[] entries = mBindingObject.getEntries(); 54 SpinnerAdapter adapter = mView.getAdapter(); 55 for (int i = 0; i < entries.length; i++) { 56 assertEquals(adapter.getItem(i), entries[i]); 57 } 58 } 59} 60