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:
@@ -67,7 +67,7 @@ public abstract class BaseNfcPreferenceController extends AbstractPreferenceCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateNonIndexableKeys(List<String> keys) {
|
public void updateNonIndexableKeys(List<String> keys) {
|
||||||
if (isAvailable()) {
|
if (!isAvailable()) {
|
||||||
keys.add(getPreferenceKey());
|
keys.add(getPreferenceKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -78,7 +78,6 @@ public class ConnectedDeviceDashboardFragmentTest {
|
|||||||
final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
|
final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||||
.getNonIndexableKeys(mContext);
|
.getNonIndexableKeys(mContext);
|
||||||
|
|
||||||
assertThat(niks).containsExactly(KEY_CONNECTED_DEVICES, KEY_AVAILABLE_DEVICES,
|
assertThat(niks).containsExactly(KEY_CONNECTED_DEVICES, KEY_AVAILABLE_DEVICES);
|
||||||
NfcPreferenceController.KEY_TOGGLE_NFC);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,9 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class AndroidBeamPreferenceControllerTest {
|
public class AndroidBeamPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -132,4 +135,24 @@ public class AndroidBeamPreferenceControllerTest {
|
|||||||
mAndroidBeamController.onResume();
|
mAndroidBeamController.onResume();
|
||||||
assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
|
assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateNonIndexableKeys_available_shouldNotUpdate() {
|
||||||
|
when(mNfcAdapter.isEnabled()).thenReturn(true);
|
||||||
|
final List<String> keys = new ArrayList<>();
|
||||||
|
|
||||||
|
mAndroidBeamController.updateNonIndexableKeys(keys);
|
||||||
|
|
||||||
|
assertThat(keys).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateNonIndexableKeys_notAvailable_shouldUpdate() {
|
||||||
|
ReflectionHelpers.setField(mAndroidBeamController, "mNfcAdapter", null);
|
||||||
|
final List<String> keys = new ArrayList<>();
|
||||||
|
|
||||||
|
mAndroidBeamController.updateNonIndexableKeys(keys);
|
||||||
|
|
||||||
|
assertThat(keys).hasSize(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,9 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class NfcPreferenceControllerTest {
|
public class NfcPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -134,4 +137,24 @@ public class NfcPreferenceControllerTest {
|
|||||||
mNfcController.onResume();
|
mNfcController.onResume();
|
||||||
assertThat(mNfcPreference.isChecked()).isFalse();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user