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 org.junit.Test;
27
28 import static org.junit.Assert.*;
29
30
31
32
33
34
35
36 public class DateFormatterTest
37 {
38
39
40
41
42
43
44
45
46
47
48
49
50 @Test public void testFormatDateString()
51 {
52 Calendar cal = new GregorianCalendar();
53 DateFormatter df = new DateFormatter();
54 int day = cal.get(Calendar.DAY_OF_MONTH);
55 int month = cal.get(Calendar.MONTH) + 1;
56 int year = cal.get(Calendar.YEAR);
57 String dayString = (day < 10 ? "0" : "") + day;
58 String monthString = (month < 10 ? "0" : "") + month;
59 String ddmmyyyy = dayString + "/" + monthString + "/" + year;
60 assertEquals(ddmmyyyy, df.format(cal.getTime(), "dd/MM/yyyy"));
61
62 String mmddyyyy = "" + monthString + "/" + dayString + "/" + year;
63 assertEquals(mmddyyyy, df.format(cal.getTime(), "MM/dd/yyyy"));
64 }
65
66
67
68
69 @Test public void testFormatDateStringNullString()
70 {
71 DateFormatter df = new DateFormatter();
72 assertEquals("null argument should produce an empty String",
73 "", df.format(null, "MM/dd/yyyy"));
74 }
75
76
77
78
79 @Test public void testFormatDateStringEmptyString()
80 {
81 Date today = new Date();
82 DateFormatter df = new DateFormatter();
83 assertEquals("Empty pattern should produce empty String",
84 "", df.format(today, ""));
85 }
86
87
88
89
90 @Test public void testFormatDateStringNullFormat()
91 {
92 Date today = new Date();
93 DateFormatter df = new DateFormatter();
94 assertEquals("null pattern should produce empty String",
95 "", df.format(today, null));
96 }
97
98 }