| Method from org.jfree.date.junit.SerialDateTests Detail: |
protected void setUp() {
this.nov9Y2001 = SerialDate.createInstance(9, MonthConstants.NOVEMBER, 2001);
}
|
public static Test suite() {
return new TestSuite(SerialDateTests.class);
}
Returns a test suite for the JUnit test runner. |
public void test1096282() {
SerialDate d = SerialDate.createInstance(29, 2, 2004);
d = SerialDate.addYears(1, d);
SerialDate expected = SerialDate.createInstance(28, 2, 2005);
assertTrue(d.isOn(expected));
}
A test for bug report 1096282 (now fixed). |
public void testAddMonths() {
SerialDate d1 = SerialDate.createInstance(31, 5, 2004);
SerialDate d2 = SerialDate.addMonths(1, d1);
assertEquals(30, d2.getDayOfMonth());
assertEquals(6, d2.getMonth());
assertEquals(2004, d2.getYYYY());
SerialDate d3 = SerialDate.addMonths(2, d1);
assertEquals(31, d3.getDayOfMonth());
assertEquals(7, d3.getMonth());
assertEquals(2004, d3.getYYYY());
SerialDate d4 = SerialDate.addMonths(1, SerialDate.addMonths(1, d1));
assertEquals(30, d4.getDayOfMonth());
assertEquals(7, d4.getMonth());
assertEquals(2004, d4.getYYYY());
}
Miscellaneous tests for the addMonths() method. |
public void testAddMonthsTo1Jan2003() {
final SerialDate d1 = SerialDate.createInstance(1, MonthConstants.JANUARY, 2003);
final SerialDate d2 = SerialDate.addMonths(0, d1);
assertEquals(d2, d1);
}
A test case for a reported bug, now fixed. |
public void testAddMonthsTo5Oct2003() {
final SerialDate d1 = SerialDate.createInstance(5, MonthConstants.OCTOBER, 2003);
final SerialDate d2 = SerialDate.addMonths(2, d1);
assertEquals(d2, SerialDate.createInstance(5, MonthConstants.DECEMBER, 2003));
}
A test case for a reported bug, now fixed. |
public void testAddMonthsTo9Nov2001() {
final SerialDate jan9Y2002 = SerialDate.addMonths(2, this.nov9Y2001);
final SerialDate answer = SerialDate.createInstance(9, 1, 2002);
assertEquals(answer, jan9Y2002);
}
9 Nov 2001 plus two months should be 9 Jan 2002. |
public void testIsLeapYear2000() {
assertTrue(SerialDate.isLeapYear(2000));
}
|
public void testIsNotLeapYear1900() {
assertTrue(!SerialDate.isLeapYear(1900));
}
|
public void testLeapYearCount1899() {
assertEquals(SerialDate.leapYearCount(1899), 0);
}
The number of leap years from 1900 up-to-and-including 1899 is 0. |
public void testLeapYearCount1903() {
assertEquals(SerialDate.leapYearCount(1903), 0);
}
The number of leap years from 1900 up-to-and-including 1903 is 0. |
public void testLeapYearCount1904() {
assertEquals(SerialDate.leapYearCount(1904), 1);
}
The number of leap years from 1900 up-to-and-including 1904 is 1. |
public void testLeapYearCount1999() {
assertEquals(SerialDate.leapYearCount(1999), 24);
}
The number of leap years from 1900 up-to-and-including 1999 is 24. |
public void testLeapYearCount2000() {
assertEquals(SerialDate.leapYearCount(2000), 25);
}
The number of leap years from 1900 up-to-and-including 2000 is 25. |
public void testMondayFollowingFriday9Nov2001() {
SerialDate mondayAfter = SerialDate.getFollowingDayOfWeek(
SerialDate.MONDAY, this.nov9Y2001
);
assertEquals(12, mondayAfter.getDayOfMonth());
}
Monday following Friday 9 November 2001 should be 12 November. |
public void testMondayNearest22Jan1970() {
SerialDate jan22Y1970 = SerialDate.createInstance(22, MonthConstants.JANUARY, 1970);
SerialDate mondayNearest = SerialDate.getNearestDayOfWeek(SerialDate.MONDAY, jan22Y1970);
assertEquals(19, mondayNearest.getDayOfMonth());
}
The Monday nearest to 22nd January 1970 falls on the 19th. |
public void testMondayNearestFriday9Nov2001() {
SerialDate mondayNearest = SerialDate.getNearestDayOfWeek(
SerialDate.MONDAY, this.nov9Y2001
);
assertEquals(12, mondayNearest.getDayOfMonth());
}
Monday nearest Friday 9 November 2001 should be 12 November. |
public void testMondayPrecedingFriday9Nov2001() {
SerialDate mondayBefore = SerialDate.getPreviousDayOfWeek(
SerialDate.MONDAY, this.nov9Y2001
);
assertEquals(5, mondayBefore.getDayOfMonth());
}
Monday preceding Friday 9 November 2001 should be 5 November. |
public void testMonthCodeToStringCode() {
final String test = SerialDate.monthCodeToString(MonthConstants.DECEMBER);
assertEquals("December", test);
}
Tests the conversion of a month code to a string. |
public void testSerialization() {
SerialDate d1 = SerialDate.createInstance(15, 4, 2000);
SerialDate d2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(d1);
out.close();
ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
d2 = (SerialDate) in.readObject();
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertEquals(d1, d2);
}
Serialize an instance, restore it, and check for equality. |
public void testStringToMonthCode() {
int m = SerialDate.stringToMonthCode("January");
assertEquals(MonthConstants.JANUARY, m);
m = SerialDate.stringToMonthCode(" January ");
assertEquals(MonthConstants.JANUARY, m);
m = SerialDate.stringToMonthCode("Jan");
assertEquals(MonthConstants.JANUARY, m);
}
Test the conversion of a string to a month. Note that this test will fail if the default
locale doesn't use English month names...devise a better test! |
public void testStringToWeekday() {
int weekday = SerialDate.stringToWeekdayCode("Wednesday");
assertEquals(SerialDate.WEDNESDAY, weekday);
weekday = SerialDate.stringToWeekdayCode(" Wednesday ");
assertEquals(SerialDate.WEDNESDAY, weekday);
weekday = SerialDate.stringToWeekdayCode("Wed");
assertEquals(SerialDate.WEDNESDAY, weekday);
}
Test the conversion of a string to a weekday. Note that this test will fail if the
default locale doesn't use English weekday names...devise a better test! |
public void testWeekdayCodeToString() {
final String test = SerialDate.weekdayCodeToString(SerialDate.SATURDAY);
assertEquals("Saturday", test);
}
Problem that the conversion of days to strings returns the right result. Actually, this
result depends on the Locale so this test needs to be modified. |