package com.icosillion.podengine.utils;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class DateUtilsTest {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);

    @Test
    public void parsesStandardDateFormats() {
        String dateTime = "Tue, 03 March 2009 15:00:00 -0000";

        Date date = DateUtils.stringToDate(dateTime);

        assertNotNull(date);
        assertEquals("Tue, 03 Mar 2009 16:00:00 +0100", sdf.format(date));
    }

    @Test
    public void parsesNonStandardDateFormats() {
        assertEquals("Tue, 03 Mar 2009 16:00:00 +0100",
                     sdf.format(DateUtils.stringToDate("Tues, 03 March 2009 15:00:00 -0000")));

        assertEquals("Wed, 04 Mar 2009 16:00:00 +0100",
                     sdf.format(DateUtils.stringToDate("Wednes, 04 March 2009 15:00:00 -0000")));

        assertEquals("Thu, 05 Mar 2009 16:00:00 +0100",
                     sdf.format(DateUtils.stringToDate("Thurs, 05 March 2009 15:00:00 -0000")));
    }

}

@@ -58,16 +58,49 @@
 .Test;%0A%0A
+import java.text.ParseException;%0A
 import j
@@ -265,16 +265,53 @@
 NotNull;
+%0Aimport static org.junit.Assert.fail;
 %0A%0Apublic
@@ -683,33 +683,33 @@
 e, 03 Mar 2009 1
-6
+5
 :00:00 +0100%22, s
@@ -697,25 +697,25 @@
  15:00:00 +0
-1
+0
 00%22, sdf.for
@@ -796,36 +796,85 @@
 ) %7B%0A        
-assertEquals
+try %7B%0A            assertEquals(%0A                    sdf.parse
 (%22Tue, 03 Ma
@@ -887,32 +887,33 @@
  16:00:00 +0100%22
+)
 ,%0A              
@@ -914,36 +914,24 @@
             
- sdf.format(
 DateUtils.st
@@ -982,33 +982,80 @@
 00%22)
-));%0A%0A        assertEquals
+%0A            );%0A%0A            assertEquals(%0A                    sdf.parse
 (%22We
@@ -1076,32 +1076,33 @@
  16:00:00 +0100%22
+)
 ,%0A              
@@ -1103,36 +1103,24 @@
             
- 
-sdf.format(
 DateUtils.st
@@ -1169,17 +1169,29 @@
  -0000%22)
-)
+%0A            
 );%0A%0A    
@@ -1186,32 +1186,36 @@
     );%0A%0A        
+    
 assertEquals(%22Th
@@ -1211,16 +1211,47 @@
 tEquals(
+%0A                    sdf.parse(
 %22Thu, 05
@@ -1275,16 +1275,17 @@
 0 +0100%22
+)
 ,%0A      
@@ -1298,28 +1298,16 @@
         
- sdf.format(
 DateUtil
@@ -1359,19 +1359,141 @@
  -0000%22)
-));
+%0A            );%0A        %7D catch (ParseException ex) %7B%0A            fail(%22Failed to parse date: %22 + ex.getMessage());%0A        %7D
 %0A    %7D%0A%0A

Fix DateUtils tests