Compare commits

...
2 Commits
Author SHA1 Message Date
KKlochko bcdd11c5a3 Add the ClassLoader.
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-10-01 20:16:05 +03:00
KKlochko 19f638e091 Fix typos and improve description in the tests.
continuous-integration/drone/tag Build is passing
2023-10-01 20:09:07 +03:00
5 changed files with 75 additions and 6 deletions
@@ -0,0 +1,26 @@
package space.kklochko.simple_jbdd.tests.loaders;
import java.util.ArrayList;
import java.util.Set;
public class ClassLoader<T> {
AbstractNameClassLoader nameLoader;
public ClassLoader(AbstractNameClassLoader nameLoader) {
this.nameLoader = nameLoader;
}
public ArrayList<T> load() {
Set<Class<?>> names = nameLoader.load();
ArrayList<T> classes = new ArrayList<>();
for(Class<?> name : names) {
SingleClassLoader loader = new SingleClassLoader(name.getName());
classes.add((T) loader.load());
}
return classes;
}
}
@@ -12,7 +12,7 @@ import spock.lang.Title
@Narrative("""The factory must generate a test command, so @Narrative("""The factory must generate a test command, so
those tests check if factory generate them right. those tests check if factory generate them right.
""") """)
@Title("Unit test for TestCommandFactory") @Title("Unit tests for TestCommandFactory")
class TestCommandFactorySpec extends Specification { class TestCommandFactorySpec extends Specification {
def "If the map of methods have one test block."() { def "If the map of methods have one test block."() {
given: "I have a TestCommandFactory object" given: "I have a TestCommandFactory object"
@@ -0,0 +1,43 @@
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 classes or null, so
those tests check if responses are right.
""")
@Title("Integrated tests for ClassLoader.")
class IntegratedClassLoader extends Specification {
def "The classes have been loaded."() {
given: "I have a name class loader"
def nameLoader = new NameClassLoader()
and: "I have a loader for classes"
@Subject
def loader = new ClassLoader(nameLoader)
when: "The classes were loaded"
def classes = loader.load()
then: "Checking that the test result is expected"
3 == classes.size()
}
def "The classes must be represent the Test interface."() {
given: "I have a name class loader"
def nameLoader = new NameClassLoader()
and: "I have a loader for classes"
@Subject
def loader = new ClassLoader(nameLoader)
when: "The classes were loaded"
def classes = loader.load()
then: "Checking that the test result is expected"
classes.every({ space.kklochko.simple_jbdd.tests.Test.class.isAssignableFrom(it) })
}
}
@@ -10,12 +10,12 @@ those tests check if responses are right.
""") """)
@Title("Integrated tests for NameClassLoader.") @Title("Integrated tests for NameClassLoader.")
class IntegratedNameClassLoader extends Specification { class IntegratedNameClassLoader extends Specification {
def "The class has been run."() { def "The class names have been loaded."() {
given: "I have a class loader" given: "I have a class loader"
@Subject @Subject
def loader = new NameClassLoader(); def loader = new NameClassLoader()
when: "The class names ware loaded" when: "The class names were loaded"
def classNames = loader.load() def classNames = loader.load()
then: "Checking that the test result is expected" then: "Checking that the test result is expected"
@@ -11,10 +11,10 @@ those tests check if responses are right.
""") """)
@Title("Integrated tests for ClassLoader.") @Title("Integrated tests for ClassLoader.")
class IntegratedSingleClassLoader extends Specification { class IntegratedSingleClassLoader extends Specification {
def "The class has been run."() { def "The class has been loaded."() {
given: "I have a class loader" given: "I have a class loader"
@Subject @Subject
def loader = new SingleClassLoader(className); def loader = new SingleClassLoader(className)
when: "The class was loaded" when: "The class was loaded"
def aClass = loader.load() def aClass = loader.load()