• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.car;
18 
19 import static android.car.test.util.AnnotationHelper.checkForAnnotation;
20 
21 import android.car.annotation.AddedInOrBefore;
22 import android.car.annotation.ApiRequirements;
23 
24 import androidx.test.core.app.ApplicationProvider;
25 
26 import com.android.car.R;
27 
28 import org.junit.Test;
29 
30 import java.io.IOException;
31 import java.io.InputStream;
32 
33 public final class AnnotationTest {
34     private static final String TAG = AnnotationTest.class.getSimpleName();
35 
36     @Test
testCarAPIApiRequirementsAnnotation()37     public void testCarAPIApiRequirementsAnnotation() throws Exception {
38         checkForAnnotation(readFile(R.raw.car_api_classes), ApiRequirements.class,
39                 AddedInOrBefore.class);
40     }
41 
42     @Test
testCarBuiltInAPIAddedInAnnotation()43     public void testCarBuiltInAPIAddedInAnnotation() throws Exception {
44         checkForAnnotation(readFile(R.raw.car_built_in_api_classes),
45                 android.car.builtin.annotation.AddedIn.class);
46     }
47 
readFile(int resourceId)48     private String[] readFile(int resourceId) throws IOException {
49         try (InputStream configurationStream = ApplicationProvider.getApplicationContext()
50                 .getResources().openRawResource(resourceId)) {
51             return new String(configurationStream.readAllBytes()).split("\n");
52         }
53     }
54 }
55