1+ import org .junit .Test ;
2+
3+ import java .util .HashSet ;
4+ import java .util .LinkedHashMap ;
5+
6+ import static org .junit .Assert .*;
7+
8+ /**
9+ * Created by Simon on 07/12/15.
10+ */
11+ public class SearcherTest {
12+
13+ @ Test
14+ public void testSearch () throws Exception {
15+ // test 'simple' search
16+ LinkedHashMap <String , HashSet > hashMap = new LinkedHashMap <String , HashSet >();
17+ Setup .addEntryToHashMap (hashMap , "word" , "testUrl" );
18+ HashSet <String > results = Searcher .search ("word" , hashMap );
19+ assertTrue (results .contains ("testUrl" ));
20+
21+ // test 'or' search
22+ LinkedHashMap <String , HashSet > hashMap2 = new LinkedHashMap <String , HashSet >();
23+ Setup .addEntryToHashMap (hashMap2 , "word" , "testUrl" );
24+ Setup .addEntryToHashMap (hashMap2 , "word2" , "testUrl2" );
25+ HashSet <String > results2 = Searcher .search ("word OR word2" , hashMap2 );
26+ assertTrue (results2 .contains ("testUrl" ) && results2 .contains ("testUrl2" ));
27+
28+ // test 'and' search
29+ LinkedHashMap <String , HashSet > hashMap3 = new LinkedHashMap <String , HashSet >();
30+ Setup .addEntryToHashMap (hashMap3 , "word" , "testUrl" );
31+ Setup .addEntryToHashMap (hashMap3 , "word2" , "testUrl2" );
32+ HashSet <String > results3 = Searcher .search ("word AND word2" , hashMap3 );
33+ assertTrue (results3 .isEmpty ());
34+
35+ Setup .addEntryToHashMap (hashMap3 , "word2" , "testUrl" );
36+ HashSet <String > results4 = Searcher .search ("word AND word2" , hashMap3 );
37+ assertTrue (results4 .contains ("testUrl" ));
38+ }
39+ }
0 commit comments