package org.easybatch.core.job;

import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;

import static org.easybatch.core.util.Utils.LINE_SEPARATOR;

public class DefaultJobReportFormatterTest {

    private JobReport report;

    private DefaultJobReportFormatter reportFormatter;

    @Before
    public void setUp() throws Exception {
        JobParameters parameters = new JobParameters();
        JobMetrics metrics = new JobMetrics();
        metrics.setStartTime(1475149183447L);
        metrics.setEndTime(1475152215457L);
        report = new JobReport();
        report.setParameters(parameters);
        report.setMetrics(metrics);
        report.setJobName("job");
        report.setStatus(JobStatus.COMPLETED);
        reportFormatter = new DefaultJobReportFormatter();
    }

    @Test
    public void testFormatReport() throws Exception {
        String expectedReport = 
                "Job Report:" + LINE_SEPARATOR +
                "===========" + LINE_SEPARATOR +
                "Name: job" + LINE_SEPARATOR +
                "Status: COMPLETED" + LINE_SEPARATOR +
                "Parameters:" + LINE_SEPARATOR +
                "\tBatch size = 100" + LINE_SEPARATOR +
                "\tError threshold = N/A" + LINE_SEPARATOR +
                "\tJmx monitoring = false" + LINE_SEPARATOR +
                "Metrics:" + LINE_SEPARATOR +
                "\tStart time = 2016-09-29 01:39:43" + LINE_SEPARATOR +
                "\tEnd time = 2016-09-29 02:30:15" + LINE_SEPARATOR +
                "\tDuration = 0hr 50min 32sec 10ms" + LINE_SEPARATOR +
                "\tRead count = 0" + LINE_SEPARATOR +
                "\tWrite count = 0" + LINE_SEPARATOR +
                "\tFiltered count = 0" + LINE_SEPARATOR +
                "\tError count = 0";

        String formattedReport = reportFormatter.formatReport(report);

        Assertions.assertThat(formattedReport).isEqualTo(expectedReport);
    }
}
@@ -115,16 +115,44 @@
 .Test;%0A%0A
+import java.util.Calendar;%0A%0A
 import s
@@ -250,16 +250,311 @@
 Test %7B%0A%0A
+    private static long START_TIME;%0A    private static long END_TIME;%0A%0A    static %7B%0A        Calendar calendar = Calendar.getInstance();%0A        calendar.set(2015, Calendar.JANUARY, 1, 1, 0, 0);%0A        START_TIME = calendar.getTime().getTime();%0A        END_TIME = START_TIME + 10 * 1000;%0A    %7D%0A%0A
     priv
@@ -823,22 +823,18 @@
 ime(
-1475149183447L
+START_TIME
 );%0A 
@@ -863,22 +863,16 @@
 ime(
-1475152215457L
+END_TIME
 );%0A 
@@ -1739,24 +1739,24 @@
  201
-6-09-29 01:39:43
+5-01-01 01:00:00
 %22 + 
@@ -1809,24 +1809,24 @@
  201
-6-09-29 02:30:15
+5-01-01 01:00:10
 %22 + 
@@ -1880,21 +1880,19 @@
 0hr 
-5
 0min 
-32
+10
 sec 
-1
 0ms%22

use fixed time for DefaultJobReportFormatterTest