/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio;

import org.junit.Rule;
import org.junit.rules.TestWatcher;
import org.junit.rules.Timeout;
import org.junit.runner.Description;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;

/**
 * Base class used for specifying the maximum time a test should run for.
 */
public abstract class BaseIntegrationTest {

  @Rule
  public Timeout mGlobalTimeout = Timeout.millis(Constants.MAX_TEST_DURATION_MS);

  @Rule
  public TestWatcher mWatcher = new TestWatcher() {
    // When tests fail, save the logs.
    protected void failed(Throwable t, Description description) {
      try {
        Files.copy(Paths.get(Constants.TESTS_LOG),
            Paths.get(Constants.TEST_LOG_DIR, String.format("%s-%s.log",
                description.getClassName(), description.getMethodName())),
            StandardCopyOption.REPLACE_EXISTING);
      } catch (IOException e) {
        if (t != null) {
          t.addSuppressed(e);
        } else {
          throw new RuntimeException(e);
        }
      }
      return;
    }

    // Before each test starts, truncate the log file.
    protected void starting(Description description) {
      try {
        Files.write(Paths.get(Constants.TESTS_LOG), new byte[0],
            StandardOpenOption.TRUNCATE_EXISTING);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  };
}

@@ -654,16 +654,43 @@
 ption;%0A%0A
+import java.io.FileWriter;%0A
 import j
@@ -809,49 +809,8 @@
 ion;
-%0Aimport java.nio.file.StandardOpenOption;
 %0A%0A/*
@@ -1769,29 +1769,22 @@
     
+new 
 File
-s.w
+W
 rite
-(Paths.get
+r
 (Con
@@ -1804,71 +1804,15 @@
 LOG)
-, new byte%5B0%5D,%0A            StandardOpenOption.TRUNCATE_EXISTING
+.close(
 );%0A 

Truncate nicer