ConstantWithConditionalTest.java revision 4d4979490e1fa374c0d7f3599fed0a9e83a579d0
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * http://www.apache.org/licenses/LICENSE-2.0 7 * Unless required by applicable law or agreed to in writing, software 8 * distributed under the License is distributed on an "AS IS" BASIS, 9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 * See the License for the specific language governing permissions and 11 * limitations under the License. 12 */ 13 14package android.databinding.testapp; 15 16import android.databinding.testapp.databinding.ConstantBindingWithConditionalBinding; 17import android.databinding.testapp.vo.BasicObject; 18import android.databinding.testapp.vo.ConstantBindingTestObject; 19import android.test.UiThreadTest; 20 21import java.util.ArrayList; 22 23public class ConstantWithConditionalTest extends BaseDataBinderTest<ConstantBindingWithConditionalBinding>{ 24 25 public ConstantWithConditionalTest() { 26 super(ConstantBindingWithConditionalBinding.class); 27 } 28 29 @UiThreadTest 30 public void testValues() { 31 initBinder(); 32 mBinder.executePendingBindings(); 33 BasicObject basicObject = new BasicObject(); 34 basicObject.setField1("tt"); 35 basicObject.setField2("blah"); 36 ConstantBindingTestObject obj = new ConstantBindingTestObject(); 37 mBinder.setVm(obj); 38 mBinder.executePendingBindings(); 39 assertTrue(mBinder.myTextView.hasFixedSize()); 40 assertTrue(mBinder.progressBar.isIndeterminate()); 41 42 obj.setErrorMessage("blah"); 43 mBinder.invalidateAll(); 44 mBinder.executePendingBindings(); 45 assertFalse(mBinder.progressBar.isIndeterminate()); 46 47 obj.setErrorMessage(null); 48 ArrayList<String> list = new ArrayList<>(); 49 obj.setCountryModels(list); 50 mBinder.invalidateAll(); 51 mBinder.executePendingBindings(); 52 assertTrue(mBinder.progressBar.isIndeterminate()); 53 54 list.add("abc"); 55 mBinder.invalidateAll(); 56 mBinder.executePendingBindings(); 57 assertFalse(mBinder.progressBar.isIndeterminate()); 58 59 } 60} 61