• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.nfc;
18 
19 import static org.mockito.Mockito.never;
20 import static org.mockito.Mockito.times;
21 import static org.mockito.Mockito.verify;
22 
23 import android.app.Application;
24 
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mock;
28 import org.mockito.MockitoAnnotations;
29 
30 public class NfcApplicationStateTest {
31     @Mock
32     private NfcActivityManager mNfcActivityManager;
33     @Mock
34     private Application mApp;
35     private NfcApplicationState mNfcApplicationState;
36 
37     @Before
setUp()38     public void setUp() {
39         MockitoAnnotations.initMocks(this);
40         mNfcApplicationState = new NfcApplicationState(mApp, mNfcActivityManager);
41     }
42 
43     @Test
testRegister()44     public void testRegister() {
45         mNfcApplicationState.register();
46 
47         verify(mApp, times(1)).registerActivityLifecycleCallbacks(mNfcActivityManager);
48     }
49 
50     @Test
testMultipleRegister()51     public void testMultipleRegister() {
52         mNfcApplicationState.register();
53         mNfcApplicationState.register();
54 
55         verify(mApp, times(1)).registerActivityLifecycleCallbacks(mNfcActivityManager);
56     }
57 
58     @Test
testUnregister()59     public void testUnregister() {
60         mNfcApplicationState.register();
61         mNfcApplicationState.unregister();
62 
63         verify(mApp, times(1)).unregisterActivityLifecycleCallbacks(mNfcActivityManager);
64     }
65 
66     @Test
testMultipleUnregister()67     public void testMultipleUnregister() {
68         mNfcApplicationState.register();
69         mNfcApplicationState.unregister();
70         mNfcApplicationState.unregister();
71 
72         verify(mApp, times(1)).unregisterActivityLifecycleCallbacks(mNfcActivityManager);
73     }
74 
75     @Test
testUnregisterWithoutRegister()76     public void testUnregisterWithoutRegister() {
77         mNfcApplicationState.unregister();
78 
79         verify(mApp, never()).unregisterActivityLifecycleCallbacks(mNfcActivityManager);
80     }
81 }
82