📄 testsimpledate.java
字号:
/*
* Copyright (C) 1999-2005 <a href="mailto:paschke@in.tum.de">Adrian Paschke</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
*/
package test.org.mandarax.lib.date;
import org.mandarax.kernel.InferenceEngine;
import org.mandarax.kernel.KnowledgeBase;
import org.mandarax.lib.date.SimpleDate;
import java.util.Calendar;
import java.util.TimeZone;
import junit.framework.TestCase;
/**
* Test case for SimpleDates. Time zones are testet in synchronized and not synchronized mode.
* @author <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
* @version 3.4 <7 March 05>
* @since 3.3.1
*/
public class TestSimpleDate extends DateTestCase {
private Calendar t1;
private Calendar t2;
private Calendar t3;
/**
* Constructor.
* @param testName the name of the test
*/
public TestSimpleDate(String testName) {
super(testName);
}
/**
* set up fixtures
*/
protected void setUp() {
t1 = new SimpleDate();
TimeZone tz = TimeZone.getTimeZone("Europe/Berlin");
t1.setTimeZone(tz);
}
/**
* Test case 1: Synchronized with different time zones
* @throws an exception (indicating that the test case has failed)
*/
public void simpleDateTest1() throws Exception {
Calendar t = (SimpleDate) t1.clone();
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
t.setTimeZone(tz);
if (t.equals(t1)) assertTrue(true);
else assertTrue(t+" is not equal "+t1,false);
}
/**
* Test case 2: Not synchronized with different time zones
* @throws an exception (indicating that the test case has failed)
*/
public void simpleDateTest2() throws Exception {
SimpleDate t = (SimpleDate) t1.clone();
t.setSynchronized(false);
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
t.setTimeZone(tz);
if (!t.equals(t1)) assertTrue(true);
else assertTrue(t+" is equal "+t1,false);
}
/**
* Test case 3: Not synchronized with different time zones and the same absolute time
* @throws an exception (indicating that the test case has failed)
*/
public void simpleDateTest3() throws Exception {
SimpleDate t = (SimpleDate) t1.clone();
t.setSynchronized(false);
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
t.setTimeZone(tz);
t.add(Calendar.MILLISECOND, +3600000);
t.add(Calendar.MILLISECOND, +28800000);
if (t.equals(t1)) assertTrue(true);
else assertTrue(t+" is not equal "+t1,false);
}
/**
* Test case 4: Synchronized with different time zones
* @throws an exception (indicating that the test case has failed)
*/
public void simpleDateTest4() throws Exception {
Calendar t = (SimpleDate) t1.clone();
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
t.setTimeZone(tz);
t.add(Calendar.MINUTE, 1);
if (t.after(t1)) assertTrue(true);
else assertTrue(t+" is not after "+t1,false);
}
/**
* Test case 5: Synchronized with different time zones
* @throws an exception (indicating that the test case has failed)
*/
public void simpleDateTest5() throws Exception {
Calendar t = (SimpleDate) t1.clone();
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
t.setTimeZone(tz);
t.add(Calendar.MINUTE, 1);
if (t1.before(t)) assertTrue(true);
else assertTrue(t1+" is not before "+t,false);
}
/**
* Test case 6: Not synchronized with different time zones
* @throws an exception (indicating that the test case has failed)
*/
public void simpleDateTest6() throws Exception {
SimpleDate t = (SimpleDate) t1.clone();
t.setSynchronized(false);
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
t.setTimeZone(tz);
if (t.before(t1)) assertTrue(true);
else assertTrue(t+" is not before "+t1,false);
}
/**
* Test case 7: Not synchronized with different time zones
* @throws an exception (indicating that the test case has failed)
*/
public void simpleDateTest7() throws Exception {
SimpleDate t = (SimpleDate) t1.clone();
t.setSynchronized(false);
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
t.setTimeZone(tz);
if (t1.after(t)) assertTrue(true);
else assertTrue(t1+" is not after "+t,false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -