litesoft
@ 939
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
package org.litesoft.core.simpletypes.temporal; import junit.framework.*; import org.litesoft.commonfoundation.base.*; import org.litesoft.commonfoundation.typeutils.*; public abstract class AbstractTemporalTestSupport<T extends AbstractTemporal<T>> extends TestCase { protected AbstractTemporalTestSupport( String name ) { super( name ); } protected enum Direction { Forward, Backward, Neither } protected String toY( int pYear ) { return Integers.zeroPadIt( 4, pYear ); } protected String toYM( int pYear, int pMonth ) { return toY( pYear ) + "/" + Integers.zeroPadIt( 2, pMonth ); } protected String toYMD( int pYear, int pMonth, int pDay ) { return toYM( pYear, pMonth ) + "/" + Integers.zeroPadIt( 2, pDay ); } protected String toSQLvalueY( int pYear ) { return Integers.zeroPadIt( 4, pYear ); } protected String toYMDH( int pYear, int pMonth, int pDay, int pHour ) { return toYMD( pYear, pMonth, pDay ) + " " + Integers.zeroPadIt( 2, pHour ); } protected String toSQLvalueYM( int pYear, int pMonth ) { return toSQLvalueY( pYear ) + "-" + Integers.zeroPadIt( 2, pMonth ); } protected String toSQLvalueYMD( int pYear, int pMonth, int pDay ) { return toSQLvalueYM( pYear, pMonth ) + "-" + Integers.zeroPadIt( 2, pDay ); } protected String toSQLvalueYMDH( int pYear, int pMonth, int pDay, int pHour ) { // TODO: XXX UtilDateAdaptor zDateAdaptor = UtilDateAdaptor.wall( pYear, pMonth, pDay, pHour ); // zDateAdaptor.getUTCtoWallOffsetMinutes() return toSQLvalueYMD( pYear, pMonth, pDay ) + "T" + Integers.zeroPadIt( 2, pHour ); } protected Direction add( int pAdjustBy ) { if ( pAdjustBy == 0 ) { return Direction.Neither; } return (pAdjustBy > 0) ? Direction.Forward : Direction.Backward; } protected Direction minus( int pAdjustBy ) { if ( pAdjustBy == 0 ) { return Direction.Neither; } return (pAdjustBy < 0) ? Direction.Forward : Direction.Backward; } protected void compareCheck( Direction pDirection, T pOd, T pNd ) { AbstractCalendarY zOD = cast( pOd ); AbstractCalendarY zNd = cast( pNd ); int zCompare = compareEm( pOd, pNd ); boolean zOdAfterOrEqualNd = zOD.afterOrEqual( zNd ); boolean zOdBeforeOrEqualNd = zOD.beforeOrEqual( zNd ); switch ( pDirection ) { case Forward: assertTrue( 0 > zCompare ); assertFalse( zOdAfterOrEqualNd ); assertTrue( zOdBeforeOrEqualNd ); break; case Backward: assertTrue( 0 < zCompare ); assertTrue( zOdAfterOrEqualNd ); assertFalse( zOdBeforeOrEqualNd ); break; default: case Neither: assertTrue( pOd == pNd ); assertTrue( 0 == zCompare ); assertTrue( zOdAfterOrEqualNd ); assertTrue( zOdBeforeOrEqualNd ); break; } } protected void chkAfterBeforeNull( T pSd ) { try { cast( pSd ).afterOrEqual( null ); fail( "Did Not fail on '" + pSd + "': after( null )" ); } catch ( IllegalArgumentException expected ) { // expected } try { cast( pSd ).beforeOrEqual( null ); fail( "Did Not fail on '" + pSd + "': before( null )" ); } catch ( IllegalArgumentException expected ) { // expected } } private AbstractCalendarY cast( T pSD ) { return Cast.it( pSD ); } @SuppressWarnings("unchecked") private int compareEm( T pOd, T pNd ) { return pOd.compareTo( pNd ); } } |
Commits for litesoft/trunk/Java/core/Anywhere/tests/org/litesoft/core/simpletypes/temporal/AbstractTemporalTestSupport.java
Revision | Author | Commited | Message |
---|---|---|---|
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
912 Diff | GeorgeS | Fri 28 Jun, 2013 06:48:05 +0000 | Revert to mixed & Working (PEDS & Prioritizer) code! |
897 Diff | GeorgeS | Mon 25 Feb, 2013 02:04:34 +0000 | |
895 | GeorgeS | Mon 04 Feb, 2013 01:12:49 +0000 |