001: package org.springunit.examples.constructor.junit.v2;
002:
003: import org.springunit.examples.CompositeDate;
004: import org.springunit.examples.InvalidDateException;
005:
006: import junit.framework.TestCase;
007:
008: /**
009: * Merges v4 from two classes to one.
010: * @author Ted.Velkoff
011: *
012: */
013: public class CompositeDateConstructorTest extends TestCase {
014:
015: protected void runValid(int year, int month, int day,
016: int expectedYear, int expectedMonth, int expectedDay)
017: throws Exception {
018: CompositeDate subject = new CompositeDate(year, month, day);
019: assertTrue(expectedMonth == subject.getMonth());
020: assertTrue(expectedDay == subject.getDay());
021: assertTrue(expectedYear == subject.getYear());
022: }
023:
024: public void testJan01() throws Exception {
025: int day = 1;
026: int month = 1;
027: int year = 2006;
028: int expectedDay = 1;
029: int expectedMonth = 1;
030: int expectedYear = 2006;
031: runValid(year, month, day, expectedYear, expectedMonth,
032: expectedDay);
033: }
034:
035: public void testDec31() throws Exception {
036: int day = 31;
037: int month = 12;
038: int year = 2006;
039: int expectedDay = 31;
040: int expectedMonth = 12;
041: int expectedYear = 2006;
042: runValid(year, month, day, expectedYear, expectedMonth,
043: expectedDay);
044: }
045:
046: public void testFeb29Leap2000() throws Exception {
047: int day = 29;
048: int month = 2;
049: int year = 2000;
050: int expectedDay = 29;
051: int expectedMonth = 2;
052: int expectedYear = 2000;
053: runValid(year, month, day, expectedYear, expectedMonth,
054: expectedDay);
055: }
056:
057: public void testFeb29Leap2004() throws Exception {
058: int day = 29;
059: int month = 2;
060: int year = 2004;
061: int expectedDay = 29;
062: int expectedMonth = 2;
063: int expectedYear = 2004;
064: runValid(year, month, day, expectedYear, expectedMonth,
065: expectedDay);
066: }
067:
068: protected void runInvalid(int year, int month, int day)
069: throws Exception {
070: try {
071: new CompositeDate(year, month, day);
072: fail("Exception not thrown");
073: } catch (InvalidDateException ex) {
074: }
075: }
076:
077: public void testApr31() throws Exception {
078: int day = 31;
079: int month = 4;
080: int year = 2006;
081: runInvalid(year, month, day);
082: }
083:
084: public void testJun31() throws Exception {
085: int day = 31;
086: int month = 6;
087: int year = 2006;
088: runInvalid(year, month, day);
089: }
090:
091: public void testSep31() throws Exception {
092: int day = 31;
093: int month = 9;
094: int year = 2006;
095: runInvalid(year, month, day);
096: }
097:
098: public void testNov31() throws Exception {
099: int day = 31;
100: int month = 11;
101: int year = 2006;
102: runInvalid(year, month, day);
103: }
104:
105: public void testFeb31() throws Exception {
106: int day = 31;
107: int month = 2;
108: int year = 2006;
109: runInvalid(year, month, day);
110: }
111:
112: public void testFeb30() throws Exception {
113: int day = 30;
114: int month = 2;
115: int year = 2006;
116: runInvalid(year, month, day);
117: }
118:
119: public void testFeb29NoLeap() throws Exception {
120: int day = 29;
121: int month = 2;
122: int year = 2003;
123: runInvalid(year, month, day);
124: }
125:
126: public void testFeb29NoLeap1900() throws Exception {
127: int day = 29;
128: int month = 2;
129: int year = 1900;
130: runInvalid(year, month, day);
131: }
132:
133: }
|