📄 wheretests.java
字号:
package test.org.mandarax.util.resultsetfilters;
/*
* Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.mandarax.kernel.InferenceException;
import org.mandarax.kernel.ResultSet;
import org.mandarax.util.resultsetfilters.*;
import junit.framework.TestSuite;
/**
* Test suite to test the where filter.
* @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
* @version 3.4 <7 March 05>
* @since 3.0
*/
public class WhereTests extends AbstractTestSuite {
private static Calendar calendar = GregorianCalendar.getInstance();
/**
* Launch the test suite. See TestRunner for interpretation
* of command line parameters.
* @see test.org.mandarax.testsupport.TestRunner
* @param args parameters
*/
public static void main(String[] args) {
test.org.mandarax.testsupport.TestRunner.run (WhereTests.class, args);
}
public static TestSuite suite() throws Exception {
/* test kb:
"Tom", "Meier", "01/01/1960", 80, 1.80;
"John", "Meier", "01/01/1960", 90, 1.90;
"Jim", "Smith", "01/01/1970", 100, 1.90;
"Jack", "Smith", "01/01/1970", 60, 1.60;
"Tom", "Taylor", "01/01/1980", 70, 1.70;
"John", "Meijer", "01/01/1980", 80, 1.80;
"Jim", "Mejer", "01/01/1990", 50, 1.50;
*/
TestSuite suite = new TestSuite("Test cases for the Where result set filter");
suite.addTest(new WhereTestCase(
"Where filter test case 1",
new ResultSetCondition(){
public boolean isSatisfiedBy(ResultSet rs) throws InferenceException {
Object value = rs.getResult(NAME);
return "Meier".equals(value);
}
},
new Object[][] {
convert("Tom", "Meier", "01/01/1960", 80, 1.80),
convert("John", "Meier", "01/01/1960", 90, 1.90)
}
));
suite.addTest(new WhereTestCase(
"Where filter test case 2",
new ResultSetCondition(){
public boolean isSatisfiedBy(ResultSet rs) throws InferenceException {
Date dob = (Date)rs.getResult(DOB);
calendar.setTime(dob);
return calendar.get(Calendar.YEAR)==1960;
}
},
new Object[][] {
convert("Tom", "Meier", "01/01/1960", 80, 1.80),
convert("John", "Meier", "01/01/1960", 90, 1.90)
}
));
suite.addTest(new WhereTestCase(
"Where filter test case 3",
new ResultSetCondition(){
public boolean isSatisfiedBy(ResultSet rs) throws InferenceException {
int weight = ((Integer)rs.getResult(WEIGHT)).intValue();
return weight==90;
}
},
new Object[][] {
convert("John", "Meier", "01/01/1960", 90, 1.90)
}
));
suite.addTest(new WhereTestCase(
"Where filter test case 4",
new ResultSetCondition(){
public boolean isSatisfiedBy(ResultSet rs) throws InferenceException {
double size = ((Double)rs.getResult(SIZE)).doubleValue();
return size==1.90;
}
},
new Object[][] {
convert("John", "Meier", "01/01/1960", 90, 1.90),
convert("Jim", "Smith", "01/01/1970", 100, 1.90)
}
));
return suite;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -