예제 #1
0
  @Test
  public void testGetQueryResult() throws QueryCacheMissException {
    Query q1 = new Query().addWord("hoi");
    Query q2 = new Query().addWord("hoi");
    String result = "my result";
    q1.addResult(result);

    QueryCache qc = new QueryCache();
    qc.addQuery(q1);
    assertEquals(result, qc.getResultForQuery(q1));
    assertEquals(result, qc.getResultForQuery(q2));
  }
예제 #2
0
 @Test
 public void testAddDuplicateQuery() throws QueryCacheMissException {
   Query q1 = new Query().addWord("hoi");
   Query q2 = new Query().addWord("hoi");
   String expectedResult = "my result";
   q1.addResult(expectedResult);
   String notExpectedResult = "another result";
   q2.addResult(notExpectedResult);
   QueryCache qc = new QueryCache();
   qc.addQuery(q1);
   qc.addQuery(q2);
   assertEquals(expectedResult, qc.getResultForQuery(q1));
   assertEquals(expectedResult, qc.getResultForQuery(q2));
 }
예제 #3
0
  @Test
  public void testHasQuery() {
    Query q1 = new Query().addWord("hoi");
    Query q2 = new Query().addWord("hoi");
    Query notAMatch = new Query().addWord("another word");

    q1.addResult("a res");
    QueryCache qc = new QueryCache();
    qc.addQuery(q1);

    assertTrue(qc.hasQuery(q1));
    assertTrue(qc.hasQuery(q2));
    assertFalse(qc.hasQuery(notAMatch));
  }
예제 #4
0
 @Test(expected = QueryCacheMissException.class)
 public void testThrowsCacheMiss() throws QueryCacheMissException {
   QueryCache qc = new QueryCache();
   qc.getResultForQuery(new Query().addWord("hoi"));
 }