Debian Codegraph @

integration-tests/TestApp/app/src/androidTest/java/android/databinding/testapp/StaticAccessTest.java

raw
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.StaticAccessTestBinding;
17 import android.databinding.testapp.vo.StaticTestsVo;
18 import android.test.UiThreadTest;
19 import android.widget.TextView;
20
21 import java.util.UUID;
22
23 public class StaticAccessTest extends BaseDataBinderTest<StaticAccessTestBinding> {
24
25 public StaticAccessTest() {
26 super(StaticAccessTestBinding.class);
27 }
28
29 @UiThreadTest
30 public void testAccessStatics() {
31 initBinder();
32 StaticTestsVo vo = new StaticTestsVo();
33 mBinder.setVo(vo);
34 assertStaticContents();
35 }
36
37 private void assertStaticContents() {
38 mBinder.executePendingBindings();
39 assertText(StaticTestsVo.ourStaticField, mBinder.staticFieldOverVo);
40 assertText(StaticTestsVo.ourStaticMethod(), mBinder.staticMethodOverVo);
41 assertText(StaticTestsVo.ourStaticObservable.get(), mBinder.obsStaticOverVo);
42
43 assertText(StaticTestsVo.ourStaticField, mBinder.staticFieldOverClass);
44 assertText(StaticTestsVo.ourStaticMethod(), mBinder.staticMethodOverClass);
45 assertText(StaticTestsVo.ourStaticObservable.get(), mBinder.obsStaticOverClass);
46
47 String newValue = UUID.randomUUID().toString();
48 StaticTestsVo.ourStaticObservable.set(newValue);
49 mBinder.executePendingBindings();
50 assertText(StaticTestsVo.ourStaticObservable.get(), mBinder.obsStaticOverVo);
51 assertText(StaticTestsVo.ourStaticObservable.get(), mBinder.obsStaticOverClass);
52 }
53
54 @UiThreadTest
55 public void testAccessStaticsVoInstance() {
56 initBinder();
57 mBinder.setVo(null);
58 assertStaticContents();
59 }
60
61 private void assertText(String contents, TextView textView) {
62 assertEquals(contents, textView.getText().toString());
63 }
64 }