Subversion Repository Public Repository

litesoft

Diff Revisions 911 vs 912 for /trunk/Java/core/Anywhere/tests/org/litesoft/core/simpletypes/temporal/CalendarYTest.java

Diff revisions: vs.
  @@ -3,7 +3,9 @@
3 3
4 4 import junit.framework.*;
5 5
6 - public class CalendarYTest extends AbstractTemporalTestSupport<CalendarY>
6 + import org.litesoft.core.typeutils.*;
7 +
8 + public class CalendarYTest extends TestCase
7 9 {
8 10 public static TestSuite suite()
9 11 {
  @@ -26,6 +28,9 @@
26 28 chkCB( "1996a" );
27 29 chkCB( "1996/a" );
28 30 chkCB( "1996/1/a" );
31 + // Bad Dates
32 + chkCB( "2000/0" );
33 + chkCB( "2000/13" );
29 34
30 35 // Too Many Parts
31 36 chkCB( "1996/2" );
  @@ -101,12 +106,13 @@
101 106
102 107 private void chk( DateFormat pFormat, CalendarY pDate, String pDateFormatToString, int pYear )
103 108 {
109 + String zExpectedStringFormYandSQL = Integers.zeroPadIt( 4, pYear );
104 110 assertEquals( "y", pFormat.getFieldOrder() );
105 111 assertEquals( "Year", pYear, pDate.getYear() );
106 112 assertEquals( pDateFormatToString, pFormat.format( pDate ) );
107 - assertEquals( "toY", toY( pYear ), pDate.toY() );
113 + assertEquals( "toY", zExpectedStringFormYandSQL, pDate.toY() );
108 114 assertEquals( "fromY", pDate, CalendarY.fromY( pDate.toY() ) );
109 - assertEquals( "toSQLvalue", toSQLvalueY( pYear ), pDate.toSQLvalue() );
115 + assertEquals( "toSQLvalue", zExpectedStringFormYandSQL, pDate.toSQLvalue() );
110 116 assertEquals( "fromSQLvalue", pDate, CalendarY.fromSQLvalue( pDate.toSQLvalue() ) );
111 117 }
112 118
  @@ -123,7 +129,25 @@
123 129 CalendarY od = CalendarY.fromY( pDateY );
124 130 CalendarY nd = od.addYears( pAdjustBy );
125 131 assertEquals( pExpectedY, nd.toY() );
126 - compareCheck( add( pAdjustBy ), od, nd );
132 + if ( pAdjustBy == 0 )
133 + {
134 + assertTrue( od == nd );
135 + assertTrue( 0 == od.compareTo( nd ) );
136 + assertTrue( od.afterOrEqual( nd ) );
137 + assertTrue( od.beforeOrEqual( nd ) );
138 + }
139 + else if ( pAdjustBy > 0 )
140 + {
141 + assertTrue( 0 > od.compareTo( nd ) );
142 + assertFalse( od.afterOrEqual( nd ) );
143 + assertTrue( od.beforeOrEqual( nd ) );
144 + }
145 + else // pAdjustBy < 0
146 + {
147 + assertTrue( 0 < od.compareTo( nd ) );
148 + assertTrue( od.afterOrEqual( nd ) );
149 + assertFalse( od.beforeOrEqual( nd ) );
150 + }
127 151 }
128 152
129 153 public void test_minusYears()
  @@ -139,11 +163,47 @@
139 163 CalendarY od = CalendarY.fromY( pDateY );
140 164 CalendarY nd = od.minusYears( pAdjustBy );
141 165 assertEquals( pExpectedY, nd.toY() );
142 - compareCheck( minus( pAdjustBy ), od, nd );
166 + if ( pAdjustBy == 0 )
167 + {
168 + assertTrue( od == nd );
169 + assertTrue( 0 == od.compareTo( nd ) );
170 + assertTrue( od.afterOrEqual( nd ) );
171 + assertTrue( od.beforeOrEqual( nd ) );
172 + }
173 + else if ( pAdjustBy < 0 )
174 + {
175 + assertTrue( 0 > od.compareTo( nd ) );
176 + assertFalse( od.afterOrEqual( nd ) );
177 + assertTrue( od.beforeOrEqual( nd ) );
178 + }
179 + else // pAdjustBy > 0
180 + {
181 + assertTrue( 0 < od.compareTo( nd ) );
182 + assertTrue( od.afterOrEqual( nd ) );
183 + assertFalse( od.beforeOrEqual( nd ) );
184 + }
143 185 }
144 186
145 187 public void test_after_before_null()
146 188 {
147 - chkAfterBeforeNull( new CalendarY( 2000 ) );
189 + CalendarY sd = new CalendarY( 2000 );
190 + try
191 + {
192 + sd.afterOrEqual( null );
193 + fail( "Did Not fail on '" + sd + "': after( null )" );
194 + }
195 + catch ( IllegalArgumentException expected )
196 + {
197 + // expected
198 + }
199 + try
200 + {
201 + sd.beforeOrEqual( null );
202 + fail( "Did Not fail on '" + sd + "': before( null )" );
203 + }
204 + catch ( IllegalArgumentException expected )
205 + {
206 + // expected
207 + }
148 208 }
149 209 }