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.ResourceTestBinding; 19 20 import android.test.UiThreadTest; 21 import android.widget.TextView; 22 23 public class ResourceTest extends BaseDataBinderTest<ResourceTestBinding> { 24 25 public ResourceTest() { 26 super(ResourceTestBinding.class); 27 } 28 29 @Override 30 protected void setUp() throws Exception { 31 super.setUp(); 32 initBinder(new Runnable() { 33 @Override 34 public void run() { 35 mBinder.setCount(0); 36 mBinder.setTitle("Mrs."); 37 mBinder.setLastName("Doubtfire"); 38 mBinder.setBase(2); 39 mBinder.setPbase(3); 40 mBinder.executePendingBindings(); 41 } 42 }); 43 } 44 45 @UiThreadTest 46 public void testStringFormat() throws Throwable { 47 TextView view = mBinder.textView0; 48 assertEquals("Mrs. Doubtfire", view.getText().toString()); 49 50 mBinder.setTitle("Mr."); 51 mBinder.executePendingBindings(); 52 assertEquals("Mr. Doubtfire", view.getText().toString()); 53 } 54 55 @UiThreadTest 56 public void testQuantityString() throws Throwable { 57 TextView view = mBinder.textView1; 58 assertEquals("oranges", view.getText().toString()); 59 60 mBinder.setCount(1); 61 mBinder.executePendingBindings(); 62 assertEquals("orange", view.getText().toString()); 63 } 64 65 @UiThreadTest 66 public void testFractionNoParameters() throws Throwable { 67 TextView view = mBinder.fractionNoParameters; 68 assertEquals("1.5", view.getText().toString()); 69 } 70 71 @UiThreadTest 72 public void testFractionOneParameter() throws Throwable { 73 TextView view = mBinder.fractionOneParameter; 74 assertEquals("3.0", view.getText().toString()); 75 } 76 77 @UiThreadTest 78 public void testFractionTwoParameters() throws Throwable { 79 TextView view = mBinder.fractionTwoParameters; 80 assertEquals("9.0", view.getText().toString()); 81 } 82 } 83