Home | History | Annotate | Download | only in reflection
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *      http://www.apache.org/licenses/LICENSE-2.0
      7  * Unless required by applicable law or agreed to in writing, software
      8  * distributed under the License is distributed on an "AS IS" BASIS,
      9  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     10  * See the License for the specific language governing permissions and
     11  * limitations under the License.
     12  */
     13 
     14 package android.databinding.tool.reflection;
     15 
     16 import org.junit.Before;
     17 import org.junit.Test;
     18 
     19 import android.databinding.tool.reflection.java.JavaAnalyzer;
     20 
     21 import static org.junit.Assert.assertEquals;
     22 
     23 public class SdkVersionTest {
     24 
     25     @Before
     26     public void setUp() throws Exception {
     27         JavaAnalyzer.initForTests();
     28     }
     29 
     30     @Test
     31     public void testApiVersionsFromResources() {
     32         SdkUtil.ApiChecker apiChecker = SdkUtil.sApiChecker;
     33         int minSdk = SdkUtil.sMinSdk;
     34         try {
     35             SdkUtil.sApiChecker = new SdkUtil.ApiChecker(null);
     36             ModelClass view = ModelAnalyzer.getInstance().findClass("android.widget.TextView", null);
     37             ModelMethod isSuggestionsEnabled = view.getMethods("isSuggestionsEnabled", 0)[0];
     38             assertEquals(14, SdkUtil.getMinApi(isSuggestionsEnabled));
     39         } finally {
     40             SdkUtil.sMinSdk = minSdk;
     41             SdkUtil.sApiChecker = apiChecker;
     42         }
     43     }
     44 
     45     @Test
     46     public void testNewApiMethod() {
     47         ModelClass view = ModelAnalyzer.getInstance().findClass("android.view.View", null);
     48         ModelMethod setElevation = view.getMethods("setElevation", 1)[0];
     49         assertEquals(21, SdkUtil.getMinApi(setElevation));
     50     }
     51 
     52     @Test
     53     public void testCustomCode() {
     54         ModelClass view = ModelAnalyzer.getInstance()
     55                 .findClass("android.databinding.tool.reflection.SdkVersionTest", null);
     56         ModelMethod setElevation = view.getMethods("testCustomCode", 0)[0];
     57         assertEquals(1, SdkUtil.getMinApi(setElevation));
     58     }
     59 }
     60