1c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar/*
2c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * Copyright (C) 2015 The Android Open Source Project
3c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar *
4c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * Licensed under the Apache License, Version 2.0 (the "License");
5c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * you may not use this file except in compliance with the License.
6c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * You may obtain a copy of the License at
7c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar *
8c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar *      http://www.apache.org/licenses/LICENSE-2.0
9c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar *
10c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * Unless required by applicable law or agreed to in writing, software
11c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * distributed under the License is distributed on an "AS IS" BASIS,
12c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * See the License for the specific language governing permissions and
14c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar * limitations under the License.
15c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar */
16c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyarpackage android.databinding.testapp;
17c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar
18c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyarimport android.databinding.testapp.databinding.ViewWithTagBinding;
19c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyarimport android.support.annotation.UiThread;
20c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyarimport android.view.View;
21c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyarimport android.view.ViewGroup;
22c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyarimport android.widget.TextView;
23c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar
24c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyarpublic class ViewWithTagTest extends BaseDataBinderTest<ViewWithTagBinding> {
25c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar    public ViewWithTagTest() {
26c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        super(ViewWithTagBinding.class);
27c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar    }
28c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar
29c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar    @UiThread
30c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar    public void test() {
31c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        ViewWithTagBinding binder = initBinder();
32c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        binder.setStr("i don't have tag");
33c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        binder.executePendingBindings();
34c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        ViewGroup root = (ViewGroup) binder.getRoot();
35c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        View view1 = root.getChildAt(0);
36c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        View view2 = root.getChildAt(1);
37c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        assertTrue(view2 instanceof TextView);
38c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        assertEquals("i don't have tag", ((TextView) view2).getText().toString());
39c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar        assertEquals("i have a tag", view1.getTag().toString());
409eb684f8375efd59c4fd880bd578b470eb273d41George Mount        assertEquals("Hello", view2.getTag(R.id.customTag));
41c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar    }
42c1560e6b00b398867da12fbdc5a1fcd1d50b801cYigit Boyar}
43