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 Config config = new Config(mContext); 38 MockSources sources = new MockSources(); 39 sources.addSource(MockSource.SOURCE_1); 40 sources.addSource(MockSource.SOURCE_2); 41 mCorpora = new SearchableCorpora(mContext, config, sources, new MockCorpusFactory()); 42 mCorpora.load(); 43 } 44 45 public void testGetAllCorpora() { 46 assertNotEmpty(mCorpora.getAllCorpora()); 47 } 48 49 public void testEnabledSuggestionSources() { 50 assertNotNull(mCorpora.getEnabledCorpora()); 51 } 52 53 public void testGetCorpusForSource() { 54 assertNotNull(mCorpora.getCorpusForSource(MockSource.SOURCE_1)); 55 assertNotNull(mCorpora.getCorpusForSource(MockSource.SOURCE_2)); 56 assertNull(mCorpora.getCorpusForSource(MockSource.SOURCE_3)); 57 } 58 59 static void assertEmpty(Collection<?> collection) { 60 assertNotNull(collection); 61 assertTrue(collection.isEmpty()); 62 } 63 64 static void assertNotEmpty(Collection<?> collection) { 65 assertNotNull(collection); 66 assertFalse(collection.isEmpty()); 67 } 68 69 } 70