ViewCompatTest.java revision b897ffb1d1cfe37e2e005e7dcdcd97bc5f74205d
100b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze/*
200b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * Copyright (C) 2015 The Android Open Source Project
300b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze *
400b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * Licensed under the Apache License, Version 2.0 (the "License");
500b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * you may not use this file except in compliance with the License.
600b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * You may obtain a copy of the License at
700b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze *
800b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze *      http://www.apache.org/licenses/LICENSE-2.0
900b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze *
1000b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * Unless required by applicable law or agreed to in writing, software
1100b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * distributed under the License is distributed on an "AS IS" BASIS,
1200b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1300b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * See the License for the specific language governing permissions and
1400b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze * limitations under the License.
1500b53b7f3f9ce5996b767b52c28dd846f47a723cAlexey Frunze */
16package android.support.v4.view;
17
18import android.app.Activity;
19import android.support.test.runner.AndroidJUnit4;
20import android.test.suitebuilder.annotation.MediumTest;
21import android.view.Display;
22import android.view.View;
23import android.support.v4.BaseInstrumentationTestCase;
24import android.support.compat.test.R;
25
26import org.junit.Before;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29
30import static org.junit.Assert.assertEquals;
31import static org.junit.Assert.assertNotNull;
32import static org.junit.Assert.assertNull;
33
34
35@RunWith(AndroidJUnit4.class)
36@MediumTest
37public class ViewCompatTest extends BaseInstrumentationTestCase<ViewCompatActivity> {
38
39    private View mView;
40
41    public ViewCompatTest() {
42        super(ViewCompatActivity.class);
43    }
44
45    @Before
46    public void setUp() {
47        final Activity activity = mActivityTestRule.getActivity();
48        mView = activity.findViewById(R.id.view);
49    }
50
51    @Test
52    public void testConstants() {
53        // Compat constants must match core constants since they can be used interchangeably
54        // in various support lib calls.
55        assertEquals("LTR constants", View.LAYOUT_DIRECTION_LTR, ViewCompat.LAYOUT_DIRECTION_LTR);
56        assertEquals("RTL constants", View.LAYOUT_DIRECTION_RTL, ViewCompat.LAYOUT_DIRECTION_RTL);
57    }
58
59    @Test
60    public void testGetDisplay() {
61        final Display display = ViewCompat.getDisplay(mView);
62        assertNotNull(display);
63    }
64
65    @Test
66    public void testGetDisplay_returnsNullForUnattachedView() {
67        final View view = new View(mActivityTestRule.getActivity());
68        final Display display = ViewCompat.getDisplay(view);
69        assertNull(display);
70    }
71
72}
73