1 package org.apache.turbine.services.pull.util;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "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 org.junit.Test;
27
28 import static org.junit.Assert.*;
29
30 /**
31 * Test class for DateFormatter.
32 *
33 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
34 * @version $Id: DateFormatterTest.java 1812628 2017-10-19 12:34:25Z gk $
35 */
36 public class DateFormatterTest
37 {
38
39 // /*
40 // * Class under test for String format(Date)
41 // */
42 // public void testFormatDate()
43 // {
44 // // Need configuration to test.
45 // }
46
47 /*
48 * Class under test for String format(Date, String)
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; // zero based
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 * Class under test for String format(null, String)
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 * Class under test for String format(Date, "")
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 * Class under test for String format(Date, "")
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 }