package org.easybatch.core.util;

import org.easybatch.core.beans.Person;
import org.junit.Test;

import java.lang.reflect.Method;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.easybatch.core.job.JobParameters.DEFAULT_ERROR_THRESHOLD;

public class UtilsTest {

    @Test
    public void testGetGetters() throws Exception {
        Map<String, Method> getters = Utils.getGetters(Person.class);

        assertThat(getters)
                .hasSize(6)
                .containsKeys("firstName", "lastName", "age", "birthDate", "married", "gender");
    }

    @Test
    public void testFormatTime() throws Exception {
        assertThat(Utils.formatTime(1475149183447L)).isEqualTo("2016-09-29 01:39:43");
    }

    @Test
    public void testFormatDuration() throws Exception {
        assertThat(Utils.formatDuration(100)).isEqualTo("0hr 0min 0sec 100ms");
        assertThat(Utils.formatDuration(1000)).isEqualTo("0hr 0min 1sec 0ms");
        assertThat(Utils.formatDuration(60 * 2 * 1000)).isEqualTo("0hr 2min 0sec 0ms");
        assertThat(Utils.formatDuration(60 * 60 * 2 * 1000)).isEqualTo("2hr 0min 0sec 0ms");
    }

    @Test
    public void testFormatErrorThreshold() throws Exception {
        assertThat(Utils.formatErrorThreshold(1)).isEqualTo("1");
        assertThat(Utils.formatErrorThreshold(5)).isEqualTo("5");
        assertThat(Utils.formatErrorThreshold(DEFAULT_ERROR_THRESHOLD)).isEqualTo("N/A");
    }

}
@@ -124,16 +124,43 @@
 Method;%0A
+import java.util.Calendar;%0A
 import j
@@ -173,16 +173,16 @@
 il.Map;%0A
-
 %0Aimport 
@@ -335,16 +335,222 @@
 Test %7B%0A%0A
+    private static long TIME;%0A%0A    static %7B%0A        Calendar calendar = Calendar.getInstance();%0A        calendar.set(2015, Calendar.JANUARY, 1, 1, 0, 0);%0A        TIME = calendar.getTime().getTime();%0A    %7D%0A%0A
     @Tes
@@ -936,22 +936,12 @@
 ime(
-1475149183447L
+TIME
 )).i
@@ -957,24 +957,24 @@
 %22201
-6-09-29 01:39:43
+5-01-01 01:00:00
 %22);%0A

use fixed time in UtilsTest