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