Make Nfc/Beam searchable based on feature availability

Update logic of updateNonIndexableKeys,
in BaseNfcPreferenceController to fix issue.
Add robotest to avoid same problem.

Change-Id: I1de5324b5a7147ff58e3c366ee7e8cf858e3283c
Fixes: 78540155
Test: make RunSettingsRoboTests
This commit is contained in:
hjchangliao
2018-04-25 11:38:05 +08:00
committed by Fan Zhang
parent 6fcce25b72
commit 1ff466675d
4 changed files with 48 additions and 3 deletions

View File

@@ -39,6 +39,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
public class NfcPreferenceControllerTest {
@@ -134,4 +137,24 @@ public class NfcPreferenceControllerTest {
mNfcController.onResume();
assertThat(mNfcPreference.isChecked()).isFalse();
}
@Test
public void updateNonIndexableKeys_available_shouldNotUpdate() {
when(mNfcAdapter.isEnabled()).thenReturn(true);
final List<String> keys = new ArrayList<>();
mNfcController.updateNonIndexableKeys(keys);
assertThat(keys).isEmpty();
}
@Test
public void updateNonIndexableKeys_notAvailable_shouldUpdate() {
ReflectionHelpers.setField(mNfcController, "mNfcAdapter", null);
final List<String> keys = new ArrayList<>();
mNfcController.updateNonIndexableKeys(keys);
assertThat(keys).hasSize(1);
}
}