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 17package com.android.quicksearchbox; 18 19import com.android.quicksearchbox.util.Consumer; 20 21import java.util.Collection; 22import java.util.Map; 23 24/** 25 * Mock implementation of {@link ShortcutRepository}. 26 * 27 */ 28public class MockShortcutRepository implements ShortcutRepository { 29 30 private Map<String, Integer> mCorpusScores; 31 32 public void setCorpusScores(Map<String, Integer> corpusScores) { 33 mCorpusScores = corpusScores; 34 } 35 36 public void clearHistory() { 37 } 38 39 public void removeFromHistory(SuggestionCursor suggestions, int position) { 40 } 41 42 public void close() { 43 } 44 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 */ 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 62 public void updateShortcut(Source source, String shortcutId, SuggestionCursor refreshed) { 63 } 64 65 public void getCorpusScores(Consumer<Map<String, Integer>> consumer) { 66 consumer.consume(mCorpusScores); 67 } 68 69 public void hasHistory(Consumer<Boolean> consumer) { 70 consumer.consume(false); 71 } 72 73 public void reportClick(SuggestionCursor suggestions, int position) { 74 } 75 76} 77