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