Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright 2019 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 
     17 package android.view.inspector.cts;
     18 
     19 
     20 import static org.junit.Assert.assertEquals;
     21 import static org.junit.Assert.assertNotNull;
     22 import static org.junit.Assert.assertNull;
     23 import static org.junit.Assert.assertTrue;
     24 
     25 import android.view.View;
     26 import android.view.inspector.InspectionCompanion;
     27 import android.view.inspector.PropertyMapper;
     28 import android.view.inspector.PropertyReader;
     29 import android.view.inspector.StaticInspectionCompanionProvider;
     30 import android.widget.RelativeLayout;
     31 
     32 import androidx.test.filters.SmallTest;
     33 import androidx.test.runner.AndroidJUnit4;
     34 
     35 import org.junit.Before;
     36 import org.junit.Test;
     37 import org.junit.runner.RunWith;
     38 
     39 /**
     40  * Tests for {@link StaticInspectionCompanionProvider}
     41  */
     42 @SmallTest
     43 @RunWith(AndroidJUnit4.class)
     44 public class StaticInspectionCompanionProviderTest {
     45     private StaticInspectionCompanionProvider mProvider;
     46 
     47     @Before
     48     public void setup() {
     49         mProvider = new StaticInspectionCompanionProvider();
     50     }
     51 
     52     @Test
     53     public void testViewWorks() {
     54         InspectionCompanion<View> companion = mProvider.provide(View.class);
     55         assertNotNull(companion);
     56         assertEquals("android.view.View$InspectionCompanion", companion.getClass().getName());
     57     }
     58 
     59     @Test
     60     public void testRelativeLayoutWorks() {
     61         InspectionCompanion<RelativeLayout.LayoutParams> companion =
     62                 mProvider.provide(RelativeLayout.LayoutParams.class);
     63         assertNotNull(companion);
     64         assertEquals(
     65                 "android.widget.RelativeLayout$LayoutParams$InspectionCompanion",
     66                 companion.getClass().getName());
     67     }
     68 
     69     static class NestedClassTest {
     70         public static final class InspectionCompanion
     71                 implements android.view.inspector.InspectionCompanion<NestedClassTest> {
     72             @Override
     73             public void mapProperties(PropertyMapper propertyMapper) {
     74 
     75             }
     76 
     77             @Override
     78             public void readProperties(NestedClassTest inspectable, PropertyReader propertyReader) {
     79 
     80             }
     81         }
     82     }
     83 
     84     @Test
     85     public void testNestedClassLoading() {
     86         InspectionCompanion<NestedClassTest> companion = mProvider.provide(NestedClassTest.class);
     87         assertNotNull(companion);
     88         assertTrue(companion instanceof NestedClassTest.InspectionCompanion);
     89     }
     90 
     91     static class NonImplementingNestedClassTest {
     92         public static final class InspectionCompanion {
     93         }
     94     }
     95 
     96     @Test
     97     public void testNonImplementingNestedClass() {
     98         InspectionCompanion<NonImplementingNestedClassTest> companion =
     99                 mProvider.provide(NonImplementingNestedClassTest.class);
    100         assertNull(companion);
    101     }
    102 
    103     class NoCompanionTest {
    104     }
    105 
    106     @Test
    107     public void testNoCompanion() {
    108         InspectionCompanion<NoCompanionTest> companion = mProvider.provide(NoCompanionTest.class);
    109         assertNull(companion);
    110     }
    111 }
    112