1 /*
2  * Copyright (C) 2021 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 com.android.server.pm.test.overlay.actor
18 
19 import android.content.Context
20 import android.content.pm.PackageManager
21 import androidx.test.InstrumentationRegistry
22 import com.google.common.truth.Truth.assertThat
23 import org.junit.Test
24 import kotlin.test.assertFailsWith
25 
26 class OverlayableVisibilityTest {
27 
28     companion object {
29         private const val TARGET_PACKAGE = "com.android.server.pm.test.overlay.target"
30         private const val OVERLAY_PACKAGE = "com.android.server.pm.test.overlay"
31     }
32 
33     private val context: Context = InstrumentationRegistry.getContext()
34     private val packageManager = context.packageManager
35 
36     @Test
verifyVisiblenull37     fun verifyVisible() {
38         assertThat(packageManager.getApplicationInfo(TARGET_PACKAGE, 0)).isNotNull()
39         assertThat(packageManager.getApplicationInfo(OVERLAY_PACKAGE, 0)).isNotNull()
40     }
41 
42     @Test
verifyNotVisiblenull43     fun verifyNotVisible() {
44         assertFailsWith(PackageManager.NameNotFoundException::class) {
45             packageManager.getApplicationInfo(TARGET_PACKAGE, 0)
46         }
47         assertFailsWith(PackageManager.NameNotFoundException::class) {
48             packageManager.getApplicationInfo(OVERLAY_PACKAGE, 0)
49         }
50     }
51 }
52