litesoft
@ 851
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.core.simpletypes.temporal; import java.util.*; import junit.framework.*; public class UtilDateAdaptorTest extends TestCase { public static TestSuite suite() { return new TestSuite( UtilDateAdaptorTest.class ); } public UtilDateAdaptorTest( String name ) { super( name ); } public static void main( String[] args ) { junit.textui.TestRunner.run( suite() ); } public void test_RoundTrip() { chkRT( 1957, 1, 4, 12 ); chkRT( 1957, 1, 4, 12, 3 ); chkRT( 1957, 1, 4, 12, 3, 4 ); chkRT( 1957, 1, 4, 12, 3, 4, 567 ); chkRT( 1969, 12, 31, 23 ); chkRT( 1969, 12, 31, 23, 59 ); chkRT( 1969, 12, 31, 23, 59, 59 ); chkRT( 1969, 12, 31, 23, 59, 59, 999 ); chkRT( 1970, 1, 1, 0 ); chkRT( 1970, 1, 1, 0, 0, 0, 1 ); chkRT( 1970, 1, 1, 0, 0, 1 ); chkRT( 1970, 1, 1, 0, 1 ); chkRT( 1970, 1, 1, 1 ); chkRT( 2007, 1, 4, 12 ); chkRT( 2007, 1, 4, 12, 3 ); chkRT( 2007, 1, 4, 12, 3, 4 ); chkRT( 2007, 1, 4, 12, 3, 4, 567 ); chkRT( TimeRes.ToHOUR, new UtilDateAdaptor( 1957, 1, 4, 12 ) ); chkRT( TimeRes.ToMIN, new UtilDateAdaptor( 1957, 1, 4, 12, 30 ) ); chkRT( TimeRes.ToSEC, new UtilDateAdaptor( 1957, 1, 4, 12, 30, 15 ) ); chkRT( TimeRes.ToMSEC, new UtilDateAdaptor( 1957, 1, 4, 12, 30, 15, 678 ) ); } private void chkRT( int pYear, int pMonth, int pDay, int pHour ) { chkRT( TimeRes.ToHOUR, // new UtilDateAdaptor( pYear, pMonth, pDay, pHour ) ); } private void chkRT( int pYear, int pMonth, int pDay, int pHour, int pMin ) { chkRT( TimeRes.ToMIN, // new UtilDateAdaptor( pYear, pMonth, pDay, pHour, pMin ) ); } private void chkRT( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec ) { chkRT( TimeRes.ToSEC, // new UtilDateAdaptor( pYear, pMonth, pDay, pHour, pMin, pSec ) ); } private void chkRT( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec ) { chkRT( TimeRes.ToMSEC, // new UtilDateAdaptor( pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ) ); } private void chkRT( TimeRes pTimeRes, UtilDateAdaptor pAdaptor ) { assertEquals( "TimeRes", pTimeRes, pAdaptor.getTimeRes() ); Date date = pAdaptor.getWallDate(); UtilDateAdaptor proxy2 = new UtilDateAdaptor( date, pAdaptor.getTimeRes().getIndex() + 1 ); assertEquals( "Year", pAdaptor.getYear(), proxy2.getYear() ); assertEquals( "Month", pAdaptor.getMonth(), proxy2.getMonth() ); assertEquals( "Day", pAdaptor.getDay(), proxy2.getDay() ); assertEquals( "TimeResolutionIndex", pAdaptor.getTimeRes(), proxy2.getTimeRes() ); assertEquals( "Hour", pAdaptor.getHour(), proxy2.getHour() ); assertEquals( "Min", pAdaptor.getMin(), proxy2.getMin() ); assertEquals( "Sec", pAdaptor.getSec(), proxy2.getSec() ); assertEquals( "MilliSec", pAdaptor.getMilliSec(), proxy2.getMilliSec() ); } } |