@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)); }
@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)); }
@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)); }
@Test(expected = QueryCacheMissException.class) public void testThrowsCacheMiss() throws QueryCacheMissException { QueryCache qc = new QueryCache(); qc.getResultForQuery(new Query().addWord("hoi")); }