com.crawljax.rules.TempDirInTargetFolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crawljax-test-utils Show documentation
Show all versions of crawljax-test-utils Show documentation
This artifact offers Crawljax plugin developers a convenient way to test their plugins by offering several default sites with known/expected output.
package com.crawljax.rules;
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.io.FileUtils.deleteQuietly;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.rules.ExternalResource;
public class TempDirInTargetFolder extends ExternalResource {
private static final String DATE_FORMAT = "yyyy-MM-dd-HH.mm.ss";
private final File target;
private final String prefix;
private final boolean override;
private File tmpDir;
public TempDirInTargetFolder(String prefix, boolean override) {
this.prefix = prefix;
this.override = override;
target = new File("target/test-data");
target.mkdirs();
checkArgument(target.exists());
}
@Override
protected void before() throws Throwable {
if (override) {
tmpDir = new File(target, prefix);
if (tmpDir.exists()) {
deleteQuietly(tmpDir);
}
} else {
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
String suffix = format.format(new Date());
tmpDir = new File(target, prefix + '-' + suffix);
}
tmpDir.mkdirs();
}
public File getTempDir() {
return tmpDir;
}
}