/*
 * 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.
 */
package org.apache.commons.io;

import org.apache.commons.io.testtools.FileBasedTestCase;
import org.apache.commons.io.testtools.TestUtils;
import org.junit.After;
import org.junit.Test;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
 * Test for FileDeleteStrategy.
 *
 * @see FileDeleteStrategy
 */
public class FileDeleteStrategyTestCase extends FileBasedTestCase {

    //-----------------------------------------------------------------------
    @Test
    public void testDeleteNormal() throws Exception {
        final File baseDir = getTestDirectory();
        final File subDir = new File(baseDir, "test");
        assertTrue(subDir.mkdir());
        final File subFile = new File(subDir, "a.txt");
        if (!subFile.getParentFile().exists()) {
            throw new IOException("Cannot create file " + subFile
                    + " as the parent directory does not exist");
        }
        try (final BufferedOutputStream output =
                new BufferedOutputStream(new FileOutputStream(subFile))) {
            TestUtils.generateTestData(output, (long) 16);
        }

        assertTrue(subDir.exists());
        assertTrue(subFile.exists());
        // delete dir
        try {
            FileDeleteStrategy.NORMAL.delete(subDir);
            fail();
        } catch (final IOException ex) {
            // expected
        }
        assertTrue(subDir.exists());
        assertTrue(subFile.exists());
        // delete file
        FileDeleteStrategy.NORMAL.delete(subFile);
        assertTrue(subDir.exists());
        assertFalse(subFile.exists());
        // delete dir
        FileDeleteStrategy.NORMAL.delete(subDir);
        assertFalse(subDir.exists());
        // delete dir
        FileDeleteStrategy.NORMAL.delete(subDir);  // no error
        assertFalse(subDir.exists());
    }

    @Test
    public void testDeleteQuietlyNormal() throws Exception {
        final File baseDir = getTestDirectory();
        final File subDir = new File(baseDir, "test");
        assertTrue(subDir.mkdir());
        final File subFile = new File(subDir, "a.txt");
        if (!subFile.getParentFile().exists()) {
            throw new IOException("Cannot create file " + subFile
                    + " as the parent directory does not exist");
        }
        try (final BufferedOutputStream output =
                new BufferedOutputStream(new FileOutputStream(subFile))) {
            TestUtils.generateTestData(output, (long) 16);
        }

        assertTrue(subDir.exists());
        assertTrue(subFile.exists());
        // delete dir
        assertFalse(FileDeleteStrategy.NORMAL.deleteQuietly(subDir));
        assertTrue(subDir.exists());
        assertTrue(subFile.exists());
        // delete file
        assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(subFile));
        assertTrue(subDir.exists());
        assertFalse(subFile.exists());
        // delete dir
        assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(subDir));
        assertFalse(subDir.exists());
        // delete dir
        assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(subDir));  // no error
        assertFalse(subDir.exists());
    }

    @Test
    public void testDeleteForce() throws Exception {
        final File baseDir = getTestDirectory();
        final File subDir = new File(baseDir, "test");
        assertTrue(subDir.mkdir());
        final File subFile = new File(subDir, "a.txt");
        if (!subFile.getParentFile().exists()) {
            throw new IOException("Cannot create file " + subFile
                    + " as the parent directory does not exist");
        }
        try (final BufferedOutputStream output =
                new BufferedOutputStream(new FileOutputStream(subFile))) {
            TestUtils.generateTestData(output, (long) 16);
        }

        assertTrue(subDir.exists());
        assertTrue(subFile.exists());
        // delete dir
        FileDeleteStrategy.FORCE.delete(subDir);
        assertFalse(subDir.exists());
        assertFalse(subFile.exists());
        // delete dir
        FileDeleteStrategy.FORCE.delete(subDir);  // no error
        assertFalse(subDir.exists());
    }

    @Test
    public void testDeleteNull() throws Exception {
        try {
            FileDeleteStrategy.NORMAL.delete(null);
            fail();
        } catch (final NullPointerException ex) {
            // expected
        }
        assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(null));
    }

    @Test
    public void testToString() {
        assertEquals("FileDeleteStrategy[Normal]", FileDeleteStrategy.NORMAL.toString());
        assertEquals("FileDeleteStrategy[Force]", FileDeleteStrategy.FORCE.toString());
    }

    @After
    public void tearDown() throws Exception {
        FileUtils.deleteDirectory(getTestDirectory());
    }

}

@@ -839,107 +839,88 @@
 ort 
-org.apache.commons.io.testtools.FileBasedTestCase;%0Aimport org.apache.commons.io.testtools.TestUti
+static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFa
 ls
+e
 ;%0Aim
@@ -916,32 +916,39 @@
 rtFalse;%0Aimport 
+static 
 org.junit.After;
@@ -942,20 +942,32 @@
 .junit.A
-fter
+ssert.assertTrue
 ;%0Aimport
@@ -967,16 +967,23 @@
 %0Aimport 
+static 
 org.juni
@@ -984,20 +984,27 @@
 g.junit.
-Test
+Assert.fail
 ;%0A%0Aimpor
@@ -1129,42 +1129,47 @@
 ort 
-static org.junit.Assert.assertEqua
+org.apache.commons.io.testtools.TestUti
 ls;%0A
@@ -1167,39 +1167,32 @@
 stUtils;%0Aimport 
-static 
 org.junit.Assert
@@ -1186,32 +1186,42 @@
 .junit.A
-ssert.assertFals
+fter;%0Aimport org.junit.Rul
 e;%0Aimpor
@@ -1214,39 +1214,32 @@
 it.Rule;%0Aimport 
-static 
 org.junit.Assert
@@ -1232,33 +1232,20 @@
 g.junit.
-Assert.assertTrue
+Test
 ;%0Aimport
@@ -1237,39 +1237,32 @@
 it.Test;%0Aimport 
-static 
 org.junit.Assert
@@ -1255,27 +1255,37 @@
 g.junit.
-Assert.fail
+rules.TemporaryFolder
 ;%0A%0A/**%0A 
@@ -1393,35 +1393,175 @@
 ase 
-extends FileBasedTestCase %7B
+%7B%0A%0A    @Rule%0A    public TemporaryFolder temporaryFolder = new TemporaryFolder();%0A%0A    private File getTestDirectory() %7B%0A        return temporaryFolder.getRoot();%0A    %7D
 %0A%0A  

Replace custom temporary folder management with JUnit's TemporaryFolder. This will allow Maven to run tests concurrently.