|
@@ -3,6 +3,8 @@ |
3 |
3 |
|
|
4 |
4 |
|
import junit.framework.*; |
5 |
5 |
|
|
|
6 |
+ |
import org.litesoft.core.typeutils.*; |
|
7 |
+ |
|
6 |
8 |
|
public class CalendarYMTest extends TestCase |
7 |
9 |
|
{ |
8 |
10 |
|
public static TestSuite suite() |
|
@@ -52,13 +54,32 @@ |
52 |
54 |
|
|
53 |
55 |
|
public void test_rtYM() |
54 |
56 |
|
{ |
55 |
|
- |
chkRT( "2000/2", "2000/02" ); |
|
57 |
+ |
chkRT_YM( "1957/1", "1957/01" ); |
|
58 |
+ |
chkRT_YM( "1957/01", "1957/01" ); |
|
59 |
+ |
chkRT_YM( "1957/001", "1957/01" ); |
|
60 |
+ |
chkRT_YM( "2000/2", "2000/02" ); |
|
61 |
+ |
chkRT_YM( "2012/012", "2012/12" ); |
|
62 |
+ |
} |
|
63 |
+ |
|
|
64 |
+ |
private void chkRT_YM( String pInputForFrom, String pToOutput ) |
|
65 |
+ |
{ |
|
66 |
+ |
CalendarYM sd = CalendarYM.fromYM( pInputForFrom ); |
|
67 |
+ |
assertEquals( pToOutput, sd.toYM() ); |
|
68 |
+ |
} |
|
69 |
+ |
|
|
70 |
+ |
public void test_rtSQL() |
|
71 |
+ |
{ |
|
72 |
+ |
chkRT_SQL( "1957-1", "1957-01" ); |
|
73 |
+ |
chkRT_SQL( "1957-01", "1957-01" ); |
|
74 |
+ |
chkRT_SQL( "1957-001", "1957-01" ); |
|
75 |
+ |
chkRT_SQL( "2000-2", "2000-02" ); |
|
76 |
+ |
chkRT_SQL( "2012-012", "2012-12" ); |
56 |
77 |
|
} |
57 |
78 |
|
|
58 |
|
- |
private void chkRT( String pToYM, String pFromYM ) |
|
79 |
+ |
private void chkRT_SQL( String pInputForFrom, String pToOutput ) |
59 |
80 |
|
{ |
60 |
|
- |
CalendarYM sd = CalendarYM.fromYM( pToYM ); |
61 |
|
- |
assertEquals( pFromYM, sd.toYM() ); |
|
81 |
+ |
CalendarYM sd = CalendarYM.fromSQLvalue( pInputForFrom ); |
|
82 |
+ |
assertEquals( pToOutput, sd.toSQLvalue() ); |
62 |
83 |
|
} |
63 |
84 |
|
|
64 |
85 |
|
public void test_fromYMAndToString() |
|
@@ -67,11 +88,12 @@ |
67 |
88 |
|
chk( DateFormat.DEFAULT_YM_FORMAT, "My", "1957/1", "Jan 1957", 1957, 1 ); |
68 |
89 |
|
chk( "MMMyy", "My", "1957/1", "Jan57", 1957, 1 ); |
69 |
90 |
|
chk( "MMMMMM y", "My", "1957 / 1", "January 1957", 1957, 1 ); |
|
91 |
+ |
chk( "y-MM", "yM", "1957 / 1", "1957-01", 1957, 1 ); |
70 |
92 |
|
} |
71 |
93 |
|
|
72 |
|
- |
private void chk( String pDateFormat, String pFieldOrder, String pDateToParse, String pToString, int pYear, int pMonth ) |
|
94 |
+ |
private void chk( String pDateFormat, String pFieldOrder, String pDateToParse, String pDateFormatToString, int pYear, int pMonth ) |
73 |
95 |
|
{ |
74 |
|
- |
chk( new DateFormat( pDateFormat ), CalendarYM.fromYM( pDateToParse ), pToString, pFieldOrder, pYear, pMonth ); |
|
96 |
+ |
chk( new DateFormat( pDateFormat ), pFieldOrder, CalendarYM.fromYM( pDateToParse ), pDateFormatToString, pYear, pMonth ); |
75 |
97 |
|
} |
76 |
98 |
|
|
77 |
99 |
|
public void test_ContructorsAndToString() |
|
@@ -80,17 +102,23 @@ |
80 |
102 |
|
chk( "MMM yyyy", "My", 2004, 2, "Feb 2004" ); |
81 |
103 |
|
} |
82 |
104 |
|
|
83 |
|
- |
private void chk( String pDateFormat, String pFieldOrder, int pYear, int pMonth, String pToString ) |
|
105 |
+ |
private void chk( String pDateFormat, String pFieldOrder, int pYear, int pMonth, String pDateFormatToString ) |
84 |
106 |
|
{ |
85 |
|
- |
chk( new DateFormat( pDateFormat ), new CalendarYM( pYear, pMonth ), pToString, pFieldOrder, pYear, pMonth ); |
|
107 |
+ |
chk( new DateFormat( pDateFormat ), pFieldOrder, new CalendarYM( pYear, pMonth ), pDateFormatToString, pYear, pMonth ); |
86 |
108 |
|
} |
87 |
109 |
|
|
88 |
|
- |
private void chk( DateFormat pFormat, CalendarYM pDate, String pToString, String pFieldOrder, int pYear, int pMonth ) |
|
110 |
+ |
private void chk( DateFormat pFormat, String pFieldOrder, CalendarYM pDate, String pDateFormatToString, int pYear, int pMonth ) |
89 |
111 |
|
{ |
|
112 |
+ |
String zExpectedStringFormY = Integers.zeroPadIt( 4, pYear ); |
|
113 |
+ |
String zExpectedStringFormM = Integers.zeroPadIt( 2, pMonth ); |
90 |
114 |
|
assertEquals( pFieldOrder, pFormat.getFieldOrder() ); |
91 |
115 |
|
assertEquals( "Year", pYear, pDate.getYear() ); |
92 |
116 |
|
assertEquals( "Month", pMonth, pDate.getMonth() ); |
93 |
|
- |
assertEquals( pToString, pFormat.format( pDate ) ); |
|
117 |
+ |
assertEquals( pDateFormatToString, pFormat.format( pDate ) ); |
|
118 |
+ |
assertEquals( "toYM", zExpectedStringFormY + "/" + zExpectedStringFormM, pDate.toYM() ); |
|
119 |
+ |
assertEquals( "fromYM", pDate, CalendarYM.fromYM( pDate.toYM() ) ); |
|
120 |
+ |
assertEquals( "toSQLvalue", zExpectedStringFormY + "-" + zExpectedStringFormM, pDate.toSQLvalue() ); |
|
121 |
+ |
assertEquals( "fromSQLvalue", pDate, CalendarYM.fromSQLvalue( pDate.toSQLvalue() ) ); |
94 |
122 |
|
} |
95 |
123 |
|
|
96 |
124 |
|
public void test_addYears() |
|
@@ -100,9 +128,6 @@ |
100 |
128 |
|
chk_addYears( "2000/02", 1, "2001/02" ); |
101 |
129 |
|
chk_addYears( "2000/02", 0, "2000/02" ); |
102 |
130 |
|
chk_addYears( "2000/02", -1, "1999/02" ); |
103 |
|
- |
chk_addYears( "1957", 51, "2008" ); |
104 |
|
- |
chk_addYears( "2000", -1, "1999" ); |
105 |
|
- |
chk_addYears( "2000", 1, "2001" ); |
106 |
131 |
|
} |
107 |
132 |
|
|
108 |
133 |
|
private void chk_addYears( String pDateYM, int pAdjustBy, String pExpectedYM ) |
|
@@ -138,10 +163,6 @@ |
138 |
163 |
|
chk_minusYears( "2000/02", 1, "1999/02" ); |
139 |
164 |
|
chk_minusYears( "2000/02", 0, "2000/02" ); |
140 |
165 |
|
chk_minusYears( "2000/02", -1, "2001/02" ); |
141 |
|
- |
chk_minusYears( "2008", 51, "1957" ); |
142 |
|
- |
chk_minusYears( "2000", -1, "2001" ); |
143 |
|
- |
chk_minusYears( "2000", 0, "2000" ); |
144 |
|
- |
chk_minusYears( "2000", 1, "1999" ); |
145 |
166 |
|
} |
146 |
167 |
|
|
147 |
168 |
|
private void chk_minusYears( String pDateYM, int pAdjustBy, String pExpectedYM ) |