Debian Codegraph @

integration-tests/TestApp/app/src/androidTestApi7/java/android/databinding/testapp/NameMappingTest.java

raw
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
17 package android.databinding.testapp;
18
19 import android.databinding.testapp.databinding.NameMappingTestBinding;
20 import android.databinding.testapp.vo.BasicObject;
21 import android.test.UiThreadTest;
22 import android.databinding.testapp.BR;
23
24 import java.util.concurrent.atomic.AtomicBoolean;
25
26 public class NameMappingTest extends BaseDataBinderTest<NameMappingTestBinding> {
27
28 public NameMappingTest() {
29 super(NameMappingTestBinding.class);
30 }
31
32 @UiThreadTest
33 public void testChanges() {
34 initBinder();
35 final AtomicBoolean f1 = new AtomicBoolean(false);
36 final AtomicBoolean f2 = new AtomicBoolean(false);
37 BasicObject object = new BasicObject() {
38 @Override
39 public boolean isThisNameDoesNotMatchAnythingElse1() {
40 return f1.get();
41 }
42
43 @Override
44 public boolean getThisNameDoesNotMatchAnythingElse2() {
45 return f2.get();
46 }
47 };
48 mBinder.setObj(object);
49 mBinder.executePendingBindings();
50 for (int i = 0; i < 5; i ++) {
51 boolean f1New = (i & 1) != 0;
52 boolean f2New = (i & 1 << 1) != 0;
53 if (f1New != f1.get()) {
54 f1.set(f1New);
55 object.notifyPropertyChanged(BR.thisNameDoesNotMatchAnythingElse1);
56 }
57 if (f2New != f2.get()) {
58 f1.set(f2New);
59 object.notifyPropertyChanged(BR.thisNameDoesNotMatchAnythingElse2);
60 }
61 mBinder.executePendingBindings();
62 assertEquals(f2.get(), mBinder.textView.isEnabled());
63 assertEquals(f2.get(), mBinder.textView2.isEnabled());
64 assertEquals(false, mBinder.textView3.isEnabled());
65
66 assertEquals(f1.get(), mBinder.textView.isFocusable());
67 assertEquals(f1.get(), mBinder.textView2.isFocusable());
68 assertEquals(false, mBinder.textView3.isFocusable());
69 }
70 }
71 }