• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Revisão07bb0280f64162d3f84e70fbfa7d74deb4e264fb (tree)
Hora2021-01-12 08:08:40
AutorAlisher Alikhodjaev <alisher@goog...>
CommiterAndroid (Google) Code Review

Mensagem de Log

Merge "Fix robotests failure in connectivity settings" into rvc-qpr-dev

Mudança Sumário

Diff

--- a/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceControllerTest.java
@@ -34,6 +34,7 @@ import androidx.test.core.content.pm.ApplicationInfoBuilder;
3434
3535 import com.android.settings.R;
3636 import com.android.settings.nfc.NfcPreferenceController;
37+import com.android.settings.testutils.shadow.ShadowNfcAdapter;
3738
3839 import org.junit.Before;
3940 import org.junit.Test;
@@ -43,7 +44,7 @@ import org.robolectric.RobolectricTestRunner;
4344 import org.robolectric.RuntimeEnvironment;
4445 import org.robolectric.Shadows;
4546 import org.robolectric.annotation.Config;
46-import org.robolectric.shadows.ShadowNfcAdapter;
47+import org.robolectric.shadow.api.Shadow;
4748 import org.robolectric.shadows.ShadowPackageManager;
4849 import org.robolectric.util.ReflectionHelpers;
4950
@@ -70,7 +71,7 @@ public class AdvancedConnectedDeviceControllerTest {
7071 mContentResolver = mContext.getContentResolver();
7172 mNfcController = new NfcPreferenceController(mContext,
7273 NfcPreferenceController.KEY_TOGGLE_NFC);
73- mShadowNfcAdapter = Shadows.shadowOf(NfcAdapter.getNfcAdapter(mContext));
74+ mShadowNfcAdapter = Shadow.extract(NfcAdapter.getDefaultAdapter(mContext));
7475 mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
7576 }
7677
--- a/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragmentTest.java
@@ -18,7 +18,6 @@ package com.android.settings.connecteddevice;
1818 import static com.google.common.truth.Truth.assertThat;
1919
2020 import static org.mockito.Mockito.spy;
21-import static org.mockito.Mockito.when;
2221
2322 import android.content.Context;
2423 import android.nfc.NfcAdapter;
@@ -26,35 +25,38 @@ import android.provider.SearchIndexableResource;
2625
2726 import com.android.settings.nfc.AndroidBeamPreferenceController;
2827 import com.android.settings.testutils.shadow.ShadowConnectivityManager;
28+import com.android.settings.testutils.shadow.ShadowNfcAdapter;
2929 import com.android.settings.testutils.shadow.ShadowUserManager;
3030 import com.android.settingslib.drawer.CategoryKey;
3131
3232 import org.junit.Before;
3333 import org.junit.Test;
3434 import org.junit.runner.RunWith;
35-import org.mockito.Mock;
3635 import org.mockito.MockitoAnnotations;
3736 import org.robolectric.RobolectricTestRunner;
3837 import org.robolectric.RuntimeEnvironment;
3938 import org.robolectric.annotation.Config;
39+import org.robolectric.shadow.api.Shadow;
4040
4141 import java.util.List;
4242
4343 @RunWith(RobolectricTestRunner.class)
4444 @Config(shadows = {ShadowUserManager.class,
45- ShadowConnectivityManager.class})
45+ ShadowConnectivityManager.class, ShadowNfcAdapter.class})
4646 public class AdvancedConnectedDeviceDashboardFragmentTest {
4747
4848 private AdvancedConnectedDeviceDashboardFragment mFragment;
4949
50- @Mock
51- private NfcAdapter mNfcAdapter;
50+ private Context mContext;
51+ private ShadowNfcAdapter mShadowNfcAdapter;
5252
5353 @Before
5454 public void setUp() {
5555 MockitoAnnotations.initMocks(this);
5656
57+ mContext = spy(RuntimeEnvironment.application);
5758 mFragment = new AdvancedConnectedDeviceDashboardFragment();
59+ mShadowNfcAdapter = Shadow.extract(NfcAdapter.getDefaultAdapter(mContext));
5860 }
5961
6062 @Test
@@ -79,13 +81,10 @@ public class AdvancedConnectedDeviceDashboardFragmentTest {
7981
8082 @Test
8183 public void testSearchIndexProvider_correctNonIndexables() {
82- Context context = spy(RuntimeEnvironment.application);
83- when(context.getApplicationContext()).thenReturn(context);
84- when(NfcAdapter.getDefaultAdapter(context)).thenReturn(mNfcAdapter);
85- when(mNfcAdapter.isSecureNfcSupported()).thenReturn(true);
84+ mShadowNfcAdapter.setSecureNfcSupported(true);
8685 final List<String> niks =
8786 AdvancedConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
88- .getNonIndexableKeys(context);
87+ .getNonIndexableKeys(mContext);
8988
9089 assertThat(niks).contains(AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
9190 }
--- a/tests/robotests/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentControllerTest.java
@@ -29,6 +29,7 @@ import android.nfc.NfcManager;
2929 import android.os.UserManager;
3030
3131 import com.android.settings.R;
32+import com.android.settings.testutils.shadow.ShadowNfcAdapter;
3233
3334 import org.junit.Before;
3435 import org.junit.Test;
@@ -37,9 +38,12 @@ import org.mockito.Mock;
3738 import org.mockito.MockitoAnnotations;
3839 import org.robolectric.RobolectricTestRunner;
3940 import org.robolectric.RuntimeEnvironment;
41+import org.robolectric.annotation.Config;
42+import org.robolectric.shadow.api.Shadow;
4043 import org.robolectric.util.ReflectionHelpers;
4144
4245 @RunWith(RobolectricTestRunner.class)
46+@Config(shadows = ShadowNfcAdapter.class)
4347 public class NfcAndPaymentFragmentControllerTest {
4448 private NfcAndPaymentFragmentController mController;
4549 private Context mContext;
@@ -50,29 +54,28 @@ public class NfcAndPaymentFragmentControllerTest {
5054 private UserManager mUserManager;
5155 @Mock
5256 private NfcManager mNfcManager;
53- @Mock
54- private NfcAdapter mNfcAdapter;
57+
58+ private ShadowNfcAdapter mShadowNfcAdapter;
5559
5660 @Before
5761 public void setUp() {
5862 MockitoAnnotations.initMocks(this);
5963 mContext = spy(RuntimeEnvironment.application);
64+ mShadowNfcAdapter = Shadow.extract(NfcAdapter.getDefaultAdapter(mContext));
6065
6166 when(mContext.getApplicationContext()).thenReturn(mContext);
6267 when(mContext.getPackageManager()).thenReturn(mPackageManager);
6368 when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
6469 when(mContext.getSystemService(Context.NFC_SERVICE)).thenReturn(mNfcManager);
65- when(NfcAdapter.getDefaultAdapter(mContext)).thenReturn(mNfcAdapter);
6670
6771 mController = new NfcAndPaymentFragmentController(mContext, "fakeKey");
68- ReflectionHelpers.setField(mController, "mNfcAdapter", mNfcAdapter);
6972 }
7073
7174 @Test
7275 public void getAvailabilityStatus_hasNfc_shouldReturnAvailable() {
7376 when(mPackageManager.hasSystemFeature(anyString())).thenReturn(true);
7477 when(mUserManager.isAdminUser()).thenReturn(true);
75- when(mNfcAdapter.isEnabled()).thenReturn(true);
78+ mShadowNfcAdapter.setEnabled(true);
7679
7780 assertThat(mController.getAvailabilityStatus())
7881 .isEqualTo(NfcAndPaymentFragmentController.AVAILABLE);
@@ -87,14 +90,14 @@ public class NfcAndPaymentFragmentControllerTest {
8790
8891 @Test
8992 public void getSummary_nfcOn_shouldProvideOnSummary() {
90- when(mNfcAdapter.isEnabled()).thenReturn(true);
93+ mShadowNfcAdapter.setEnabled(true);
9194 assertThat(mController.getSummary().toString()).contains(
9295 mContext.getString(R.string.switch_on_text));
9396 }
9497
9598 @Test
9699 public void getSummary_nfcOff_shouldProvideOffSummary() {
97- when(mNfcAdapter.isEnabled()).thenReturn(false);
100+ mShadowNfcAdapter.setEnabled(false);
98101 assertThat(mController.getSummary().toString()).contains(
99102 mContext.getString(R.string.switch_off_text));
100103 }
--- a/tests/robotests/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/NfcAndPaymentFragmentTest.java
@@ -22,9 +22,12 @@ import static org.mockito.Mockito.spy;
2222 import static org.mockito.Mockito.when;
2323
2424 import android.content.Context;
25+import android.content.pm.PackageManager;
2526 import android.nfc.NfcAdapter;
2627 import android.provider.SearchIndexableResource;
2728
29+import com.android.settings.testutils.shadow.ShadowNfcAdapter;
30+
2831 import org.junit.Before;
2932 import org.junit.Test;
3033 import org.junit.runner.RunWith;
@@ -32,16 +35,20 @@ import org.mockito.Mock;
3235 import org.mockito.MockitoAnnotations;
3336 import org.robolectric.RobolectricTestRunner;
3437 import org.robolectric.RuntimeEnvironment;
38+import org.robolectric.annotation.Config;
39+import org.robolectric.shadow.api.Shadow;
3540
3641 import java.util.List;
3742
3843 @RunWith(RobolectricTestRunner.class)
44+@Config(shadows = ShadowNfcAdapter.class)
3945 public class NfcAndPaymentFragmentTest {
46+ @Mock
47+ private PackageManager mPackageManager;
48+
4049 private NfcAndPaymentFragment mFragment;
4150 private Context mContext;
42-
43- @Mock
44- private NfcAdapter mNfcAdapter;
51+ private ShadowNfcAdapter mShadowNfcAdapter;
4552
4653 @Before
4754 public void setUp() {
@@ -49,6 +56,9 @@ public class NfcAndPaymentFragmentTest {
4956
5057 mFragment = new NfcAndPaymentFragment();
5158 mContext = spy(RuntimeEnvironment.application);
59+ mShadowNfcAdapter = Shadow.extract(NfcAdapter.getDefaultAdapter(mContext));
60+
61+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
5262 }
5363
5464 @Test
@@ -64,8 +74,10 @@ public class NfcAndPaymentFragmentTest {
6474 @Test
6575 public void searchIndexProvider_shouldIndexValidItems() {
6676 when(mContext.getApplicationContext()).thenReturn(mContext);
67- when(NfcAdapter.getDefaultAdapter(mContext)).thenReturn(mNfcAdapter);
68- when(mNfcAdapter.isSecureNfcSupported()).thenReturn(true);
77+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
78+ when(mPackageManager.hasSystemFeature(
79+ PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)).thenReturn(true);
80+ mShadowNfcAdapter.setSecureNfcSupported(true);
6981
7082 final List<String> niks = NfcAndPaymentFragment.SEARCH_INDEX_DATA_PROVIDER
7183 .getNonIndexableKeys(mContext);
--- a/tests/robotests/src/com/android/settings/nfc/AndroidBeamPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/AndroidBeamPreferenceControllerTest.java
@@ -31,6 +31,7 @@ import android.provider.Settings;
3131
3232 import androidx.preference.PreferenceScreen;
3333
34+import com.android.settings.testutils.shadow.ShadowNfcAdapter;
3435 import com.android.settingslib.RestrictedLockUtilsInternal;
3536 import com.android.settingslib.RestrictedPreference;
3637
@@ -41,19 +42,20 @@ import org.mockito.Mock;
4142 import org.mockito.MockitoAnnotations;
4243 import org.robolectric.RobolectricTestRunner;
4344 import org.robolectric.RuntimeEnvironment;
45+import org.robolectric.annotation.Config;
46+import org.robolectric.shadow.api.Shadow;
4447 import org.robolectric.util.ReflectionHelpers;
4548
4649 import java.util.ArrayList;
4750 import java.util.List;
4851
4952 @RunWith(RobolectricTestRunner.class)
53+@Config(shadows = ShadowNfcAdapter.class)
5054 public class AndroidBeamPreferenceControllerTest {
5155
5256 Context mContext;
5357 @Mock
54- private NfcAdapter mNfcAdapter;
55- @Mock
56- NfcManager mManager;
58+ NfcManager mNfcManager;
5759 @Mock
5860 private UserManager mUserManager;
5961 @Mock
@@ -63,18 +65,19 @@ public class AndroidBeamPreferenceControllerTest {
6365
6466 private RestrictedPreference mAndroidBeamPreference;
6567 private AndroidBeamPreferenceController mAndroidBeamController;
68+ private ShadowNfcAdapter mShadowNfcAdapter;
6669
6770 @Before
6871 public void setUp() {
6972 MockitoAnnotations.initMocks(this);
7073 mContext = spy(RuntimeEnvironment.application);
74+ mShadowNfcAdapter = Shadow.extract(NfcAdapter.getDefaultAdapter(mContext));
7175
7276 when(mContext.getApplicationContext()).thenReturn(mContext);
7377 when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
74- when(mContext.getSystemService(Context.NFC_SERVICE)).thenReturn(mManager);
78+ when(mContext.getSystemService(Context.NFC_SERVICE)).thenReturn(mNfcManager);
7579 when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
7680 UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId())).thenReturn(false);
77- when(NfcAdapter.getDefaultAdapter(mContext)).thenReturn(mNfcAdapter);
7881
7982 mAndroidBeamController = new AndroidBeamPreferenceController(mContext,
8083 AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
@@ -95,13 +98,13 @@ public class AndroidBeamPreferenceControllerTest {
9598
9699 @Test
97100 public void isAvailable_hasNfc_shouldReturnTrue() {
98- when(mNfcAdapter.isEnabled()).thenReturn(true);
101+ mShadowNfcAdapter.setEnabled(true);
99102 assertThat(mAndroidBeamController.isAvailable()).isTrue();
100103 }
101104
102105 @Test
103106 public void isAvailable_noNfcFeature_shouldReturnFalse() {
104- when(mNfcAdapter.isEnabled()).thenReturn(true);
107+ mShadowNfcAdapter.setEnabled(true);
105108 when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM)).thenReturn(false);
106109 assertThat(mAndroidBeamController.isAvailable()).isFalse();
107110 }
@@ -114,7 +117,7 @@ public class AndroidBeamPreferenceControllerTest {
114117
115118 @Test
116119 public void isBeamEnable_disAllowBeam_shouldReturnFalse() {
117- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_OFF);
120+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_OFF);
118121
119122 when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
120123 UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId())).thenReturn(true);
@@ -125,7 +128,7 @@ public class AndroidBeamPreferenceControllerTest {
125128
126129 @Test
127130 public void isBeamEnable_nfcStateOn_shouldReturnTrue() {
128- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_ON);
131+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_ON);
129132 try {
130133 mAndroidBeamController.onResume();
131134 } catch (NullPointerException e) {
@@ -137,22 +140,22 @@ public class AndroidBeamPreferenceControllerTest {
137140
138141 @Test
139142 public void isBeamEnable_nfcStateNotOn_shouldReturnFalse() {
140- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_OFF);
143+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_OFF);
141144 mAndroidBeamController.onResume();
142145 assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
143146
144- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_TURNING_ON);
147+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_TURNING_ON);
145148 mAndroidBeamController.onResume();
146149 assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
147150
148- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_TURNING_OFF);
151+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_TURNING_OFF);
149152 mAndroidBeamController.onResume();
150153 assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
151154 }
152155
153156 @Test
154157 public void updateNonIndexableKeys_available_shouldNotUpdate() {
155- when(mNfcAdapter.isEnabled()).thenReturn(true);
158+ mShadowNfcAdapter.setEnabled(true);
156159 final List<String> keys = new ArrayList<>();
157160
158161 mAndroidBeamController.updateNonIndexableKeys(keys);
--- a/tests/robotests/src/com/android/settings/nfc/NfcPaymentPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/NfcPaymentPreferenceControllerTest.java
@@ -29,6 +29,7 @@ import androidx.preference.PreferenceScreen;
2929
3030 import com.android.settings.R;
3131 import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
32+import com.android.settings.testutils.shadow.ShadowNfcAdapter;
3233
3334 import org.junit.Before;
3435 import org.junit.Test;
@@ -37,10 +38,12 @@ import org.mockito.Mock;
3738 import org.mockito.MockitoAnnotations;
3839 import org.robolectric.RobolectricTestRunner;
3940 import org.robolectric.RuntimeEnvironment;
41+import org.robolectric.annotation.Config;
4042
4143 import java.util.ArrayList;
4244
4345 @RunWith(RobolectricTestRunner.class)
46+@Config(shadows = ShadowNfcAdapter.class)
4447 public class NfcPaymentPreferenceControllerTest {
4548
4649 private static final String PREF_KEY = PaymentSettingsTest.PAYMENT_KEY;
--- a/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
@@ -35,6 +35,7 @@ import androidx.preference.SwitchPreference;
3535
3636 import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker;
3737 import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker.NfcUpdateReceiver;
38+import com.android.settings.testutils.shadow.ShadowNfcAdapter;
3839
3940 import org.junit.Before;
4041 import org.junit.Test;
@@ -43,17 +44,18 @@ import org.mockito.Mock;
4344 import org.mockito.MockitoAnnotations;
4445 import org.robolectric.RobolectricTestRunner;
4546 import org.robolectric.RuntimeEnvironment;
47+import org.robolectric.annotation.Config;
48+import org.robolectric.shadow.api.Shadow;
4649 import org.robolectric.util.ReflectionHelpers;
4750
4851 import java.util.ArrayList;
4952 import java.util.List;
5053
5154 @RunWith(RobolectricTestRunner.class)
55+@Config(shadows = ShadowNfcAdapter.class)
5256 public class NfcPreferenceControllerTest {
5357
5458 @Mock
55- private NfcAdapter mNfcAdapter;
56- @Mock
5759 NfcManager mManager;
5860 @Mock
5961 private UserManager mUserManager;
@@ -63,16 +65,19 @@ public class NfcPreferenceControllerTest {
6365 private Context mContext;
6466 private SwitchPreference mNfcPreference;
6567 private NfcPreferenceController mNfcController;
68+ private ShadowNfcAdapter mShadowNfcAdapter;
69+ private NfcAdapter mNfcAdapter;
6670
6771 @Before
6872 public void setUp() {
6973 MockitoAnnotations.initMocks(this);
7074 mContext = spy(RuntimeEnvironment.application);
75+ mShadowNfcAdapter = Shadow.extract(NfcAdapter.getDefaultAdapter(mContext));
76+ mNfcAdapter = NfcAdapter.getDefaultAdapter(mContext);
7177
7278 when(mContext.getApplicationContext()).thenReturn(mContext);
7379 when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
7480 when(mContext.getSystemService(Context.NFC_SERVICE)).thenReturn(mManager);
75- when(NfcAdapter.getDefaultAdapter(mContext)).thenReturn(mNfcAdapter);
7681
7782 mNfcController = new NfcPreferenceController(mContext,
7883 NfcPreferenceController.KEY_TOGGLE_NFC);
@@ -83,7 +88,7 @@ public class NfcPreferenceControllerTest {
8388
8489 @Test
8590 public void getAvailabilityStatus_hasNfc_shouldReturnAvailable() {
86- when(mNfcAdapter.isEnabled()).thenReturn(true);
91+ mShadowNfcAdapter.setEnabled(true);
8792 assertThat(mNfcController.getAvailabilityStatus())
8893 .isEqualTo(NfcPreferenceController.AVAILABLE);
8994 }
@@ -98,11 +103,11 @@ public class NfcPreferenceControllerTest {
98103 @Test
99104 public void isNfcEnable_nfcStateNotTurning_shouldReturnTrue() {
100105 mNfcController.displayPreference(mScreen);
101- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_ON);
106+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_ON);
102107 mNfcController.onResume();
103108 assertThat(mNfcPreference.isEnabled()).isTrue();
104109
105- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_OFF);
110+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_OFF);
106111 mNfcController.onResume();
107112 assertThat(mNfcPreference.isEnabled()).isTrue();
108113 }
@@ -110,11 +115,11 @@ public class NfcPreferenceControllerTest {
110115 @Test
111116 public void isNfcEnable_nfcStateTurning_shouldReturnFalse() {
112117 mNfcController.displayPreference(mScreen);
113- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_TURNING_ON);
118+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_TURNING_ON);
114119 mNfcController.onResume();
115120 assertThat(mNfcPreference.isEnabled()).isFalse();
116121
117- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_TURNING_OFF);
122+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_TURNING_OFF);
118123 mNfcController.onResume();
119124 assertThat(mNfcPreference.isEnabled()).isFalse();
120125 }
@@ -122,29 +127,29 @@ public class NfcPreferenceControllerTest {
122127 @Test
123128 public void isNfcChecked_nfcStateOn_shouldReturnTrue() {
124129 mNfcController.displayPreference(mScreen);
125- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_ON);
130+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_ON);
126131 mNfcController.onResume();
127132 assertThat(mNfcPreference.isChecked()).isTrue();
128133
129- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_TURNING_ON);
134+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_TURNING_ON);
130135 mNfcController.onResume();
131136 assertThat(mNfcPreference.isChecked()).isTrue();
132137 }
133138
134139 @Test
135140 public void isNfcChecked_nfcStateOff_shouldReturnFalse() {
136- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_OFF);
141+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_OFF);
137142 mNfcController.onResume();
138143 assertThat(mNfcPreference.isChecked()).isFalse();
139144
140- when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_TURNING_OFF);
145+ mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_TURNING_OFF);
141146 mNfcController.onResume();
142147 assertThat(mNfcPreference.isChecked()).isFalse();
143148 }
144149
145150 @Test
146151 public void updateNonIndexableKeys_available_shouldNotUpdate() {
147- when(mNfcAdapter.isEnabled()).thenReturn(true);
152+ mShadowNfcAdapter.setEnabled(true);
148153 final List<String> keys = new ArrayList<>();
149154
150155 mNfcController.updateNonIndexableKeys(keys);
@@ -167,7 +172,7 @@ public class NfcPreferenceControllerTest {
167172 mNfcController.setChecked(true);
168173 mNfcController.onResume();
169174
170- verify(mNfcAdapter).enable();
175+ assertThat(mNfcAdapter.isEnabled()).isTrue();
171176 }
172177
173178 @Test
@@ -175,7 +180,7 @@ public class NfcPreferenceControllerTest {
175180 mNfcController.setChecked(false);
176181 mNfcController.onResume();
177182
178- verify(mNfcAdapter).disable();
183+ assertThat(mNfcAdapter.isEnabled()).isFalse();
179184 }
180185
181186 @Test
--- a/tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java
@@ -33,6 +33,8 @@ import androidx.preference.Preference;
3333 import androidx.preference.PreferenceManager;
3434 import androidx.preference.PreferenceScreen;
3535
36+import com.android.settings.testutils.shadow.ShadowNfcAdapter;
37+
3638 import org.junit.Before;
3739 import org.junit.Test;
3840 import org.junit.runner.RunWith;
@@ -48,7 +50,7 @@ import java.util.ArrayList;
4850 import java.util.List;
4951
5052 @RunWith(RobolectricTestRunner.class)
51-@Config(shadows = PaymentSettingsTest.ShadowPaymentBackend.class)
53+@Config(shadows = {PaymentSettingsTest.ShadowPaymentBackend.class, ShadowNfcAdapter.class})
5254 public class PaymentSettingsTest {
5355
5456 static final String PAYMENT_KEY = "nfc_payment";
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowNfcAdapter.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowNfcAdapter.java
@@ -16,6 +16,8 @@
1616
1717 package com.android.settings.testutils.shadow;
1818
19+import static org.robolectric.shadow.api.Shadow.newInstanceOf;
20+
1921 import android.app.Activity;
2022 import android.content.Context;
2123 import android.nfc.NfcAdapter;
@@ -24,16 +26,18 @@ import android.os.Bundle;
2426 import org.robolectric.annotation.Implementation;
2527 import org.robolectric.annotation.Implements;
2628 import org.robolectric.annotation.Resetter;
27-import org.robolectric.util.ReflectionHelpers;
28-import org.robolectric.util.ReflectionHelpers.ClassParameter;
2929
3030 /**
3131 * Shadow of {@link NfcAdapter}.
3232 */
33-@Implements(NfcAdapter.class)
34-public class ShadowNfcAdapter {
33+@Implements(value = NfcAdapter.class)
34+public class ShadowNfcAdapter extends org.robolectric.shadows.ShadowNfcAdapter {
3535 private static boolean sReaderModeEnabled;
36+ private static Object sNfcAdapter = newInstanceOf("android.nfc.NfcAdapter");
37+
3638 private boolean mIsNfcEnabled = false;
39+ private int mState = NfcAdapter.STATE_ON;
40+ private boolean mIsSecureNfcSupported = false;
3741
3842 @Implementation
3943 protected void enableReaderMode(Activity activity, NfcAdapter.ReaderCallback callback,
@@ -43,8 +47,7 @@ public class ShadowNfcAdapter {
4347
4448 @Implementation
4549 protected static NfcAdapter getDefaultAdapter(Context context) {
46- return ReflectionHelpers.callConstructor(
47- NfcAdapter.class, ClassParameter.from(Context.class, context));
50+ return (NfcAdapter) sNfcAdapter;
4851 }
4952
5053 @Implementation
@@ -52,6 +55,28 @@ public class ShadowNfcAdapter {
5255 return mIsNfcEnabled;
5356 }
5457
58+ public void setEnabled(boolean enable) {
59+ mIsNfcEnabled = enable;
60+ }
61+
62+ @Implementation
63+ protected int getAdapterState() {
64+ return mState;
65+ }
66+
67+ public void setAdapterState(int state) {
68+ this.mState = state;
69+ }
70+
71+ @Implementation
72+ protected boolean isSecureNfcSupported() {
73+ return mIsSecureNfcSupported;
74+ }
75+
76+ public void setSecureNfcSupported(boolean supported) {
77+ this.mIsSecureNfcSupported = supported;
78+ }
79+
5580 @Implementation
5681 protected boolean enable() {
5782 mIsNfcEnabled = true;