01: package org.uispec4j.utils;
02:
03: import java.util.Calendar;
04: import java.util.Date;
05: import java.util.Locale;
06: import java.text.SimpleDateFormat;
07: import java.text.DateFormat;
08:
09: public class DateUtilsTest extends UnitTestCase {
10:
11: private Date date = getDate(1974, Calendar.NOVEMBER, 23, 19, 55, 0);
12:
13: public void testDate() throws Exception {
14: assertEquals(date.toString(), DateUtils.getDate(
15: "1974.11.23 19:55").toString());
16: }
17:
18: public void testStandard() throws Exception {
19: assertEquals("1974.11.23 19:55", DateUtils
20: .getStandardDate(date));
21: }
22:
23: public void testFormatted() throws Exception {
24: Locale defaultLocale = Locale.getDefault();
25: Locale.setDefault(new Locale("en", "us"));
26: assertEquals("November 23, 1974 7:55 PM",
27: getFormattedDate(date));
28: Locale.setDefault(defaultLocale);
29: }
30:
31: public void testSetDateFormat() throws Exception {
32: Date date = getDate(2003, Calendar.DECEMBER, 25, 12, 0, 0);
33:
34: DateUtils.setDateFormat(new SimpleDateFormat("yyyy.MM.dd"));
35: assertEquals("2003.12.25", DateUtils.getStandardDate(date));
36:
37: DateUtils.setDateFormat(DateUtils.DEFAULT_DATE_FORMAT);
38: assertEquals("2003.12.25 12:00", DateUtils
39: .getStandardDate(date));
40: }
41:
42: private static String getFormattedDate(Date date) {
43: return DateFormat.getDateTimeInstance(DateFormat.LONG,
44: DateFormat.SHORT).format(date);
45: }
46:
47: private static Date getDate(int year, int month, int day, int hour,
48: int minute, int second) {
49: Calendar calendar = Calendar.getInstance();
50: calendar.set(year, month, day, hour, minute, second);
51: return calendar.getTime();
52: }
53: }
|