1 25 26 package org.snipsnap.test.commons; 27 28 import junit.framework.Test; 29 import junit.framework.TestCase; 30 import junit.framework.TestSuite; 31 import org.snipsnap.cache.QueryList; 32 import org.snipsnap.snip.storage.query.Query; 33 34 import java.util.ArrayList ; 35 import java.util.List ; 36 37 public class QueryListTest extends TestCase { 38 protected QueryList list; 39 40 public QueryListTest(String name) { 41 super(name); 42 } 43 44 public abstract class IntegerQuery implements Query { 45 public boolean fit(Object object) { 46 if (!(object instanceof Integer )) { return false; } 47 return fit((Integer ) object); 48 } 49 50 public abstract boolean fit(Integer i); 51 } 52 53 protected void setUp() throws Exception { 54 list = new QueryList(new ArrayList ()); 55 list.add(new Integer (1)); 56 list.add(new Integer (5)); 57 list.add(new Integer (2)); 58 super.setUp(); 59 } 60 61 public static Test suite() { 62 return new TestSuite(QueryListTest.class); 63 } 64 65 public void testQuery() { 66 List test = new ArrayList (); 67 test.add(new Integer (2)); 68 assertEquals("Query returns correct result", test, list.query( 69 new IntegerQuery() { 70 public boolean fit(Integer i) { 71 return i.intValue() == 2; 72 } 73 } 74 )); 75 } 76 } 77 | Popular Tags |