01: /*
02: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package org.mandarax.reference.validation;
20:
21: import java.util.Iterator;
22: import org.mandarax.kernel.KnowledgeBase;
23: import junit.framework.*;
24:
25: /**
26: * Utility to convert a kb to a JUnit test suite.
27: * This test suite can then be used with one of the JUnit test runners to validate the KB.
28: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
29: * @version 3.4 <7 March 05>
30: * @since 3.4
31: */
32: public class KB2TestSuite {
33:
34: /**
35: * Converts a knowledge base into a JUnit test suite.
36: * @param kb a knowledge base
37: * @return a test suite
38: * @throws an exception if one of the (mandarax) test cases cannot be casted to a JUnit test case
39: */
40: public static Test suite(KnowledgeBase kb) throws Exception {
41: TestSuite suite = new TestSuite();
42: for (Iterator iter = kb.testcases(); iter.hasNext();) {
43: Object next = iter.next();
44: suite.addTest((junit.framework.TestCase) next);// not all mandarax test cases are junit test cases, but the default implementation is
45: }
46: return suite;
47: }
48: }
|