All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.crawljax.rules.TempDirInTargetFolder Maven / Gradle / Ivy

Go to download

This artifact offers Crawljax plugin developers a convenient way to test their plugins by offering several default sites with known/expected output.

There is a newer version: 3.6
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy