package cucumber.runtime.formatter;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import gherkin.formatter.model.Step;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;

import org.junit.Test;

import cucumber.runtime.Backend;
import cucumber.runtime.Runtime;
import cucumber.runtime.RuntimeOptions;
import cucumber.runtime.io.ClasspathResourceLoader;

public class JSONPrettyFormatterTest {

    @Test
    public void featureWithOutlineTest() throws Exception {
        File report = runFeaturesWithJSONPrettyFormatter(asList("cucumber/runtime/formatter/JSONPrettyFormatterTest.feature"));
        String expected = new Scanner(getClass().getResourceAsStream("JSONPrettyFormatterTest.json"), "UTF-8").useDelimiter("\\A").next();
        String actual = new Scanner(report, "UTF-8").useDelimiter("\\A").next();
        assertEquals(expected, actual);
    }

    private File runFeaturesWithJSONPrettyFormatter(final List<String> featurePaths) throws IOException {
        File report = File.createTempFile("cucumber-jvm-junit", ".json");
        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);

        List<String> args = new ArrayList<String>();
        args.add("--format");
        args.add("json-pretty:" + report.getAbsolutePath());
        args.addAll(featurePaths);

        RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties(), args.toArray(new String[args.size()]));
        Backend backend = mock(Backend.class);
        when(backend.getSnippet(any(Step.class))).thenReturn("TEST SNIPPET");
        final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(backend), runtimeOptions);
        runtime.run();
        return report;
    }

}

@@ -980,32 +980,272 @@
 (%22%5C%5CA%22).next();%0A
+        expected = expected.replace(%22cucumber/runtime/formatter/JSONPrettyFormatterTest.feature%22, %22cucumber%22 + File.separator + %22runtime%22%0A                + File.separator + %22formatter%22 + File.separator + %22JSONPrettyFormatterTest.feature%22);%0A
         String a

Fix for Windows OS