| 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 |
package android.databinding.testapp; |
| 17 |
|
| 18 |
import android.databinding.testapp.databinding.FindMethodTestBinding; |
| 19 |
import android.databinding.testapp.vo.FindMethodBindingObject; |
| 20 |
|
| 21 |
import android.test.UiThreadTest; |
| 22 |
import android.widget.TextView; |
| 23 |
|
| 24 |
public class FindMethodTest |
| 25 |
extends BindingAdapterTestBase<FindMethodTestBinding, FindMethodBindingObject> { |
| 26 |
|
| 27 |
public FindMethodTest() { |
| 28 |
super(FindMethodTestBinding.class, FindMethodBindingObject.class, R.layout.find_method_test); |
| 29 |
} |
| 30 |
|
| 31 |
public void testNoArg() throws Throwable { |
| 32 |
TextView textView = mBinder.textView6; |
| 33 |
assertEquals("no arg", textView.getText().toString()); |
| 34 |
} |
| 35 |
|
| 36 |
public void testIntArg() throws Throwable { |
| 37 |
TextView textView = mBinder.textView0; |
| 38 |
assertEquals("1", textView.getText().toString()); |
| 39 |
} |
| 40 |
|
| 41 |
public void testFloatArg() throws Throwable { |
| 42 |
TextView textView = mBinder.textView1; |
| 43 |
assertEquals("1.25", textView.getText().toString()); |
| 44 |
} |
| 45 |
|
| 46 |
public void testStringArg() throws Throwable { |
| 47 |
TextView textView = mBinder.textView2; |
| 48 |
assertEquals("hello", textView.getText().toString()); |
| 49 |
} |
| 50 |
|
| 51 |
public void testBoxedArg() throws Throwable { |
| 52 |
TextView textView = mBinder.textView3; |
| 53 |
assertEquals("1", textView.getText().toString()); |
| 54 |
} |
| 55 |
|
| 56 |
public void testInheritedMethod() throws Throwable { |
| 57 |
TextView textView = mBinder.textView4; |
| 58 |
assertEquals("base", textView.getText().toString()); |
| 59 |
} |
| 60 |
|
| 61 |
public void testInheritedMethodInt() throws Throwable { |
| 62 |
TextView textView = mBinder.textView5; |
| 63 |
assertEquals("base 2", textView.getText().toString()); |
| 64 |
} |
| 65 |
|
| 66 |
public void testStaticMethod() throws Throwable { |
| 67 |
TextView textView = mBinder.textView7; |
| 68 |
assertEquals("world", textView.getText().toString()); |
| 69 |
} |
| 70 |
|
| 71 |
public void testStaticField() throws Throwable { |
| 72 |
TextView textView = mBinder.textView8; |
| 73 |
assertEquals("hello world", textView.getText().toString()); |
| 74 |
} |
| 75 |
|
| 76 |
public void testImportStaticMethod() throws Throwable { |
| 77 |
TextView textView = mBinder.textView9; |
| 78 |
assertEquals("world", textView.getText().toString()); |
| 79 |
} |
| 80 |
|
| 81 |
public void testImportStaticField() throws Throwable { |
| 82 |
TextView textView = mBinder.textView10; |
| 83 |
assertEquals("hello world", textView.getText().toString()); |
| 84 |
} |
| 85 |
|
| 86 |
public void testAliasStaticMethod() throws Throwable { |
| 87 |
TextView textView = mBinder.textView11; |
| 88 |
assertEquals("world", textView.getText().toString()); |
| 89 |
} |
| 90 |
|
| 91 |
public void testAliasStaticField() throws Throwable { |
| 92 |
TextView textView = mBinder.textView12; |
| 93 |
assertEquals("hello world", textView.getText().toString()); |
| 94 |
} |
| 95 |
|
| 96 |
@UiThreadTest |
| 97 |
public void testObservableField() throws Throwable { |
| 98 |
// tests an ObservableField inside an Observable object |
| 99 |
assertEquals("", mBinder.textView25.getText().toString()); |
| 100 |
mBinder.getObj().myField.set("Hello World"); |
| 101 |
mBinder.executePendingBindings(); |
| 102 |
assertEquals("Hello World", mBinder.textView25.getText().toString()); |
| 103 |
|
| 104 |
mBinder.getObj().myField.set("World Hello"); |
| 105 |
mBinder.executePendingBindings(); |
| 106 |
assertEquals("World Hello", mBinder.textView25.getText().toString()); |
| 107 |
} |
| 108 |
|
| 109 |
@UiThreadTest |
| 110 |
public void testObservableInstanceField() throws Throwable { |
| 111 |
assertEquals("", mBinder.textView26.getText().toString()); |
| 112 |
mBinder.getObj().observableClass.setX("foobar"); |
| 113 |
mBinder.executePendingBindings(); |
| 114 |
assertEquals("foobar", mBinder.textView26.getText().toString()); |
| 115 |
mBinder.getObj().observableClass.setX("barfoo"); |
| 116 |
mBinder.executePendingBindings(); |
| 117 |
assertEquals("barfoo", mBinder.textView26.getText().toString()); |
| 118 |
} |
| 119 |
|
| 120 |
@UiThreadTest |
| 121 |
public void testPrimitiveToObject() throws Throwable { |
| 122 |
mBinder.executePendingBindings(); |
| 123 |
assertTrue(mBinder.textView27.getTag() instanceof Integer); |
| 124 |
assertEquals((Integer)1, mBinder.textView27.getTag()); |
| 125 |
} |
| 126 |
|
| 127 |
@UiThreadTest |
| 128 |
public void testFindMethodBasedOnSecondParam() throws Throwable { |
| 129 |
mBinder.executePendingBindings(); |
| 130 |
assertEquals("2", mBinder.textView28.getText().toString()); |
| 131 |
assertEquals("10", mBinder.textView29.getText().toString()); |
| 132 |
} |
| 133 |
} |