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 */
13package android.databinding.testapp;
14
15
16import android.databinding.testapp.databinding.StaticAccessImportOnDemandBinding;
17import android.databinding.testapp.databinding.StaticAccessTestBinding;
18import android.databinding.testapp.vo.StaticTestsVo;
19import android.test.UiThreadTest;
20import android.widget.TextView;
21
22import java.util.UUID;
23
24public class StaticAccessImportOnDemandTest extends
25        BaseDataBinderTest<StaticAccessImportOnDemandBinding> {
26
27    public StaticAccessImportOnDemandTest() {
28        super(StaticAccessImportOnDemandBinding.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