parent
a0880372f8
commit
38f4cf3464
@ -0,0 +1,8 @@
|
||||
package space.kklochko.simple_jbdd.tests.loaders;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractNameClassLoader {
|
||||
public abstract Set<Class<?>> load();
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package space.kklochko.simple_jbdd.tests.loaders;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Set;
|
||||
|
||||
public class NameClassLoader extends AbstractNameClassLoader {
|
||||
public Set<Class<?>> load() {
|
||||
try {
|
||||
return ClassPath.from(java.lang.ClassLoader.getSystemClassLoader())
|
||||
.getAllClasses()
|
||||
.stream()
|
||||
// exclude the Test class, which indicate a Test class
|
||||
.filter(aClass -> !aClass.getName().endsWith(".Test"))
|
||||
.filter(aClass -> aClass.getName().endsWith("Test"))
|
||||
// include classes which extends the Test class
|
||||
.filter(aClass -> space.kklochko.simple_jbdd.tests.Test.class.isAssignableFrom(aClass.load()))
|
||||
.filter(aClass -> aClass.getName().startsWith("space"))
|
||||
.map(aClass -> aClass.load())
|
||||
.collect(Collectors.toSet());
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package space.kklochko.simple_jbdd.tests.loaders
|
||||
|
||||
import spock.lang.Narrative
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
import spock.lang.Title
|
||||
|
||||
@Narrative("""The loader must return a test class names or null, so
|
||||
those tests check if responses are right.
|
||||
""")
|
||||
@Title("Integrated tests for NameClassLoader.")
|
||||
class IntegratedNameClassLoader extends Specification {
|
||||
def "The class has been run."() {
|
||||
given: "I have a class loader"
|
||||
@Subject
|
||||
def loader = new NameClassLoader();
|
||||
|
||||
when: "The class names ware loaded"
|
||||
def classNames = loader.load()
|
||||
|
||||
then: "Checking that the test result is expected"
|
||||
3 == classNames.size()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue