/*-------------------------------------------------------------------------------------------------------------------*\
|  Copyright (C) 2015 PayPal                                                                                          |
|                                                                                                                     |
|  Licensed 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.                                     |
\*-------------------------------------------------------------------------------------------------------------------*/

package com.paypal.selion.reports.reporter.services;

import static org.testng.Assert.assertEquals;

import java.util.Date;
import java.util.TimeZone;

import org.testng.annotations.Test;

import com.paypal.selion.reports.reporter.services.ReporterDateFormatter;

public class ReporterDateFormatterTest {

    @Test(groups = "unit")
    public void testGetISO8601StringWithSpecificTimeZone() {

        Date dateValue = new Date(1421806893955L);
        String resultDateString = ReporterDateFormatter.getISO8601StringWithSpecificTimeZone(dateValue,
                TimeZone.getTimeZone("UTC"));
        assertEquals(resultDateString, "2015-01-21T02:21:33.955Z");

        dateValue = new Date(401324999000L);
        resultDateString = ReporterDateFormatter.getISO8601StringWithSpecificTimeZone(dateValue,
                TimeZone.getTimeZone("PST"));
        assertEquals(resultDateString, "1982-09-19T16:09:59.000-07:00");
    }

    @Test(groups = "unit")
    public void testGetStringFromISODateString() {

        String expectedString = "Jan 20, 2015 6:21 PM";

        String dateString = "2015-01-21T02:21:33.955Z";
        String resultDateString = ReporterDateFormatter.getStringFromISODateString(dateString);
        assertEquals(resultDateString, expectedString);

        dateString = "2015-01-20T18:21:33.955-08:00";
        resultDateString = ReporterDateFormatter.getStringFromISODateString(dateString);
        assertEquals(resultDateString, expectedString);

    }

}

@@ -1791,46 +1791,167 @@
 ava.
-util.Date;%0Aimport java.util.TimeZone;%0A
+text.ParseException;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Date;%0Aimport java.util.TimeZone;%0A%0Aimport org.apache.commons.lang.time.DateFormatUtils;
 %0Aimp
@@ -2803,16 +2803,38 @@
 String()
+ throws ParseException
  %7B%0A%0A    
@@ -2884,16 +2884,351 @@
 :21 PM%22;
+%0A        SimpleDateFormat sdf = new SimpleDateFormat(%22MMM dd, yyyy h:mm a%22);%0A        sdf.setTimeZone(TimeZone.getTimeZone(%22PST%22));%0A        Date date = sdf.parse(expectedString);%0A        // convert expected string from PST to local TZ.%0A        expectedString = DateFormatUtils.format(date, %22MMM dd, yyyy h:mm a%22, TimeZone.getDefault());
 %0A%0A      

Fix ReporterDateFormatterTest in CST