01: package org.apache.turbine.services.pull.util;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: // * Class under test for String format(Date)
38: // */
39: // public void testFormatDate()
40: // {
41: // // Need configuration to test.
42: // }
43:
44: /*
45: * Class under test for String format(Date, String)
46: */
47: public void testFormatDateString() {
48: Calendar cal = new GregorianCalendar();
49: DateFormatter df = new DateFormatter();
50: int day = cal.get(Calendar.DAY_OF_MONTH);
51: int month = cal.get(Calendar.MONTH) + 1; // zero based
52: int year = cal.get(Calendar.YEAR);
53: String dayString = (day < 10 ? "0" : "") + day;
54: String monthString = (month < 10 ? "0" : "") + month;
55: String ddmmyyyy = dayString + "/" + monthString + "/" + year;
56: assertEquals(ddmmyyyy, df.format(cal.getTime(), "dd/MM/yyyy"));
57:
58: String mmddyyyy = "" + monthString + "/" + dayString + "/"
59: + year;
60: assertEquals(mmddyyyy, df.format(cal.getTime(), "MM/dd/yyyy"));
61: }
62:
63: /*
64: * Class under test for String format(null, String)
65: */
66: public void testFormatDateStringNullString() {
67: DateFormatter df = new DateFormatter();
68: assertEquals("null argument should produce an empty String",
69: "", df.format(null, "MM/dd/yyyy"));
70: }
71:
72: /*
73: * Class under test for String format(Date, "")
74: */
75: public void testFormatDateStringEmptyString() {
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: * Class under test for String format(Date, "")
84: */
85: public void testFormatDateStringNullFormat() {
86: Date today = new Date();
87: DateFormatter df = new DateFormatter();
88: assertEquals("null pattern should produce empty String", "", df
89: .format(today, null));
90: }
91:
92: }
|