1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.quicksearchbox; 18 19 import com.android.quicksearchbox.util.Consumer; 20 21 import java.util.Collection; 22 import java.util.Map; 23 24 /** 25 * Mock implementation of {@link ShortcutRepository}. 26 * 27 */ 28 public class MockShortcutRepository implements ShortcutRepository { 29 30 private Map<String, Integer> mCorpusScores; 31 setCorpusScores(Map<String, Integer> corpusScores)32 public void setCorpusScores(Map<String, Integer> corpusScores) { 33 mCorpusScores = corpusScores; 34 } 35 clearHistory()36 public void clearHistory() { 37 } 38 removeFromHistory(SuggestionCursor suggestions, int position)39 public void removeFromHistory(SuggestionCursor suggestions, int position) { 40 } 41 close()42 public void close() { 43 } 44 getShortcutsForQuery(String query, Collection<Corpus> corporaToQuery, boolean allowWebSearchShortcuts, Consumer<ShortcutCursor> consumer)45 public void getShortcutsForQuery(String query, Collection<Corpus> corporaToQuery, 46 boolean allowWebSearchShortcuts, Consumer<ShortcutCursor> consumer) { 47 ShortcutCursor cursor = getShortcutsForQuery(query, corporaToQuery); 48 consumer.consume(cursor); 49 } 50 51 /** 52 * Synchronous version for use in tests that just need a ShortcutCursor. 53 */ getShortcutsForQuery(String query, Collection<Corpus> corporaToQuery)54 public ShortcutCursor getShortcutsForQuery(String query, Collection<Corpus> corporaToQuery) { 55 // TODO: should look at corporaToQuery 56 ShortcutCursor cursor = new ShortcutCursor(query, null, null, null); 57 cursor.add(MockSource.SOURCE_1.createSuggestion(query + "_1_shortcut")); 58 cursor.add(MockSource.SOURCE_2.createSuggestion(query + "_2_shortcut")); 59 return cursor; 60 } 61 updateShortcut(Source source, String shortcutId, SuggestionCursor refreshed)62 public void updateShortcut(Source source, String shortcutId, SuggestionCursor refreshed) { 63 } 64 getCorpusScores(Consumer<Map<String, Integer>> consumer)65 public void getCorpusScores(Consumer<Map<String, Integer>> consumer) { 66 consumer.consume(mCorpusScores); 67 } 68 hasHistory(Consumer<Boolean> consumer)69 public void hasHistory(Consumer<Boolean> consumer) { 70 consumer.consume(false); 71 } 72 reportClick(SuggestionCursor suggestions, int position)73 public void reportClick(SuggestionCursor suggestions, int position) { 74 } 75 76 } 77