ViewCompatTest.java revision 4bb57b2c7c5e8fa607119bd5089535d5862cb979
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.support.v4.view;
17
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertNotNull;
20import static org.junit.Assert.assertNull;
21
22import android.app.Activity;
23import android.support.compat.test.R;
24import android.support.test.filters.SmallTest;
25import android.support.test.runner.AndroidJUnit4;
26import android.support.v4.BaseInstrumentationTestCase;
27import android.view.Display;
28import android.view.View;
29
30import org.junit.Before;
31import org.junit.Test;
32import org.junit.runner.RunWith;
33
34
35@RunWith(AndroidJUnit4.class)
36@SmallTest
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