Home | History | Annotate | Download | only in testapp
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *      http://www.apache.org/licenses/LICENSE-2.0
      7  * Unless required by applicable law or agreed to in writing, software
      8  * distributed under the License is distributed on an "AS IS" BASIS,
      9  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     10  * See the License for the specific language governing permissions and
     11  * limitations under the License.
     12  */
     13 package android.databinding.testapp;
     14 
     15 
     16 import android.databinding.testapp.databinding.StaticAccessImportOnDemandBinding;
     17 import android.databinding.testapp.databinding.StaticAccessImportOnDemandWithConflictBinding;
     18 import android.databinding.testapp.vo.StaticTestsVo;
     19 import android.test.UiThreadTest;
     20 import android.widget.TextView;
     21 
     22 import java.util.UUID;
     23 
     24 public class StaticAccessImportOnDemandWithConflictTest extends
     25         BaseDataBinderTest<StaticAccessImportOnDemandWithConflictBinding> {
     26 
     27     public StaticAccessImportOnDemandWithConflictTest() {
     28         super(StaticAccessImportOnDemandWithConflictBinding.class);
     29     }
     30 
     31     @UiThreadTest
     32     public void testAccessStatics() {
     33         initBinder();
     34         StaticTestsVo vo = new StaticTestsVo();
     35         mBinder.setVo(vo);
     36         assertStaticContents();
     37     }
     38 
     39     private void assertStaticContents() {
     40         mBinder.executePendingBindings();
     41         assertText(StaticTestsVo.ourStaticField, mBinder.staticFieldOverVo);
     42         assertText(StaticTestsVo.ourStaticMethod(), mBinder.staticMethodOverVo);
     43         assertText(StaticTestsVo.ourStaticObservable.get(), mBinder.obsStaticOverVo);
     44 
     45         String newValue = UUID.randomUUID().toString();
     46         StaticTestsVo.ourStaticObservable.set(newValue);
     47         mBinder.executePendingBindings();
     48         assertText(StaticTestsVo.ourStaticObservable.get(), mBinder.obsStaticOverVo);
     49     }
     50 
     51     @UiThreadTest
     52     public void testAccessStaticsVoInstance() {
     53         initBinder();
     54         mBinder.setVo(null);
     55         assertStaticContents();
     56     }
     57 
     58     private void assertText(String contents, TextView textView) {
     59         assertEquals(contents, textView.getText().toString());
     60     }
     61 }
     62