1 /*
2  * Copyright (C) 2017 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 import androidx.lifecycle.Lifecycle
18 import androidx.lifecycle.LifecycleOwner
19 import androidx.lifecycle.LifecycleRegistry
20 import androidx.lifecycle.LifecycleRegistry.Companion.createUnsafe
21 import org.junit.Before
22 import org.junit.Test
23 import org.junit.runner.RunWith
24 import org.junit.runners.JUnit4
25 import org.mockito.Mockito.mock
26 import org.mockito.Mockito.verify
27 import org.mockito.Mockito.`when`
28 
29 @RunWith(JUnit4::class)
30 class NoPackageTest {
31     private lateinit var lifecycleOwner: LifecycleOwner
32     private lateinit var lifecycle: Lifecycle
33     private lateinit var registry: LifecycleRegistry
34 
35     @Before
initnull36     fun init() {
37         lifecycleOwner = mock(LifecycleOwner::class.java)
38         lifecycle = mock(Lifecycle::class.java)
39         `when`(lifecycleOwner.lifecycle).thenReturn(lifecycle)
40         registry = createUnsafe(lifecycleOwner)
41     }
42 
43     @Test
testNoPackagenull44     fun testNoPackage() {
45         val observer = mock(NoPackageObserver::class.java)
46         registry.addObserver(observer)
47         registry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
48         verify(observer).onCreate()
49     }
50 }
51