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 */ 16 package android.support.v4.view; 17 18 import static org.junit.Assert.assertEquals; 19 import static org.junit.Assert.assertNotNull; 20 import static org.junit.Assert.assertNull; 21 22 import android.app.Activity; 23 import android.support.compat.test.R; 24 import android.support.test.filters.SmallTest; 25 import android.support.test.runner.AndroidJUnit4; 26 import android.support.v4.BaseInstrumentationTestCase; 27 import android.view.Display; 28 import android.view.View; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 35 @RunWith(AndroidJUnit4.class) 36 @SmallTest 37 public 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 @Test 73 public void testTransitionName() { 74 final View view = new View(mActivityTestRule.getActivity()); 75 ViewCompat.setTransitionName(view, "abc"); 76 assertEquals("abc", ViewCompat.getTransitionName(view)); 77 } 78 79 } 80