1 64 65 package com.jcorporate.expresso.core.misc.tests; 66 67 import com.jcorporate.expresso.core.misc.DateTime; 68 import com.jcorporate.expresso.services.test.ExpressoTestCase; 69 import com.jcorporate.expresso.services.test.TestSystemInitializer; 70 import junit.framework.Test; 71 import junit.framework.TestSuite; 72 import junit.textui.TestRunner; 73 74 import java.util.Calendar ; 75 import java.util.Date ; 76 77 85 public class TestDateTime extends ExpressoTestCase { 86 87 String myContext = TestSystemInitializer.getTestContext(); 88 89 public TestDateTime(String testName) 90 throws Exception { 91 super(testName); 92 } 93 94 public static Test suite() { 95 return new TestSuite(TestDateTime.class); 96 } 97 98 public static void checkOKDate(String testName, String result) { 99 assertTrue("Not null Return ", (result != null)); 100 assertTrue("Greater Than Zero Length Return ", (result.length() > 0)); 101 System.out.println(testName + " : result " + result); 102 } 103 104 public static void checkNullDate(String testName, String result) { 105 assertTrue("Is Null Return ", (result == null)); 106 System.out.println(testName + " : result " + result); 107 } 108 109 public void testGoodDate() throws Exception { 110 111 int year = 1969; 112 int month = 4; 113 int day = 22; 114 int hour = 13; 115 int min = 14; 116 int sec = 15; 117 Date date = new Date (); 118 Calendar aCalendar = Calendar.getInstance(); 119 aCalendar.set(year, month, day, hour, min, sec); 120 121 System.out.println("======================================="); 122 System.out.println("testGoodDate\n"); 123 System.out.println("year = " + year); 124 System.out.println("month = " + month); 125 System.out.println("day = " + day); 126 System.out.println("hour = " + hour); 127 System.out.println("min = " + min); 128 System.out.println("sec = " + sec); 129 System.out.println("date = " + date); 130 System.out.println(""); 131 132 checkOKDate("getDateString()", DateTime.getDateString()); 133 checkOKDate("getDateTimeForDB()", DateTime.getDateTimeForDB()); 134 checkOKDate("getDateTimeForDB(myContext)", 135 DateTime.getDateTimeForDB(myContext)); 136 checkOKDate("getDateTimeForDB(year, month, day, hour, min, sec, myContext)", 137 DateTime.getDateTimeForDB(year, month, day, hour, min, sec, myContext)); 138 checkOKDate("getDateTimeForDB(date, myContext)", 139 DateTime.getDateTimeForDB(date, myContext)); 140 checkOKDate("getDateTimeForDB(year, month, day, hour, min, sec)", 143 DateTime.getDateTimeForDB(year, month, day, hour, min, sec)); 144 checkOKDate("getDateTimeForDB(date)", 145 DateTime.getDateTimeForDB(date)); 146 checkOKDate("getDateTimeString()", 147 DateTime.getDateTimeString()); 148 checkOKDate("getDateTimeString(date)", 149 DateTime.getDateTimeString(date)); 150 checkOKDate("getTimeForDB()", DateTime.getTimeForDB()); 151 checkOKDate("getTimeForDB(hour, min, sec)", 152 DateTime.getTimeForDB(hour, min, sec)); 153 checkOKDate("getTimeForDB(date)", DateTime.getTimeForDB(date)); 154 checkOKDate("getTimeForDB(date, myContext)", 155 DateTime.getTimeForDB(date, myContext)); 156 checkOKDate("getDateForDB()", DateTime.getDateForDB()); 157 checkOKDate("getDateForDB(year, month, day)", 158 DateTime.getDateForDB(year, month, day)); 159 checkOKDate("getDateForDB(date)", DateTime.getDateForDB(date)); 160 checkOKDate("getDateForDB(date, myContext)", 161 DateTime.getDateForDB(date, myContext)); 162 } 163 164 public void testNullDate() throws Exception { 165 166 Date date = null; 167 168 System.out.println("======================================="); 169 System.out.println("testNullDate\n"); 170 171 checkNullDate("getDateTimeForDB(date, myContext)", 172 DateTime.getDateTimeForDB(date, myContext)); 173 checkNullDate("getDateTimeForDB(date)", 174 DateTime.getDateTimeForDB(date)); 175 checkNullDate("getDateTimeString(date)", 176 DateTime.getDateTimeString(date)); 177 checkNullDate("getTimeForDB(date)", 178 DateTime.getTimeForDB(date)); 179 checkNullDate("getTimeForDB(date, myContext)", 180 DateTime.getTimeForDB(date, myContext)); 181 checkNullDate("getDateForDB(date)", 182 DateTime.getDateForDB(date)); 183 checkNullDate("getDateForDB(date, myContext)", 184 DateTime.getDateForDB(date, myContext)); 185 186 } 187 188 public void testBadDate1() throws Exception { 189 190 int year = -1; 191 int month = -1; 192 int day = -1; 193 int hour = -1; 194 int min = -1; 195 int sec = -1; 196 Calendar aCalendar = Calendar.getInstance(); 197 aCalendar.set(year, month, day, hour, min, sec); 198 199 System.out.println("======================================="); 200 System.out.println("testBadDate\n"); 201 System.out.println("year = " + year); 202 System.out.println("month = " + month); 203 System.out.println("day = " + day); 204 System.out.println("hour = " + hour); 205 System.out.println("min = " + min); 206 System.out.println("sec = " + sec); 207 System.out.println(""); 208 209 System.out.println("getDateTimeForDB(year, month, day, hour, min, sec, myContext) : result " 210 + DateTime.getDateTimeForDB(year, month, day, hour, min, sec, myContext)); 211 System.out.println("getDateTimeForDB(year, month, day, hour, min, sec) : result " 214 + DateTime.getDateTimeForDB(year, month, day, hour, min, sec)); 215 System.out.println("getTimeForDB(hour, min, sec) : result " 216 + DateTime.getTimeForDB(hour, min, sec)); 217 System.out.println("getDateForDB(year, month, day) : result " 218 + DateTime.getDateForDB(year, month, day)); 219 220 } 221 222 public void testBadDate2() throws Exception { 223 224 int year = 99999; 225 int month = 99; 226 int day = 99; 227 int hour = 99; 228 int min = 99; 229 int sec = 99; 230 Calendar aCalendar = Calendar.getInstance(); 231 aCalendar.set(year, month, day, hour, min, sec); 232 233 System.out.println("======================================="); 234 System.out.println("testBadDate2\n"); 235 System.out.println("year = " + year); 236 System.out.println("month = " + month); 237 System.out.println("day = " + day); 238 System.out.println("hour = " + hour); 239 System.out.println("min = " + min); 240 System.out.println("sec = " + sec); 241 System.out.println(""); 242 243 System.out.println("getDateTimeForDB(year, month, day, hour, min, sec," + 244 " myContext) : result " 245 + DateTime.getDateTimeForDB(year, month, 246 day, hour, min, sec, myContext)); 247 System.out.println("getDateTimeForDB(year, month, day, hour, min, sec) : result " + 250 DateTime.getDateTimeForDB(year, month, day, 251 hour, min, sec)); 252 System.out.println("getTimeForDB(hour, min, sec) : result " + 253 DateTime.getTimeForDB(hour, min, sec)); 254 System.out.println("getDateForDB(year, month, day) : result " + 255 DateTime.getDateForDB(year, month, day)); 256 } 257 258 259 public static void main(String args[]) 260 throws Exception { 261 TestRunner.run(suite()); 262 } 263 264 } 265 266 | Popular Tags |