1   package org.apache.turbine.services.pull.util;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  //     * Class under test for String format(Date)
36  //     */
37  //    public void testFormatDate()
38  //    {
39  //        // Need configuration to test.
40  //    }
41  
42      /*
43       * Class under test for String format(Date, String)
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; // zero based
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       * Class under test for String format(null, String)
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       * Class under test for String format(Date, "")
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       * Class under test for String format(Date, "")
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  }