<commit_before>package com.tlorrain.android.rezenerator.core;

import static org.fest.assertions.Assertions.assertThat;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.ImmutableMap;
import com.tlorrain.android.rezenerator.core.utils.PNGFileUtils;

public class RezeneratorRunnerTest {

	private File outDir = new File("target/RezeneratorRunnerTest-tmp");
	private RezeneratorRunner rezeneratorRunner = new RezeneratorRunner();
	private Configuration config = config();

	@Before
	public void setup() throws Exception {
		FileUtils.deleteDirectory(outDir);
	}

	@Test
	public void basic() throws Exception {
		rezeneratorRunner.run(config);
		checkOutDir(outDir);

	}

	@Test
	public void existingFiles() throws Exception {
		rezeneratorRunner.run(config);
		checkOutDir(outDir);
		File mdpi = getOutFile(outDir, "mdpi");
		File hdpi = getOutFile(outDir, "hdpi");
		File xhdpi = getOutFile(outDir, "xhdpi");
		File xxhdpi = getOutFile(outDir, "xxhdpi");

		long lastModifiedMdpi = mdpi.lastModified();
		long lastModifiedHdpi = hdpi.lastModified();
		long lastModifiedXhdpi = xhdpi.lastModified();
		long lastModifiedXxhdpi = xxhdpi.lastModified();
		Files.copy(xhdpi.toPath(), xxhdpi.toPath(), StandardCopyOption.REPLACE_EXISTING);

		Thread.sleep(1000); // time resolution on some files systems is 1s, so
							// lets wait that to be sure

		rezeneratorRunner.run(config);

		assertThat(mdpi.lastModified()).isEqualTo(lastModifiedMdpi);
		assertThat(hdpi.lastModified()).isEqualTo(lastModifiedHdpi);
		assertThat(xhdpi.lastModified()).isEqualTo(lastModifiedXhdpi);
		assertThat(xxhdpi.lastModified()).isGreaterThan(lastModifiedXxhdpi);

		checkOutDir(outDir);
	}

	@Test
	public void forceUpdate() throws Exception {
		rezeneratorRunner.run(config);
		checkOutDir(outDir);
		File mdpi = getOutFile(outDir, "mdpi");
		File hdpi = getOutFile(outDir, "hdpi");
		File xhdpi = getOutFile(outDir, "xhdpi");
		File xxhdpi = getOutFile(outDir, "xxhdpi");

		long lastModifiedMdpi = mdpi.lastModified();
		long lastModifiedHdpi = hdpi.lastModified();
		long lastModifiedXhdpi = xhdpi.lastModified();
		long lastModifiedXxhdpi = xxhdpi.lastModified();

		Thread.sleep(1000); // time resolution on some files systems is 1s, so
							// lets wait that to be sure

		rezeneratorRunner.run(config().setForceUpdate(true));

		assertThat(mdpi.lastModified()).isGreaterThan(lastModifiedMdpi);
		assertThat(hdpi.lastModified()).isGreaterThan(lastModifiedHdpi);
		assertThat(xhdpi.lastModified()).isGreaterThan(lastModifiedXhdpi);
		assertThat(xxhdpi.lastModified()).isGreaterThan(lastModifiedXxhdpi);

		checkOutDir(outDir);
	}

	private Configuration config() {
		return new Configuration().setInDir(new File("src/test/resources")).setBaseOutDir(outDir).addScannedPackage("com.tlorrain.android");
	}

	private void checkOutDir(File outDir) throws Exception {
		Map<String, Integer> dims = ImmutableMap.of("mdpi", 48, "hdpi", 72, "xhdpi", 96, "xxhdpi", 144);
		for (String subDir : dims.keySet()) {
			File outFile = getOutFile(outDir, subDir);
			assertThat(PNGFileUtils.getDimensions(outFile)).isEqualTo(new Dimensions(dims.get(subDir)));
		}

	}

	private File getOutFile(File outDir, String subDir) {
		return new File(outDir, "drawable-" + subDir + "/rezenerator.png");
	}

}
<commit_msg>remove java.nio usage in tests, fix #8<commit_after>package com.tlorrain.android.rezenerator.core;

import static org.fest.assertions.Assertions.assertThat;

import java.io.File;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.ImmutableMap;
import com.tlorrain.android.rezenerator.core.utils.PNGFileUtils;

public class RezeneratorRunnerTest {

	private File outDir = new File("target/RezeneratorRunnerTest-tmp");
	private RezeneratorRunner rezeneratorRunner = new RezeneratorRunner();
	private Configuration config = config();

	@Before
	public void setup() throws Exception {
		FileUtils.deleteDirectory(outDir);
	}

	@Test
	public void basic() throws Exception {
		rezeneratorRunner.run(config);
		checkOutDir(outDir);

	}

	@Test
	public void existingFiles() throws Exception {
		rezeneratorRunner.run(config);
		checkOutDir(outDir);
		File mdpi = getOutFile(outDir, "mdpi");
		File hdpi = getOutFile(outDir, "hdpi");
		File xhdpi = getOutFile(outDir, "xhdpi");
		File xxhdpi = getOutFile(outDir, "xxhdpi");

		long lastModifiedMdpi = mdpi.lastModified();
		long lastModifiedHdpi = hdpi.lastModified();
		long lastModifiedXhdpi = xhdpi.lastModified();
		long lastModifiedXxhdpi = xxhdpi.lastModified();
		FileUtils.copyFile(xhdpi, xxhdpi);

		Thread.sleep(1000); // time resolution on some files systems is 1s, so
							// lets wait that to be sure

		rezeneratorRunner.run(config);

		assertThat(mdpi.lastModified()).isEqualTo(lastModifiedMdpi);
		assertThat(hdpi.lastModified()).isEqualTo(lastModifiedHdpi);
		assertThat(xhdpi.lastModified()).isEqualTo(lastModifiedXhdpi);
		assertThat(xxhdpi.lastModified()).isGreaterThan(lastModifiedXxhdpi);

		checkOutDir(outDir);
	}

	@Test
	public void forceUpdate() throws Exception {
		rezeneratorRunner.run(config);
		checkOutDir(outDir);
		File mdpi = getOutFile(outDir, "mdpi");
		File hdpi = getOutFile(outDir, "hdpi");
		File xhdpi = getOutFile(outDir, "xhdpi");
		File xxhdpi = getOutFile(outDir, "xxhdpi");

		long lastModifiedMdpi = mdpi.lastModified();
		long lastModifiedHdpi = hdpi.lastModified();
		long lastModifiedXhdpi = xhdpi.lastModified();
		long lastModifiedXxhdpi = xxhdpi.lastModified();

		Thread.sleep(1000); // time resolution on some files systems is 1s, so
							// lets wait that to be sure

		rezeneratorRunner.run(config().setForceUpdate(true));

		assertThat(mdpi.lastModified()).isGreaterThan(lastModifiedMdpi);
		assertThat(hdpi.lastModified()).isGreaterThan(lastModifiedHdpi);
		assertThat(xhdpi.lastModified()).isGreaterThan(lastModifiedXhdpi);
		assertThat(xxhdpi.lastModified()).isGreaterThan(lastModifiedXxhdpi);

		checkOutDir(outDir);
	}

	private Configuration config() {
		return new Configuration().setInDir(new File("src/test/resources")).setBaseOutDir(outDir).addScannedPackage("com.tlorrain.android");
	}

	private void checkOutDir(File outDir) throws Exception {
		Map<String, Integer> dims = ImmutableMap.of("mdpi", 48, "hdpi", 72, "xhdpi", 96, "xxhdpi", 144);
		for (String subDir : dims.keySet()) {
			File outFile = getOutFile(outDir, subDir);
			assertThat(PNGFileUtils.getDimensions(outFile)).isEqualTo(new Dimensions(dims.get(subDir)));
		}

	}

	private File getOutFile(File outDir, String subDir) {
		return new File(outDir, "drawable-" + subDir + "/rezenerator.png");
	}

}

{'fraction_non_alphanumeric': 0.12348385211164693, 'fraction_numerical': 0.005699254712845244, 'mean_word_length': 5.657587548638133, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3878053', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2290, 'n_words': 441}