package com.github.quadflask.smartcrop;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;

/**
 * Created by flask on 2015. 10. 27..
 */
public class SmartCropTest {

	static String samplePath = "src/test/resources/sample";
	static String debugPath = "src/test/resources/debug";

	static Map<String, BufferedImage> bufferedImages = new ConcurrentHashMap<>();
	static Map<String, BufferedImage> resultBufferedImages = new ConcurrentHashMap<>();

	@BeforeClass
	public static void setup() throws Exception {
		Arrays.stream(new File(samplePath)
				.listFiles(pathname -> pathname.getName().endsWith(".jpg")))
				.forEach(file -> {
					try {
						bufferedImages.put(file.getName(), ImageIO.read(file));
					} catch (IOException e) {
						e.printStackTrace();
					}
				});
	}

	@AfterClass
	public static void teardown() {
		resultBufferedImages.forEach((name, resultBufferedImage) -> {
			new Thread(() -> {
				try {
					long b = System.currentTimeMillis();
					String newName = name; // name.replace("jpg", "png");
					ImageIO.write(resultBufferedImage, "jpg", new File(debugPath, newName));
					System.out.println("saved... " + newName + " / took " + (System.currentTimeMillis() - b) + "ms");
				} catch (IOException e) {
					e.printStackTrace();
				}
			}).run();
		});
	}

	@Test
	public void test() throws Exception {
		bufferedImages.forEach((name, img) -> {
			long b = System.currentTimeMillis();
			Options options = new Options();
			options.setBufferedBitmapType(BufferedImage.TYPE_INT_RGB);
			CropResult result = new SmartCrop(options).analyze(img);
			System.out.println("done: " + name + " / analyze took " + (System.currentTimeMillis() - b) + "ms");

			resultBufferedImages.put(name, result.getBufferedImage());
		});
	}
}
@@ -67,33 +67,8 @@
 ss;%0A
-import org.junit.Before;%0A
 impo
@@ -89,24 +89,24 @@
 eforeClass;%0A
+
 import org.j
@@ -209,35 +209,8 @@
 le;%0A
-import java.io.FileFilter;%0A
 impo
@@ -250,17 +250,22 @@
 va.util.
-*
+Arrays
 ;%0Aimport
@@ -275,16 +275,38 @@
 va.util.
+Map;%0Aimport java.util.
 concurre
@@ -329,118 +329,8 @@
 hMap
-;%0Aimport java.util.function.BiConsumer;%0Aimport java.util.function.Consumer;%0Aimport java.util.function.Function
 ;%0A%0A/

Remove unused imports in test