Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -3,6 +3,8 @@
3 3
4 4 import junit.framework.*;
5 5
6 + import org.litesoft.core.typeutils.*;
7 +
6 8 public class CalendarYTest extends TestCase
7 9 {
8 10 public static TestSuite suite()
  @@ -49,50 +51,69 @@
49 51
50 52 public void test_rtY()
51 53 {
52 - chkRT( "1996", "1996" );
54 + chkRTY( "1996", "1996" );
55 + chkRTY( "2000", "2000" );
56 + chkRTY( "2012", "2012" );
57 + }
58 +
59 + private void chkRTY( String pInputForFrom, String pToOutput )
60 + {
61 + CalendarY sd = CalendarY.fromY( pInputForFrom );
62 + assertEquals( pToOutput, sd.toY() );
53 63 }
54 64
55 - private void chkRT( String pToY, String pFromY )
65 + public void test_rtSQL()
56 66 {
57 - CalendarY sd = CalendarY.fromY( pToY );
58 - assertEquals( pFromY, sd.toY() );
67 + chkRTSQL( "1996", "1996" );
68 + chkRTSQL( "2000", "2000" );
69 + chkRTSQL( "2012", "2012" );
70 + }
71 +
72 + private void chkRTSQL( String pInputForFrom, String pToOutput )
73 + {
74 + CalendarY sd = CalendarY.fromSQLvalue( pInputForFrom );
75 + assertEquals( pToOutput, sd.toSQLvalue() );
59 76 }
60 77
61 78 public void test_fromYAndToString()
62 79 throws Exception
63 80 {
64 - chk( DateFormat.DEFAULT_Y_FORMAT, "y", "1957", "1957", 1957 );
65 - chk( "yy", "y", "1996", "96", 1996 );
66 - chk( "/yy", "y", "1996", "/96", 1996 );
67 - chk( "/ y:", "y", "1996", "/ 1996:", 1996 );
68 - chk( "/ yyy:", "y", "1996", "/ 1996:", 1996 );
81 + chk( DateFormat.DEFAULT_Y_FORMAT, "1957", "1957", 1957 );
82 + chk( "yy", "1996", "96", 1996 );
83 + chk( "/yy", "1996", "/96", 1996 );
84 + chk( "/ y:", "1996", "/ 1996:", 1996 );
85 + chk( "/ yyy:", "1996", "/ 1996:", 1996 );
69 86 }
70 87
71 - private void chk( String pDateFormat, String pFieldOrder, String pDateToParse, String pToString, int pYear )
88 + private void chk( String pDateFormat, String pDateToParse, String pDateFormatToString, int pYear )
72 89 {
73 - chk( new DateFormat( pDateFormat ), CalendarY.fromY( pDateToParse ), pToString, pFieldOrder, pYear );
90 + chk( new DateFormat( pDateFormat ), CalendarY.fromY( pDateToParse ), pDateFormatToString, pYear );
74 91 }
75 92
76 93 public void test_ContructorsAndToString()
77 94 throws Exception
78 95 {
79 - chk( "yy", "y", 1996, "96" );
80 - chk( "/yy", "y", 1996, "/96" );
81 - chk( "/ y:", "y", 1996, "/ 1996:" );
82 - chk( "/ yyy:", "y", 1996, "/ 1996:" );
96 + chk( "yy", 1996, "96" );
97 + chk( "/yy", 1996, "/96" );
98 + chk( "/ y:", 1996, "/ 1996:" );
99 + chk( "/ yyy:", 1996, "/ 1996:" );
83 100 }
84 101
85 -
86 - private void chk( String pDateFormat, String pFieldOrder, int pYear, String pToString )
102 + private void chk( String pDateFormat, int pYear, String pDateFormatToString )
87 103 {
88 - chk( new DateFormat( pDateFormat ), new CalendarY( pYear ), pToString, pFieldOrder, pYear );
104 + chk( new DateFormat( pDateFormat ), new CalendarY( pYear ), pDateFormatToString, pYear );
89 105 }
90 106
91 - private void chk( DateFormat pFormat, CalendarY pDate, String pToString, String pFieldOrder, int pYear )
107 + private void chk( DateFormat pFormat, CalendarY pDate, String pDateFormatToString, int pYear )
92 108 {
93 - assertEquals( pFieldOrder, pFormat.getFieldOrder() );
109 + String zExpectedStringFormYandSQL = Integers.zeroPadIt( 4, pYear );
110 + assertEquals( "y", pFormat.getFieldOrder() );
94 111 assertEquals( "Year", pYear, pDate.getYear() );
95 - assertEquals( pToString, pFormat.format( pDate ) );
112 + assertEquals( pDateFormatToString, pFormat.format( pDate ) );
113 + assertEquals( "toY", zExpectedStringFormYandSQL, pDate.toY() );
114 + assertEquals( "fromY", pDate, CalendarY.fromY( pDate.toY() ) );
115 + assertEquals( "toSQLvalue", zExpectedStringFormYandSQL, pDate.toSQLvalue() );
116 + assertEquals( "fromSQLvalue", pDate, CalendarY.fromSQLvalue( pDate.toSQLvalue() ) );
96 117 }
97 118
98 119 public void test_addYears()