package com.aventstack.extentreports.reporter;

import java.io.File;
import java.util.Calendar;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentReports;

public class FileReporterPathsTest {

    private ExtentReports getExtent(String r, String f) {
        ExtentReports extent = new ExtentReports();
        if (r == "spark")
            extent.attachReporter(new ExtentSparkReporter(f));
        else
            extent.attachReporter(new JsonFormatter(f));
        extent.createTest("Test").pass("Pass");
        extent.flush();
        return extent;
    }

    private String getFileName(String ext) {
        final String basePath = "target/";
        long t = Calendar.getInstance().getTimeInMillis();
        String fileName = basePath + t + ext;
        return fileName;
    }

    @Test
    public void sparkPathAsFile() {
        String f = getFileName(".html");
        getExtent("spark", f);
        Assert.assertTrue(new File(f).exists());
    }

    @Test
    public void sparkPathAsDirectory() {
        String f = getFileName("");
        getExtent("spark", f);
        Assert.assertFalse(new File(f).exists());
        Assert.assertTrue(new File(f + ".html").exists());
    }

    @Test
    public void jsonPathAsFile() {
        String f = getFileName(".json");
        getExtent("json", f);
        Assert.assertTrue(new File(f).exists());
    }

    @Test
    public void jsonPathAsDirectory() {
        String f = getFileName("");
        getExtent("json", f);
        Assert.assertFalse(new File(f).exists());
        Assert.assertTrue(new File(f + ".json").exists());
    }
}

@@ -1144,36 +1144,35 @@
    Assert.assert
-Fals
+Tru
 e(new File(f).ex
@@ -1220,16 +1220,22 @@
 le(f + %22
+/Index
 .html%22).
@@ -1565,12 +1565,11 @@
 sert
-Fals
+Tru
 e(ne
@@ -1629,16 +1629,23 @@
 le(f + %22
+/extent
 .json%22).

fix tests for v4 path creation style