package com.github.sfleiter.cdi_interceptors.impl;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.TimeZone;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class StringTransformerTest {

    private StringTransformer stringTransformer;
    private StringBuilder sb;
    private Object input;
    private String expected;
    private int maximumCount;

    public StringTransformerTest(Object input, String expected, int maximumCount) {
        this.input = input;
        this.expected = expected;
        this.maximumCount = maximumCount;
    }
    
    @Before
    public void setUp() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        stringTransformer = new StringTransformer();
        sb = new StringBuilder();
    }
    @After
    public void tearDown() {
        TimeZone.setDefault(null);
    }
    
    @Parameters
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][] {
                { null, "null", Integer.MAX_VALUE },
                
                { "a" , "a", Integer.MAX_VALUE },
                { 1 , "1", Integer.MAX_VALUE },
                { -1 , "-1", Integer.MAX_VALUE },
                
                { new Date(0), "Thu Jan 01 00:00:00 GMT 1970", Integer.MAX_VALUE },
                
                { new Object[] { 1 }, "Collection[size=1, 1]", Integer.MAX_VALUE },
                { new Object[] { 1, "a", null, new Date(0) }, 
                    "Collection[size=4, 1, a, null, Thu Jan 01 00:00:00 GMT 1970]", 
                    Integer.MAX_VALUE },
                { new Object[] { 1, "a", null, new Date(0) }, 
                    "Collection[size=4, 1, a, null, ...]", 
                    3 },

                { new Object[] { 1, "a", new Object[] { "b", 2, new Date(1000) }, new Date(0) }, 
                    "Collection[size=4, 1, a, Collection[size=3, b, 2, Thu Jan 01 00:00:01 GMT 1970], Thu Jan 01 00:00:00 GMT 1970]", 
                    Integer.MAX_VALUE },

        });
    }
    
    @Test
    public void test() {
        stringTransformer.transform(sb, input, maximumCount);
        assertEquals(expected, sb.toString());
    }

}

@@ -80,9 +80,20 @@
 ert.
-*
+assertEquals
 ;%0A%0Ai
@@ -120,35 +120,8 @@
 ys;%0A
-import java.util.Calendar;%0A
 impo
@@ -149,82 +149,8 @@
 on;%0A
-import java.util.Date;%0Aimport java.util.TimeZone;%0A%0Aimport org.junit.After;
 %0Aimp
@@ -385,16 +385,169 @@
 erTest %7B
+%0A    %0A    static class IH %7B%0A        private int i;%0A        public IH(int i) %7B this.i = i; %7D%0A        public String toString() %7B return %22IH: %22 + i; %7D%0A    %7D
 %0A%0A    pr
@@ -946,66 +946,8 @@
 ) %7B%0A
-        TimeZone.setDefault(TimeZone.getTimeZone(%22GMT%22));%0A
     
@@ -1039,89 +1039,8 @@
   %7D%0A
-    @After%0A    public void tearDown() %7B%0A        TimeZone.setDefault(null);%0A    %7D%0A
     
@@ -1411,46 +1411,21 @@
 new 
-Date(0), %22Thu Jan 01 00:00:00 GMT 1970
+IH(5), %22IH: 5
 %22, I
@@ -1588,38 +1588,36 @@
  %22a%22, null, new 
-Date(0
+IH(5
 ) %7D, %0A          
@@ -1662,36 +1662,13 @@
 ll, 
-Thu Jan 01 00:00:00 GMT 1970
+IH: 5
 %5D%22, 
@@ -1756,30 +1756,28 @@
 , null, new 
-Date(0
+IH(5
 ) %7D, %0A      
@@ -1928,17 +1928,12 @@
 new 
-Date(1000
+IH(6
 ) %7D,
@@ -1941,14 +1941,12 @@
 new 
-Date(0
+IH(5
 ) %7D,
@@ -2022,67 +2022,21 @@
  2, 
-Thu Jan 01 00:00:01 GMT 1970%5D, Thu Jan 01 00:00:00 GMT 1970
+IH: 6%5D, IH: 5
 %5D%22, 

make StringTransformerTest shorter and easier to understand by using a special Object IH instead of Date