package me.gregorias.dfuntest;

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

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;

import me.gregorias.dfuntest.util.FileUtilsImpl;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class LocalEnvironmentTest {
  private static final String PREFIX = "NEBTMP";
  private Path mEnvDir;
  private Path mLocalDir;

  private Environment mLocalEnvironment;

  @Before
  public void setUp() throws IOException {
    mEnvDir = Files.createTempDirectory(null);
    mLocalDir = Files.createTempDirectory(null);

    mLocalEnvironment = new LocalEnvironment(0, mEnvDir, FileUtilsImpl.getFileUtilsImpl());
  }

  @After
  public void tearDown() {
    FileUtils.deleteQuietly(mLocalDir.toFile());
    FileUtils.deleteQuietly(mEnvDir.toFile());
  }

  @Test
  public void shouldCreateFileUsingTouchProcess() throws
      CommandException,
      InterruptedException,
      IOException {
    List<String> commands = new LinkedList<>();
    commands.add("touch");
    commands.add(PREFIX);

    RemoteProcess finishedProcess = mLocalEnvironment.runCommand(commands);
    Path envFile = mEnvDir.resolve(PREFIX);
    assertTrue(finishedProcess.waitFor() == 0);
    assertTrue(Files.exists(envFile));
    Files.deleteIfExists(envFile);
  }

  @Test
  public void shouldCopyDirFromLocalDir() throws IOException {
    Path localFile = Files.createTempDirectory(mLocalDir, PREFIX);
    Path envFile = mLocalDir.resolve(localFile.getFileName());
    mLocalEnvironment.copyFilesFromLocalDisk(localFile, ".");
    assertTrue(Files.exists(envFile));
    Files.deleteIfExists(envFile);
    Files.deleteIfExists(localFile);
  }

  @Test
  public void shouldCopyFileFromLocalDir() throws IOException {
    Path localFile = Files.createTempFile(mLocalDir, PREFIX, "");
    Path envFile = mLocalDir.resolve(localFile.getFileName());
    mLocalEnvironment.copyFilesFromLocalDisk(localFile, ".");
    assertTrue(Files.exists(envFile));
    Files.deleteIfExists(envFile);
    Files.deleteIfExists(localFile);
  }

  @Test
  public void shouldCopyDirToLocalDir() throws IOException {
    Path envFile = Files.createTempDirectory(mEnvDir, PREFIX);
    Path localFile = mLocalDir.resolve(envFile.getFileName());
    mLocalEnvironment.copyFilesToLocalDisk(envFile.toString(), mLocalDir);
    assertTrue(Files.exists(localFile));
    Files.deleteIfExists(envFile);
    Files.deleteIfExists(localFile);
  }

  @Test
  public void shouldCopyFileToLocalDir() throws IOException {
    Path envFile = Files.createTempFile(mEnvDir, PREFIX, "");
    Path localFile = mLocalDir.resolve(envFile.getFileName());
    mLocalEnvironment.copyFilesToLocalDisk(envFile.toString(), mLocalDir);
    assertTrue(Files.exists(localFile));
    Files.deleteIfExists(envFile);
    Files.deleteIfExists(localFile);
  }

  @Test
  public void shouldRemoveFile() throws InterruptedException, IOException {
    Path envFile = Files.createTempFile(mEnvDir, PREFIX, "");
    assertTrue(Files.exists(envFile));
    mLocalEnvironment.removeFile(envFile.toString());
    assertFalse(Files.exists(envFile));
  }

}

@@ -408,50 +408,184 @@
 nit.
-Test;%0A%0Apublic class LocalEnvironmentTest %7B
+Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.TemporaryFolder;%0A%0Apublic class LocalEnvironmentTest %7B%0A  @Rule%0A  public TemporaryFolder mTempFolder = new TemporaryFolder();%0A
 %0A  p
@@ -794,87 +794,89 @@
 r = 
-Files.createTempDirectory(null);%0A    mLocalDir = Files.createTempDirectory(null
+mTempFolder.newFolder().toPath();%0A    mLocalDir = mTempFolder.newFolder().toPath(
 );%0A%0A
@@ -976,145 +976,8 @@
  %7D%0A%0A
-  @After%0A  public void tearDown() %7B%0A    FileUtils.deleteQuietly(mLocalDir.toFile());%0A    FileUtils.deleteQuietly(mEnvDir.toFile());%0A  %7D%0A%0A
   @T

Use TemporaryFolder rule for LocalEnvironmentTest