View Javadoc
1   package org.kuali.student.ap.coursesearch.controller;
2   
3   import org.junit.Before;
4   import org.junit.Test;
5   import org.kuali.student.ap.coursesearch.QueryTokenizer;
6   
7   import java.util.List;
8   
9   import static org.junit.Assert.assertEquals;
10  import static org.junit.Assert.assertTrue;
11  
12  public class QueryTokenizerImplTest {
13      String sample = " A abc123 edc&i \"quoted text !@#\" 0 00 000 0000 3xx 4XX ";
14      QueryTokenizer qt;
15  
16      @Before
17      public void setUp() {
18          qt = new QueryTokenizerImpl();
19      }
20  
21      @Test
22      public void testTokenize() throws Exception {
23          List<QueryTokenizer.Token> list = qt.tokenize(sample);
24          assertTrue( list.size() == 10 );
25          assertEquals( list.get( 2 ).rule, QueryTokenizer.Rule.WORD );
26          assertEquals( list.get( 2 ).value, "edc&i" );
27          assertEquals( list.get( 3 ).rule, QueryTokenizer.Rule.QUOTED );
28      }
29  
30      @Test
31      public void testIgnoreSpaces() throws Exception {
32          List<QueryTokenizer.Token> list = qt.tokenize("   A  B   C     D  ");
33          assertTrue( list.size() == 4 );
34          assertEquals( list.get( 3 ).rule, QueryTokenizer.Rule.WORD );
35      }
36  
37      @Test
38      public void testExtractCourseLevels() throws Exception {
39          List<String> levels = qt.extractCourseLevels(sample);
40          assertEquals( levels.get( 0 ), "3xx" );
41          assertEquals( levels.get( 1 ), "4XX" );
42      }
43  
44      @Test
45      public void testExtractCourseCodes() throws Exception {
46          List<String> levels = qt.extractCourseCodes(sample);
47          assertEquals( levels.get( 0 ), "123" );
48          assertEquals( levels.get( 1 ), "000" );
49      }
50  }