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 android.test.AndroidTestCase; 20 import android.test.suitebuilder.annotation.MediumTest; 21 22 import java.util.Collection; 23 24 /** 25 * Tests for {@link SearchableCorpora}. 26 * 27 */ 28 @MediumTest 29 public class SearchableCorporaTest extends AndroidTestCase { 30 31 protected SearchableCorpora mCorpora; 32 33 @Override 34 protected void setUp() throws Exception { 35 super.setUp(); 36 37 MockSources sources = new MockSources(); 38 sources.addSource(MockSource.SOURCE_1); 39 sources.addSource(MockSource.SOURCE_2); 40 mCorpora = new SearchableCorpora(mContext, sources, new MockCorpusFactory()); 41 mCorpora.update(); 42 } 43 44 public void testGetAllCorpora() { 45 assertNotEmpty(mCorpora.getAllCorpora()); 46 } 47 48 public void testEnabledSuggestionSources() { 49 assertNotNull(mCorpora.getEnabledCorpora()); 50 } 51 52 public void testGetCorpusForSource() { 53 assertNotNull(mCorpora.getCorpusForSource(MockSource.SOURCE_1)); 54 assertNotNull(mCorpora.getCorpusForSource(MockSource.SOURCE_2)); 55 assertNull(mCorpora.getCorpusForSource(MockSource.SOURCE_3)); 56 } 57 58 static void assertEmpty(Collection<?> collection) { 59 assertNotNull(collection); 60 assertTrue(collection.isEmpty()); 61 } 62 63 static void assertNotEmpty(Collection<?> collection) { 64 assertNotNull(collection); 65 assertFalse(collection.isEmpty()); 66 } 67 68 } 69