    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 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  //     * Class under test for String format(Date)
    39  //     */
    40  //    public void testFormatDate()
    41  //    {
    42  //        // Need configuration to test.
    43  //    }
    44
    45      /*
    46       * Class under test for String format(Date, String)
    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; // zero based
    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       * Class under test for String format(null, String)
    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       * Class under test for String format(Date, "")
    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       * Class under test for String format(Date, "")
    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  }