001package org.apache.turbine.services.pull.util;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.Calendar;
023import java.util.Date;
024import java.util.GregorianCalendar;
025
026import org.junit.Test;
027
028import static org.junit.Assert.*;
029
030/**
031 * Test class for DateFormatter.
032 *
033 * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
034 * @version $Id: DateFormatterTest.java 1812628 2017-10-19 12:34:25Z gk $
035 */
036public class DateFormatterTest
037{
038
039//    /*
040//     * Class under test for String format(Date)
041//     */
042//    public void testFormatDate()
043//    {
044//        // Need configuration to test.
045//    }
046
047    /*
048     * Class under test for String format(Date, String)
049     */
050    @Test public void testFormatDateString()
051    {
052        Calendar cal = new GregorianCalendar();
053        DateFormatter df = new DateFormatter();
054        int day = cal.get(Calendar.DAY_OF_MONTH);
055        int month = cal.get(Calendar.MONTH) + 1; // zero based
056        int year = cal.get(Calendar.YEAR);
057        String dayString = (day < 10 ? "0" : "") + day;
058        String monthString = (month < 10 ? "0" : "") + month;
059        String ddmmyyyy = dayString + "/" + monthString + "/" + year;
060        assertEquals(ddmmyyyy, df.format(cal.getTime(), "dd/MM/yyyy"));
061
062        String mmddyyyy = "" + monthString + "/" + dayString + "/" + year;
063        assertEquals(mmddyyyy, df.format(cal.getTime(), "MM/dd/yyyy"));
064    }
065
066    /*
067     * Class under test for String format(null, String)
068     */
069    @Test public void testFormatDateStringNullString()
070    {
071        DateFormatter df = new DateFormatter();
072        assertEquals("null argument should produce an empty String",
073                "", df.format(null, "MM/dd/yyyy"));
074    }
075
076    /*
077     * Class under test for String format(Date, "")
078     */
079    @Test public void testFormatDateStringEmptyString()
080    {
081        Date today = new Date();
082        DateFormatter df = new DateFormatter();
083        assertEquals("Empty pattern should produce empty String",
084                "", df.format(today, ""));
085    }
086
087    /*
088     * Class under test for String format(Date, "")
089     */
090    @Test public void testFormatDateStringNullFormat()
091    {
092        Date today = new Date();
093        DateFormatter df = new DateFormatter();
094        assertEquals("null pattern should produce empty String",
095                "", df.format(today, null));
096    }
097
098}