package com.dhemery.runtimesuite.finders;

import java.io.File;
import java.util.Collection;

import org.junit.Test;

import com.dhemery.runtimesuite.ClassFinder;
import com.dhemery.runtimesuite.finders.ClassesOnClassPath;

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

public class AClassesOnClasspathFinder {
	@Test public void findsAllClassesOnASingleElementClasspath() {
		String classpath = "./examples-for-testing/classpath1";
		ClassFinder finder = new ClassesOnClassPath(classpath);
		Collection<Class<?>> found = finder.find();
		assertThat(found).containsOnly(a.Test_a_1.class,
										a.Test_a_2.class,
										a._1.Test_a1_1.class,
										a._1.Test_a1_2.class,
										a._1._a.Test_a1a_1.class,
										a._1._a.Test_a1a_2.class,
										a._1._b.Test_a1b_1.class,
										a._1._b.Test_a1b_2.class,
										a._2.Test_a2_1.class,
										a._2.Test_a2_2.class);
	}

	@Test public void findsAllClassesOnAMultipleElementClasspath() {
		String classpath = "./examples-for-testing/classpath1"
							+ File.pathSeparator
							+ "./examples-for-testing/classpath2";
		ClassFinder finder = new ClassesOnClassPath(classpath);
		Collection<Class<?>> found = finder.find();
		assertThat(found).containsOnly(a.Test_a_1.class,
										a.Test_a_2.class,
										a._1.Test_a1_1.class,
										a._1.Test_a1_2.class,
										a._1._a.Test_a1a_1.class,
										a._1._a.Test_a1a_2.class,
										a._1._b.Test_a1b_1.class,
										a._1._b.Test_a1b_2.class,
										a._2.Test_a2_1.class,
										a._2.Test_a2_2.class,
										b.Test_b_1.class,
										b.Test_b_2.class,
										b._1.Test_b1_1.class,
										b._1.Test_b1_2.class,
										b._2.Test_b2_1.class,
										b._2.Test_b2_2.class,
										b._2._a.Test_b2a_1.class,
										b._2._a.Test_b2a_2.class,
										b._2._b.Test_b2b_1.class,
										b._2._b.Test_b2b_2.class);
	}
	
	@Test public void ignoresNonClassFiles() {
		// classpath.three contains
		//    - ./c/Test_c_1.class
		//    - ./c/not-a-test.txt
		String classpath = "./examples-for-testing/classpath3";
		ClassFinder finder = new ClassesOnClassPath(classpath);
		Collection<Class<?>> found = finder.find();
		assertThat(found).containsOnly(c.Test_c_1.class);
	}
	
	@Test public void ignoresNonTestClasses() {
		// classpath.four contains
		//    - ./d/Test_d_1.class
		//    - ./d/NotATest_d_2.class
		String classpath = "./examples-for-testing/classpath4";
		ClassFinder finder = new ClassesOnClassPath(classpath);
		Collection<Class<?>> found = finder.find();
		assertThat(found).containsOnly(d.Test_d_1.class);
	}
	
	@Test public void ignoresNonDirectoryClasspathElements() {
		ClassFinder finder = new ClassesOnClassPath("no.such.directory");
		Collection<Class<?>> found = finder.find();
		assertThat(found).isEmpty();
	}
}

@@ -396,32 +396,23 @@
 h = 
-%22./examples-for-testing/
+makeClasspath(%22
 clas
@@ -416,18 +416,20 @@
 lasspath
-1%22
+.a%22)
 ;%0A%09%09Clas
@@ -882,16 +882,135 @@
 s);%0A%09%7D%0A%0A
+%09private String makeClasspath(String path) %7B%0A%09%09return String.format(%22./examples-for-testing/bin/finder/%25s%22, path);%0A%09%7D%0A%0A
 %09@Test p
@@ -1092,32 +1092,23 @@
 h = 
-%22./examples-for-testing/
+makeClasspath(%22
 clas
@@ -1116,10 +1116,12 @@
 path
-1%22
+.a%22)
 %0A%09%09%09
@@ -1158,32 +1158,23 @@
 %09%09+ 
-%22./examples-for-testing/
+makeClasspath(%22
 clas
@@ -1182,10 +1182,12 @@
 path
-2%22
+.b%22)
 ;%0A%09%09
@@ -2036,13 +2036,9 @@
 ath.
-three
+c
  con
@@ -2126,32 +2126,23 @@
 h = 
-%22./examples-for-testing/
+makeClasspath(%22
 clas
@@ -2150,10 +2150,12 @@
 path
-3%22
+.c%22)
 ;%0A%09%09
@@ -2474,32 +2474,23 @@
 h = 
-%22./examples-for-testing/
+makeClasspath(%22
 clas
@@ -2498,10 +2498,12 @@
 path
-4%22
+.d%22)
 ;%0A%09%09

Update ClassesOnClasspath finder test to use new examples-for-testing outputs