SuggestionsAdapter extends BaseAdapter { public void addSuggestions(final @NonNull SuggestionsResult result, final @NonNull String bucket, final @NonNull TokenSource source) { QueryToken query = result.getQueryToken(); synchronized (mLock) { mResultMap.put(bucket, result); Set<String> waitingForBuckets = mWaitingForResults.get(query); if (waitingForBuckets != null) { waitingForBuckets.remove(bucket); if (waitingForBuckets.size() == 0) { mWaitingForResults.remove(query); } } } String currentTokenString = source.getCurrentTokenString(); synchronized (mLock) { mSuggestions.clear(); List<Suggestible> suggestions = mSuggestionsListBuilder.buildSuggestions(mResultMap, currentTokenString); if (suggestions.size() > 0) { mSuggestions.addAll(suggestions); mSuggestionsVisibilityManager.displaySuggestions(true); } else { hideSuggestionsIfNecessary(result.getQueryToken(), source); } } notifyDataSetChanged(); } SuggestionsAdapter(final @NonNull Context context,
                              final @NonNull SuggestionsVisibilityManager suggestionsVisibilityManager,
                              final @NonNull SuggestionsListBuilder suggestionsListBuilder); void notifyQueryTokenReceived(@NonNull QueryToken queryToken,
                                         @NonNull List<String> buckets); void addSuggestions(final @NonNull SuggestionsResult result,
                               final @NonNull String bucket,
                               final @NonNull TokenSource source); void clear(); @Override int getCount(); @Override Suggestible getItem(int position); @Override long getItemId(int position); @Override View getView(int position, View convertView, ViewGroup parent); void setSuggestionsManager(final @NonNull SuggestionsVisibilityManager suggestionsVisibilityManager); void setSuggestionsListBuilder(final @NonNull SuggestionsListBuilder suggestionsListBuilder);  }
@Test public void testAddSuggestions() throws Exception { TestMention testMention1 = new TestMention("FirstName LastName"); addMentionToEditor(testMention1, "First", "Person"); assertEquals(1, mAdapter.getCount()); TestMention testMention2 = new TestMention("Second Name"); addMentionToEditor(testMention2, "Second", "Group"); assertEquals(1, mAdapter.getCount()); TestMention testMention3 = new TestMention("SecondName LastName"); addMentionToEditor(testMention3, "Second", "Person"); assertEquals(2, mAdapter.getCount()); }