Home | History | Annotate | Download | only in quicksearchbox
      1 /*
      2  * Copyright (C) 2010 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 package com.android.quicksearchbox;
     17 
     18 import android.test.AndroidTestCase;
     19 import android.test.suitebuilder.annotation.SmallTest;
     20 
     21 import java.util.ArrayList;
     22 import java.util.Arrays;
     23 import java.util.List;
     24 
     25 /**
     26  * Tests for SingleCorpusPromoter.
     27  */
     28 @SmallTest
     29 public class SingleCorpusPromoterTest extends AndroidTestCase {
     30     public static final String TEST_QUERY = "query";
     31 
     32     private List<Corpus> mCorpora = Arrays.asList(MockCorpus.CORPUS_1, MockCorpus.CORPUS_2);
     33     private SingleCorpusPromoter mPromoter;
     34 
     35     @Override
     36     public void setUp() {
     37         mPromoter = new SingleCorpusPromoter(MockCorpus.CORPUS_1, 10);
     38     }
     39 
     40     public void testPromotesOnlyGivenCorpus() {
     41         Suggestions suggestions = makeSuggestions(TEST_QUERY);
     42 
     43         ListSuggestionCursor promoted = new ListSuggestionCursor(TEST_QUERY);
     44         mPromoter.pickPromoted(suggestions, 4, promoted);
     45 
     46         assertEquals(2, promoted.getCount());
     47 
     48         Source[] expectedSource = { MockSource.SOURCE_1, MockSource.SOURCE_1 };
     49 
     50         for (int i = 0; i < promoted.getCount(); i++) {
     51             promoted.moveTo(i);
     52             assertEquals("Source in position " + i,
     53                     expectedSource[i], promoted.getSuggestionSource());
     54         }
     55     }
     56 
     57     private Suggestions makeSuggestions(String query) {
     58         Suggestions suggestions = new Suggestions(query, mCorpora);
     59         ArrayList<CorpusResult> results = new ArrayList<CorpusResult>();
     60         for (Corpus corpus : mCorpora) {
     61             results.add(corpus.getSuggestions(query, 10, false));
     62         }
     63         suggestions.addCorpusResults(results);
     64         return suggestions;
     65     }
     66 
     67 }
     68