Fix NPE during unit test

As of ag/3932176 the slice indexer now queries getSummary() for each
controller. So we need to create all necessary objects before
getSummary(). In this case, the PSCD object.

Change-Id: I0162996be37d740f1e450880bf4698acd94ca0ad
Fixes: 78897071
Test: atest
This commit is contained in:
Fan Zhang
2018-04-30 13:41:56 -07:00
parent 8efbe6e255
commit 16de45d8ec
11 changed files with 63 additions and 63 deletions

View File

@@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.content.Intent;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@@ -35,6 +34,8 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import androidx.preference.Preference;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {ShadowPrivacySettingsUtils.class})
public class ConfigureAccountPreferenceControllerTest {
@@ -51,7 +52,7 @@ public class ConfigureAccountPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mPSCD = new PrivacySettingsConfigData();
mPSCD = PrivacySettingsConfigData.getInstance();
mController = new ConfigureAccountPreferenceController(mContext,
PrivacySettingsUtils.CONFIGURE_ACCOUNT);
mPreference = new Preference(mContext);
@@ -68,7 +69,7 @@ public class ConfigureAccountPreferenceControllerTest {
mPSCD.setBackupEnabled(true);
mPSCD.setBackupGray(false);
mPSCD.setConfigIntent(mIntent);
mController.setPrivacySettingsConfigData(mPSCD);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isTrue();
}
@@ -80,7 +81,7 @@ public class ConfigureAccountPreferenceControllerTest {
mPSCD.setBackupGray(false);
mPSCD.setConfigIntent(mIntent);
mPSCD.setConfigSummary(null);
mController.setPrivacySettingsConfigData(mPSCD);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.backup_configure_account_default_summary));
@@ -93,7 +94,7 @@ public class ConfigureAccountPreferenceControllerTest {
mPSCD.setBackupGray(false);
mPSCD.setConfigIntent(mIntent);
mPSCD.setConfigSummary(mTestSummary);
mController.setPrivacySettingsConfigData(mPSCD);
mController.updateState(mPreference);
assertThat(mPreference.getSummary()).isEqualTo(mTestSummary);
}