package com.versionone.hudson;

import hudson.scm.SubversionChangeLogSet;
import junit.framework.Assert;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Test;

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

public class SvnModificationTest {
    private Mockery mockery = new Mockery() {
        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };

    @Test
    public void getDate() throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
        final String gmtDate = "2012-01-12T08:43:41.359375Z";//SVN plugin returns date in GMT
        final String localDateWithoutMicrosecond = "2012-01-12T11:43:41.359Z";
        SvnModification modification = CreateSvnModification(gmtDate);

        Date date = modification.getDate();
        Assert.assertEquals(dateFormat.parse(localDateWithoutMicrosecond), date);
    }

    @Test
    public void getDateWithoutMicrosecond() throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
        final String gmtDate = "2012-01-12T08:43:41.359Z";//SVN plugin returns date in GMT
        final String localDate = "2012-01-12T11:43:41.359Z";
        SvnModification modification = CreateSvnModification(gmtDate);

        Date date = modification.getDate();
        Assert.assertEquals(dateFormat.parse(localDate), date);
    }

    private SvnModification CreateSvnModification(final String strDate) {
        final SubversionChangeLogSet.LogEntry changeSet = mockery.mock(SubversionChangeLogSet.LogEntry.class);

        SvnModification modification = new SvnModification(changeSet);
        mockery.checking(new Expectations() {
            {
                allowing(changeSet).getDate();
                will(returnValue(strDate));
            }
        });
        return modification;
    }
}

@@ -354,16 +354,44 @@
 Locale;%0D
+%0Aimport java.util.TimeZone;%0D
 %0A%0D%0Apubli
@@ -703,32 +703,96 @@
 :mm:ss.S'Z'%22);%0D%0A
+        dateFormat.setTimeZone(TimeZone.getTimeZone(%22GMT+4%22));%0D%0A
         final St
@@ -926,33 +926,33 @@
  = %222012-01-12T1
-1
+2
 :43:41.359Z%22;%0D%0A 
@@ -1320,32 +1320,107 @@
 T'HH:mm:ss.S'Z'%22
+, Locale.US);%0D%0A        dateFormat.setTimeZone(TimeZone.getTimeZone(%22GMT+4%22)
 );%0D%0A        fina
@@ -1545,17 +1545,17 @@
 -01-12T1
-1
+2
 :43:41.3

fix tests