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