package cz.encircled.macl;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author Vlad on 01-Nov-17.
 */
public class ExecutorTest extends AbstractTest {

    @Before
    public void before() {
        Assume.assumeTrue(new File(path()).canWrite());

        File file = new File(path());
        if (file.exists()) {
            file.delete();
        }

        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            Files.write(Paths.get(path()), changelog_A(newMessagesUnfiltered()), Charset.forName("UTF-8"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void endToEndTest() {
        executor(
                new ChangelogConfiguration()
                        .setMergeRequestReplacePattern("(\\])")
                        .setMergeRequestReplacement(" MR#$1)")
                        .setCommitFormat(".*")
                        .setLastTagPattern(".*\\[([\\d\\.]+)].*")
                        .setLastTagFormat("%s")
                        .setPathToChangelog(path())
                        .setUnreleasedRowPattern("## \\[Unreleased]")
                        .setApplicableCommitPattern(".*\\(.*")
        ).run(consoleLog());
    }

    private String path() {
        return "target\\test-changelog.md";
    }

}

@@ -322,16 +322,42 @@
 Test %7B%0A%0A
+    private String path;%0A%0A
     @Bef
@@ -399,189 +399,53 @@
     
-Assume.assumeTrue(new File(path()).canWrite());%0A%0A        File file = new File(path());%0A        if (file.exists()) %7B%0A            file.delete();%0A        %7D%0A%0A        try %7B%0A            f
+File file;%0A        try %7B%0A            file = F
 ile.
@@ -454,82 +454,73 @@
 eate
-New
+Temp
 File(
-);%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace
+%22test-changelog%22, %22md%22);%0A            path = file.getPath
 ();%0A
@@ -530,26 +530,23 @@
     
- %7D%0A%0A
      
-   
 try %7B%0A
+    
     
@@ -579,18 +579,16 @@
 get(path
-()
 ), chang
@@ -655,16 +655,20 @@
         
+  
+  
 %7D catch 
@@ -681,24 +681,28 @@
 eption e) %7B%0A
+    
             
@@ -732,16 +732,97 @@
 ion(e);%0A
+            %7D%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A
         
@@ -869,24 +869,61 @@
 EndTest() %7B%0A
+        Assume.assumeNotNull(path);%0A%0A
         exec
@@ -1309,18 +1309,16 @@
 log(path
-()
 )%0A      
@@ -1484,85 +1484,6 @@
  %7D%0A%0A
-    private String path() %7B%0A        return %22target%5C%5Ctest-changelog.md%22;%0A    %7D%0A%0A
 %7D%0A

Test temp file