| 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.ViewStubBinding; |
| 19 |
import android.databinding.testapp.databinding.ViewStubContentsBinding; |
| 20 |
import android.databinding.ViewStubProxy; |
| 21 |
import android.support.v4.util.ArrayMap; |
| 22 |
import android.test.UiThreadTest; |
| 23 |
import android.view.View; |
| 24 |
import android.widget.TextView; |
| 25 |
|
| 26 |
import java.util.ArrayList; |
| 27 |
|
| 28 |
public class ViewStubTest extends BaseDataBinderTest<ViewStubBinding> { |
| 29 |
|
| 30 |
public ViewStubTest() { |
| 31 |
super(ViewStubBinding.class); |
| 32 |
} |
| 33 |
|
| 34 |
@Override |
| 35 |
protected void setUp() throws Exception { |
| 36 |
super.setUp(); |
| 37 |
initBinder(new Runnable() { |
| 38 |
@Override |
| 39 |
public void run() { |
| 40 |
mBinder.setViewStubVisibility(View.GONE); |
| 41 |
mBinder.setFirstName("Hello"); |
| 42 |
mBinder.setLastName("World"); |
| 43 |
mBinder.executePendingBindings(); |
| 44 |
} |
| 45 |
}); |
| 46 |
} |
| 47 |
|
| 48 |
@UiThreadTest |
| 49 |
public void testInflation() throws Throwable { |
| 50 |
ViewStubProxy viewStubProxy = mBinder.viewStub; |
| 51 |
assertFalse(viewStubProxy.isInflated()); |
| 52 |
assertNull(viewStubProxy.getBinding()); |
| 53 |
assertNotNull(viewStubProxy.getViewStub()); |
| 54 |
assertNull(mBinder.getRoot().findViewById(R.id.firstNameContents)); |
| 55 |
assertNull(mBinder.getRoot().findViewById(R.id.lastNameContents)); |
| 56 |
mBinder.setViewStubVisibility(View.VISIBLE); |
| 57 |
mBinder.executePendingBindings(); |
| 58 |
assertTrue(viewStubProxy.isInflated()); |
| 59 |
assertNotNull(viewStubProxy.getBinding()); |
| 60 |
assertNull(viewStubProxy.getViewStub()); |
| 61 |
ViewStubContentsBinding contentsBinding = (ViewStubContentsBinding) |
| 62 |
viewStubProxy.getBinding(); |
| 63 |
assertNotNull(contentsBinding.firstNameContents); |
| 64 |
assertNotNull(contentsBinding.lastNameContents); |
| 65 |
assertEquals("Hello", contentsBinding.firstNameContents.getText().toString()); |
| 66 |
assertEquals("World", contentsBinding.lastNameContents.getText().toString()); |
| 67 |
} |
| 68 |
|
| 69 |
@UiThreadTest |
| 70 |
public void testChangeValues() throws Throwable { |
| 71 |
ViewStubProxy viewStubProxy = mBinder.viewStub; |
| 72 |
mBinder.setViewStubVisibility(View.VISIBLE); |
| 73 |
mBinder.executePendingBindings(); |
| 74 |
ViewStubContentsBinding contentsBinding = (ViewStubContentsBinding) |
| 75 |
viewStubProxy.getBinding(); |
| 76 |
assertEquals("Hello", contentsBinding.firstNameContents.getText().toString()); |
| 77 |
mBinder.setFirstName("Goodbye"); |
| 78 |
mBinder.executePendingBindings(); |
| 79 |
assertEquals("Goodbye", contentsBinding.firstNameContents.getText().toString()); |
| 80 |
} |
| 81 |
} |