Fix a NPE from incorrect assumption of operation pecedence.

Change-Id: I13d01c39bd3afcfbc7b680b96e0c7eb341fbc584
Fixes: 123709444
Test: robotest
This commit is contained in:
Fan Zhang
2019-01-31 13:48:40 -08:00
parent f508a57ab5
commit b617f84b32
2 changed files with 7 additions and 2 deletions

View File

@@ -128,8 +128,10 @@ public class LegacySuggestionContextualCardController implements ContextualCardC
return;
}
final List<Suggestion> suggestions = mSuggestionController.getSuggestions();
Log.d(TAG, "Loaded suggests: "
+ suggestions == null ? "null" : String.valueOf(suggestions.size()));
final String suggestionCount = suggestions == null
? "null"
: String.valueOf(suggestions.size());
Log.d(TAG, "Loaded suggests: " + suggestionCount);
final List<ContextualCard> cards = new ArrayList<>();
if (suggestions != null) {

View File

@@ -19,6 +19,7 @@ package com.android.settings.homepage.contextualcards.legacysuggestion;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -84,8 +85,10 @@ public class LegacySuggestionContextualCardControllerTest {
@Test
public void onServiceConnected_shouldLoadSuggestion() {
when(mSuggestionController.getSuggestions()).thenReturn(null);
mController.mSuggestionController = mSuggestionController;
mController.setCardUpdateListener(mCardUpdateListener);
mController.onServiceConnected();
verify(mSuggestionController).getSuggestions();