001 package org.hackystat.utilities.time.period; 002 003 import javax.xml.datatype.XMLGregorianCalendar; 004 005 import org.hackystat.utilities.tstamp.Tstamp; 006 007 import junit.framework.TestCase; 008 009 /** 010 * Tests the Month and Months implementations. 011 * 012 * @author Hongbing Kou, Philip Johnson 013 */ 014 public class TestMonth extends TestCase { 015 016 /** 017 * Test the XMLGregorianCalendar constructor. 018 * @throws Exception If problems. 019 */ 020 public void testXmlMonth() throws Exception { 021 XMLGregorianCalendar xmlDay = Tstamp.makeTimestamp("2003-08-01"); 022 Month month = new Month(xmlDay); 023 assertEquals("Checking month's toString() method", "Aug-2003", month.toString()); 024 } 025 026 /** 027 * Test month constructor and operation. 028 */ 029 public void testMonth() { 030 // Creates January, 2003 031 Month month = new Month(2003, 0); 032 assertEquals("Checking the year", 2003, month.getYear()); 033 assertEquals("Checking the month", 0, month.getMonth()); 034 assertEquals("Checking month's toString() method", "Jan-2003", month.toString()); 035 assertEquals("Checking number of days in this month", 31, month.getNumOfDays()); 036 assertEquals("Checking the first day of this month", Day.getInstance(2003, 0, 1), 037 month.getFirstDay()); 038 039 assertEquals("Checking the first week of this month", new Week(Day.getInstance(2003, 0, 1)), 040 month.getFirstWeekInMonth()); 041 042 assertEquals("Checking the last day of this month", Day.getInstance(2003, 0, 31), 043 month.getLastDay()); 044 assertEquals("Checking the last week of this month", new Week(Day.getInstance(2003, 0, 31)), 045 month.getLastWeekInMonth()); 046 047 Month month2 = new Month(2003, 1); 048 assertTrue("Check the month comparison", month.compareTo(month2) < 0); 049 assertEquals("Checking number of days in month Feb, 2003", 28, month2.getNumOfDays()); 050 assertEquals("Checking the last day in Feb, 2003", Day.getInstance(2003, 1, 28), 051 month2.getLastDay()); 052 053 Month month3 = new Month(2002, 11); 054 assertTrue("Check the month comparison", month.compareTo(month3) > 0); 055 assertEquals("Checking number of days in this month", 31, month3.getNumOfDays()); 056 assertEquals("Checking the last day in Feb, 2003", Day.getInstance(2002, 11, 31), 057 month3.getLastDay()); 058 } 059 060 /** 061 * Tests month metods. 062 */ 063 public void testMonth2() { 064 Month month = new Month(2003, 11); 065 Month prev = new Month(2003, 10); 066 Month next = new Month(2004, 0); 067 068 assertEquals("Checking the previous method", prev, month.dec()); 069 assertEquals("Checking the next method", next, month.inc()); 070 month = new Month(2004, 0); 071 prev = new Month(2003, 11); 072 next = new Month(2004, 1); 073 074 assertEquals("Checking the previous method", prev, month.dec()); 075 assertEquals("Checking the next method", next, month.inc()); 076 } 077 078 /** 079 * Test month collection. 080 */ 081 public void testMonths() { 082 Month month = new Month(2004, 1); 083 assertEquals("Check the number of days in the month with day list", 29, month.getDays().size()); 084 } 085 }