package eu.ydp.empiria.player;

import com.google.common.base.Predicate;
import java.util.Set;
import junit.framework.*;
import org.junit.runner.RunWith;
import org.junit.runners.AllTests;
import org.mockito.configuration.MockitoConfiguration;
import org.reflections.Reflections;
import org.reflections.util.*;
import spock.lang.Specification;

@RunWith(AllTests.class)
public class SpockTestSuite {

	private final static Predicate<String> onlyClassEndsWithTest = new Predicate<String>() {
		@Override
		public boolean apply(final String name) {
			return name.endsWith("Test.class");
		}
	};

	public static TestSuite suite() {
		MockitoConfiguration.setenableClassCache(false);
		TestSuite junitSuite = new TestSuite();

		Iterable<Class<? extends Specification>> filteredClasses = getTestClasses();
		for (Class<? extends Specification> clazz : filteredClasses) {
			JUnit4TestAdapter adapter = new JUnit4TestAdapter(clazz);
			junitSuite.addTest(adapter);
		}
		return junitSuite;
	}

	private static Set<Class<? extends Specification>> getTestClasses() {
		Reflections reflections = createSpockTestReflections();
		return reflections.getSubTypesOf(Specification.class);
	}

	private static Reflections createSpockTestReflections() {
		ConfigurationBuilder inputFilterByName = new ConfigurationBuilder().filterInputsBy(new FilterBuilder().add(onlyClassEndsWithTest));
		inputFilterByName.setUrls(ClasspathHelper.forPackage("eu.ydp.empiria"));
		return inputFilterByName.build();
	}
}

@@ -78,20 +78,40 @@
 rt j
-ava.util.Set
+unit.framework.JUnit4TestAdapter
 ;%0Aim
@@ -131,17 +131,25 @@
 amework.
-*
+TestSuite
 ;%0Aimport
@@ -333,9 +333,116 @@
 til.
-*
+ClasspathHelper;%0Aimport org.reflections.util.ConfigurationBuilder;%0Aimport org.reflections.util.FilterBuilder
 ;%0Aim
@@ -473,16 +473,39 @@
 ation;%0A%0A
+import java.util.Set;%0A%0A
 @RunWith
@@ -844,21 +844,21 @@
 stSuite 
-junit
+spock
 Suite = 
@@ -1083,21 +1083,21 @@
 zz);%0A%09%09%09
-junit
+spock
 Suite.ad
@@ -1125,21 +1125,21 @@
 %09return 
-junit
+spock
 Suite;%0A%09

rename variable