package org.apache.log4j.config;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */

@RunWith(Parameterized.class)
public abstract class AbstractLog4j1ConfigurationConverterTest {

    private static String outputFile = "target/log4j1-log4j2.txt";

    protected static List<Path> getPaths(final String root) throws IOException {
        final List<Path> paths = new ArrayList<>();
        Files.walkFileTree(Paths.get(root), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
                paths.add(file.toAbsolutePath());
                return FileVisitResult.CONTINUE;
            }
        });
        return paths;
    }

    private final Path pathIn;
    private final Path pathOut;

    public AbstractLog4j1ConfigurationConverterTest(final Path path) {
        super();
        this.pathIn = path;
        File file = new File(outputFile);
        this.pathOut = file.toPath();
    }

    @Test
    public void test() throws IOException {
        final Path tempFile = Files.createTempFile("log4j", ".xml");
        try {
            final Log4j1ConfigurationConverter.CommandLineArguments cla = new Log4j1ConfigurationConverter.CommandLineArguments();
            cla.setPathIn(pathIn);
            cla.setPathOut(tempFile);
            Log4j1ConfigurationConverter.run(cla);
        } finally {
            Files.deleteIfExists(tempFile);
        }
    }
}

@@ -31,29 +31,8 @@
 g;%0A%0A
-import java.io.File;%0A
 impo
@@ -320,16 +320,40 @@
 .List;%0A%0A
+import org.junit.After;%0A
 import o
@@ -2100,77 +2100,43 @@
     
-File file = new File(outputFile);%0A        this.pathOut = file.toPath(
+this.pathOut = Paths.get(outputFile
 );%0A 
@@ -2146,20 +2146,21 @@
 %7D%0A%0A    @
-Test
+After
 %0A    pub
@@ -2170,18 +2170,22 @@
  void te
-st
+arDown
 () throw
@@ -2212,87 +2212,85 @@
     
-final Path tempFile = Files.createTempFile(%22log4j%22, %22.xml%22
+Files.deleteIfExists(pathOut
 );%0A    
+%7D%0A
     
-try %7B
 %0A    
+@Test%0A    public void test() %7B%0A
     
@@ -2412,36 +2412,32 @@
 ents();%0A        
-    
 cla.setPathIn(pa
@@ -2447,28 +2447,24 @@
 n);%0A        
-    
 cla.setPathO
@@ -2466,31 +2466,26 @@
 PathOut(
-tempFile);%0A    
+pathOut);%0A
         
@@ -2527,82 +2527,8 @@
 a);%0A
-        %7D finally %7B%0A            Files.deleteIfExists(tempFile);%0A        %7D%0A
     

Delete temp test file.