View Javadoc
1   package emissary.util.search;
2   
3   import org.junit.jupiter.api.Test;
4   
5   import static org.junit.jupiter.api.Assertions.assertEquals;
6   import static org.junit.jupiter.api.Assertions.assertThrows;
7   
8   class BackwardsTreeScannerTest {
9   
10      private final String[] defaultKeywords = {"fox", "dog"};
11      private static final String DEFAULT_DATA = "the quick brown fox jumped over the lazy dog";
12  
13      @Test
14      void testBothConstructors() throws Exception {
15          HitList hits = new HitList();
16          BackwardsTreeScanner first = new BackwardsTreeScanner();
17          first.resetKeywords(defaultKeywords);
18          int result = first.scan(DEFAULT_DATA.getBytes(), DEFAULT_DATA.length() - 1, hits);
19          assertEquals(39, result);
20  
21          hits = new HitList();
22          BackwardsTreeScanner second = new BackwardsTreeScanner(defaultKeywords);
23          result = second.scan(DEFAULT_DATA.getBytes(), DEFAULT_DATA.length() - 1, hits);
24          assertEquals(39, result);
25      }
26  
27      @Test
28      void testExpectedException() throws Exception {
29          HitList hits = new HitList();
30          BackwardsTreeScanner second = new BackwardsTreeScanner(defaultKeywords);
31          assertThrows(Exception.class, () -> second.scan(null, DEFAULT_DATA.length() - 1, hits));
32      }
33  }