KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > test > commons > QueryListTest


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

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 JavaDoc;
35 import java.util.List JavaDoc;
36
37 public class QueryListTest extends TestCase {
38   protected QueryList list;
39
40   public QueryListTest(String JavaDoc name) {
41     super(name);
42   }
43
44   public abstract class IntegerQuery implements Query {
45     public boolean fit(Object JavaDoc object) {
46       if (!(object instanceof Integer JavaDoc)) { return false; }
47       return fit((Integer JavaDoc) object);
48     }
49
50     public abstract boolean fit(Integer JavaDoc i);
51   }
52
53   protected void setUp() throws Exception JavaDoc {
54     list = new QueryList(new ArrayList JavaDoc());
55     list.add(new Integer JavaDoc(1));
56     list.add(new Integer JavaDoc(5));
57     list.add(new Integer JavaDoc(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 JavaDoc();
67     test.add(new Integer JavaDoc(2));
68     assertEquals("Query returns correct result", test, list.query(
69         new IntegerQuery() {
70           public boolean fit(Integer JavaDoc i) {
71             return i.intValue() == 2;
72           }
73         }
74     ));
75   }
76 }
77
Popular Tags