Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10ba1f1e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE when calling getSuggestionV2 in adapter."

parents bfb67139 45424c54
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -220,6 +220,9 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>

    public Tile getSuggestion(int position) {
        final long itemId = getItemId(position);
        if (mSuggestions == null) {
            return null;
        }
        for (Tile tile : mSuggestions) {
            if (Objects.hash(tile.title) == itemId) {
                return tile;
@@ -230,6 +233,9 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>

    public Suggestion getSuggestionsV2(int position) {
        final long itemId = getItemId(position);
        if (mSuggestionsV2 == null) {
            return null;
        }
        for (Suggestion suggestion : mSuggestionsV2) {
            if (Objects.hash(suggestion.getId()) == itemId) {
                return suggestion;
+17 −1
Original line number Diff line number Diff line
@@ -233,6 +233,22 @@ public class SuggestionAdapterTest {
        assertThat(itemView.getChildCount()).isEqualTo(1);
    }

    @Test
    public void getSuggestionsV2_shouldReturnSuggestionWhenMatch() {
        final List<Suggestion> suggestionsV2 = makeSuggestionsV2("pkg1");
        setupSuggestions(mActivity, null /* suggestionV1 */, suggestionsV2);

        assertThat(mSuggestionAdapter.getSuggestion(0)).isNull();
        assertThat(mSuggestionAdapter.getSuggestionsV2(0)).isNotNull();

        List<Tile> suggestionsV1 = makeSuggestions("pkg1");
        setupSuggestions(mActivity, suggestionsV1, null /* suggestionV2 */);

        assertThat(mSuggestionAdapter.getSuggestionsV2(0)).isNull();
        assertThat(mSuggestionAdapter.getSuggestion(0)).isNotNull();

    }

    private void setupSuggestions(Context context, List<Tile> suggestions,
            List<Suggestion> suggestionsV2) {
        mSuggestionAdapter = new SuggestionAdapter(context, suggestions, suggestionsV2,