1 package org.apache.turbine.services.pull.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Calendar;
20 import java.util.Date;
21 import java.util.GregorianCalendar;
22
23 import junit.framework.TestCase;
24
25 /***
26 * Test class for DateFormatter.
27 *
28 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
29 * @version $Id: DateFormatterTest.java 264148 2005-08-29 14:21:04Z henning $
30 */
31 public class DateFormatterTest extends TestCase
32 {
33
34
35
36
37
38
39
40
41
42
43
44
45 public void testFormatDateString()
46 {
47 Calendar cal = new GregorianCalendar();
48 DateFormatter df = new DateFormatter();
49 int day = cal.get(Calendar.DAY_OF_MONTH);
50 int month = cal.get(Calendar.MONTH) + 1;
51 int year = cal.get(Calendar.YEAR);
52 String dayString = (day < 10 ? "0" : "") + day;
53 String monthString = (month < 10 ? "0" : "") + month;
54 String ddmmyyyy = dayString + "/" + monthString + "/" + year;
55 assertEquals(ddmmyyyy, df.format(cal.getTime(), "dd/MM/yyyy"));
56
57 String mmddyyyy = "" + monthString + "/" + dayString + "/" + year;
58 assertEquals(mmddyyyy, df.format(cal.getTime(), "MM/dd/yyyy"));
59 }
60
61
62
63
64 public void testFormatDateStringNullString()
65 {
66 DateFormatter df = new DateFormatter();
67 assertEquals("null argument should produce an empty String",
68 "", df.format(null, "MM/dd/yyyy"));
69 }
70
71
72
73
74 public void testFormatDateStringEmptyString()
75 {
76 Date today = new Date();
77 DateFormatter df = new DateFormatter();
78 assertEquals("Empty pattern should produce empty String",
79 "", df.format(today, ""));
80 }
81
82
83
84
85 public void testFormatDateStringNullFormat()
86 {
87 Date today = new Date();
88 DateFormatter df = new DateFormatter();
89 assertEquals("null pattern should produce empty String",
90 "", df.format(today, null));
91 }
92
93 }