package org.apache.velocity.tools.generic;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Locale;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
//import org.apache.velocity.tools.generic.DateTool;

/**
 * <p>Tests for DateToolTests</p>
 *
 * @author Christopher Schultz
 * @since VelocityTools 2.0.1
 * @version $Id$
 */
public class DateToolTests
{
    public @Test void toLocalizedPattern_simplePattern() throws Exception
    {
        DateTool dt = new DateTool();

        Locale frFR = new Locale("fr", "FR");

        assertEquals("DateTool incorrectly localizes date format pattern",
                     new SimpleDateFormat("yyyy-MM-dd", frFR).toLocalizedPattern(), // "aaaa-MM-jj"
                     dt.toLocalizedPattern("yyyy-MM-dd", frFR));
    }

    public @Test void toLocalizedPattern_predefinedDateTimePattern() throws Exception
    {
        DateTool dt = new DateTool();

        Locale frFR = new Locale("fr", "FR");

        assertEquals("DateTool incorrectly localizes date format pattern",
                     ((SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, frFR)).toLocalizedPattern(),
                     dt.toLocalizedPattern("short", frFR));
    }

    public @Test void toLocalizedPattern_predefinedDatePattern() throws Exception
    {
        DateTool dt = new DateTool();

        Locale frFR = new Locale("fr", "FR");

        assertEquals("DateTool incorrectly localizes date format pattern",
                     ((SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT, frFR)).toLocalizedPattern(),
                     dt.toLocalizedPattern("short_date", frFR));
    }

    public @Test void toLocalizedPattern_predefinedTimePattern() throws Exception
    {
        DateTool dt = new DateTool();

        Locale frFR = new Locale("fr", "FR");

        assertEquals("DateTool incorrectly localizes date format pattern",
                     ((SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, frFR)).toLocalizedPattern(),
                     dt.toLocalizedPattern("short_time", frFR));
    }
}

@@ -1171,16 +1171,39 @@
 .fail;%0A%0A
+import java.util.Date;%0A
 import j
@@ -1283,16 +1283,43 @@
 Format;%0A
+import java.util.TimeZone;%0A
 //import
@@ -3253,11 +3253,383 @@
 );%0A    %7D
+%0A%0A    public @Test void toIsoFormat() throws Exception%0A    %7B%0A        DateTool dt = new DateTool();%0A        Date date = new Date();%0A        dt.setTimeZone(TimeZone.getTimeZone(%22CET%22));%0A        assertEquals(%22DateTool incorrectly formatted iso format%22,%0A                new SimpleDateFormat(%22yyyy-MM-dd HH:mm:ssXXX%22).format(date),%0A                dt.format(%22iso%22,date));%0A    %7D
 %0A%7D%0A

add iso format test