xref: /aosp_15_r20/external/dagger2/javatests/dagger/android/AndroidProguardTest.java (revision f585d8a307d0621d6060bd7e80091fdcbf94fe27)
1 /*
2  * Copyright (C) 2020 The Dagger Authors.
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 dagger.android;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.os.Build;
22 import androidx.test.ext.junit.runners.AndroidJUnit4;
23 import dagger.android.internal.AndroidInjectionKeys;
24 import java.net.URL;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.robolectric.annotation.Config;
28 
29 @RunWith(AndroidJUnit4.class)
30 // Robolectric requires Java9 to run API 29 and above, so use API 28 instead
31 @Config(sdk = Build.VERSION_CODES.P)
32 public class AndroidProguardTest {
33 
34   @Test
checkLegacyProguardRules()35   public void checkLegacyProguardRules() {
36     URL resUrl =
37         AndroidInjectionKeys.class
38             .getClassLoader()
39             .getResource("META-INF/proguard/dagger-android.pro");
40     assertThat(resUrl).isNotNull();
41   }
42 
43   // The com.android.tools files are only used outside Google, in Gradle projects.
44   @Test
checkProguardRules()45   public void checkProguardRules() {
46     URL resUrl =
47         AndroidInjectionKeys.class
48             .getClassLoader()
49             .getResource("META-INF/com.android.tools/proguard/dagger-android.pro");
50     assertThat(resUrl).isNotNull();
51   }
52 
53   @Test
checkR8Rules()54   public void checkR8Rules() {
55     URL resUrl =
56         AndroidInjectionKeys.class
57             .getClassLoader()
58             .getResource("META-INF/com.android.tools/r8/dagger-android.pro");
59     assertThat(resUrl).isNotNull();
60   }
61 }
62