1 /* 2 * Copyright (C) 2024 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 com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.ArgumentMatchers.any; 22 import static org.mockito.Mockito.mock; 23 import static org.mockito.Mockito.when; 24 25 import android.content.Context; 26 27 import androidx.test.ext.junit.runners.AndroidJUnit4; 28 29 import com.android.dx.mockito.inline.extended.ExtendedMockito; 30 31 import org.junit.After; 32 import org.junit.Before; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.mockito.Mock; 36 import org.mockito.MockitoAnnotations; 37 import org.mockito.MockitoSession; 38 import org.mockito.quality.Strictness; 39 40 @RunWith(AndroidJUnit4.class) 41 public class NfcManagerTest { 42 43 private MockitoSession mMockitoSession; 44 private NfcManager mNfcManager; 45 @Mock 46 private Context mContext; 47 48 @Before setUp()49 public void setUp() { 50 mMockitoSession = ExtendedMockito.mockitoSession() 51 .mockStatic(NfcAdapter.class) 52 .strictness(Strictness.LENIENT) 53 .startMocking(); 54 MockitoAnnotations.initMocks(this); 55 56 when(NfcAdapter.getNfcAdapter(any())).thenReturn(mock(NfcAdapter.class)); 57 when(mContext.getApplicationContext()).thenReturn(mContext); 58 mNfcManager = new NfcManager(mContext); 59 } 60 61 @After tearDown()62 public void tearDown() { 63 mMockitoSession.finishMocking(); 64 } 65 66 @Test testGetDefaultAdapter()67 public void testGetDefaultAdapter() { 68 NfcAdapter nfcAdapter = mNfcManager.getDefaultAdapter(); 69 assertThat(nfcAdapter).isNotNull(); 70 } 71 } 72