ViewWithTagTest.java revision c1560e6b00b398867da12fbdc5a1fcd1d50b801c
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.ViewWithTagBinding; 19import android.support.annotation.UiThread; 20import android.view.View; 21import android.view.ViewGroup; 22import android.widget.TextView; 23 24public class ViewWithTagTest extends BaseDataBinderTest<ViewWithTagBinding> { 25 public ViewWithTagTest() { 26 super(ViewWithTagBinding.class); 27 } 28 29 @UiThread 30 public void test() { 31 ViewWithTagBinding binder = initBinder(); 32 binder.setStr("i don't have tag"); 33 binder.executePendingBindings(); 34 ViewGroup root = (ViewGroup) binder.getRoot(); 35 View view1 = root.getChildAt(0); 36 View view2 = root.getChildAt(1); 37 assertTrue(view2 instanceof TextView); 38 assertEquals("i don't have tag", ((TextView) view2).getText().toString()); 39 assertEquals("i have a tag", view1.getTag().toString()); 40 } 41} 42