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