Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38f4cf3464 | ||
|
|
a0880372f8 | ||
|
|
db0c3da413 | ||
|
|
75e30ddae9 | ||
|
|
9056c8d047 |
@@ -18,6 +18,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.guava:guava:32.1.2-jre'
|
||||
// mandatory dependencies for using Spock
|
||||
implementation platform('org.apache.groovy:groovy-bom:4.0.15')
|
||||
implementation 'org.apache.groovy:groovy'
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<groovy.version>4.0.15</groovy.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@@ -77,6 +79,11 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>32.1.2-jre</version>
|
||||
</dependency>
|
||||
<!-- Mandatory dependencies for using Spock -->
|
||||
<dependency>
|
||||
<groupId>org.spockframework</groupId>
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories;
|
||||
|
||||
import space.kklochko.simple_jbdd.tests.Test;
|
||||
import space.kklochko.simple_jbdd.tests.commands.AbstractTestCommand;
|
||||
import space.kklochko.simple_jbdd.tests.runners.AbstractTestRunner;
|
||||
|
||||
public abstract class AbstractTestRunnerFactory {
|
||||
public abstract AbstractTestRunner create(AbstractTestCommand<Test> command);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories;
|
||||
|
||||
import space.kklochko.simple_jbdd.tests.Test;
|
||||
import space.kklochko.simple_jbdd.tests.commands.AbstractTestCommand;
|
||||
import space.kklochko.simple_jbdd.tests.runners.AbstractTestRunner;
|
||||
import space.kklochko.simple_jbdd.tests.runners.SimpleTestRunner;
|
||||
|
||||
public class SimpleTestRunnerFactory extends AbstractTestRunnerFactory {
|
||||
public AbstractTestRunner create(AbstractTestCommand<Test> command) {
|
||||
return new SimpleTestRunner(command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories;
|
||||
|
||||
import space.kklochko.simple_jbdd.tests.Test;
|
||||
import space.kklochko.simple_jbdd.tests.commands.AbstractTestCommand;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TestCommandQueueFactory {
|
||||
private ArrayList<Test> tests;
|
||||
private TestCommandFactory factory;
|
||||
|
||||
public TestCommandQueueFactory(ArrayList<Test> tests, TestCommandFactory factory) {
|
||||
setTests(tests);
|
||||
setFactory(factory);
|
||||
}
|
||||
|
||||
public ArrayList<AbstractTestCommand<Test>> create() {
|
||||
ArrayList<AbstractTestCommand<Test>> commands = new ArrayList<AbstractTestCommand<Test>>();
|
||||
|
||||
for(Test test : getTests()) {
|
||||
AbstractTestCommand<Test> command = getFactory().create(test);
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
public ArrayList<Test> getTests() {
|
||||
return tests;
|
||||
}
|
||||
|
||||
public void setTests(ArrayList<Test> tests) {
|
||||
this.tests = tests;
|
||||
}
|
||||
|
||||
public TestCommandFactory getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
public void setFactory(TestCommandFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,26 @@
|
||||
package space.kklochko.simple_jbdd.tests.loaders;
|
||||
|
||||
public class SingleClassLoader {
|
||||
String className;
|
||||
|
||||
public SingleClassLoader(String className) {
|
||||
setClassName(className);
|
||||
}
|
||||
|
||||
public Class<?> load() {
|
||||
try {
|
||||
return Class.forName(getClassName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
}
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories
|
||||
|
||||
import space.kklochko.simple_jbdd.test_examples.tests.SimpleGivenWhenThenTest
|
||||
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTest
|
||||
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTestWithoutTitle
|
||||
import space.kklochko.simple_jbdd.tests.Test
|
||||
import spock.lang.Narrative
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
import spock.lang.Title
|
||||
|
||||
@Narrative("""The factory must generate a queue of the test commands, so
|
||||
those tests check if factory generate them right.
|
||||
""")
|
||||
@Title("Integrated tests for TestCommandQueueFactory")
|
||||
class IntegratedTestCommandQueueFactorySpec extends Specification {
|
||||
def "Factory generate the queue and its size is 2."() {
|
||||
given: "I have a list of tests"
|
||||
def tests = [new SimpleThenTest(), new SimpleThenTestWithoutTitle()]
|
||||
|
||||
and: "I have a test factory"
|
||||
def testFactory = new TestCommandFactory()
|
||||
|
||||
and: "I have a factory"
|
||||
@Subject
|
||||
def factory = new TestCommandQueueFactory(tests, testFactory)
|
||||
|
||||
when: "Factory build the queue"
|
||||
def queue = factory.create()
|
||||
|
||||
then: "the size is 2"
|
||||
2 == queue.size()
|
||||
}
|
||||
|
||||
def "Factory generate the queue and the commands and test order is the same."() {
|
||||
given: "I have a list of tests with first methods [check, setup]"
|
||||
def tests = [new SimpleThenTest(), new SimpleGivenWhenThenTest()]
|
||||
|
||||
and: "I have a test factory"
|
||||
def testFactory = new TestCommandFactory()
|
||||
|
||||
and: "I have a factory"
|
||||
@Subject
|
||||
def factory = new TestCommandQueueFactory(tests, testFactory)
|
||||
|
||||
when: "Factory build the queue"
|
||||
def queue = factory.create()
|
||||
|
||||
then: "the order is the same"
|
||||
queue[0].method.getName() == "check"
|
||||
queue[1].method.getName() == "setup"
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories
|
||||
|
||||
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTest
|
||||
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTestWithoutTitle
|
||||
import space.kklochko.simple_jbdd.tests.Test
|
||||
import space.kklochko.simple_jbdd.tests.commands.decorators.BlockDecorator
|
||||
import spock.lang.Narrative
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
import spock.lang.Title
|
||||
|
||||
@Narrative("""The factory must generate a queue of the test commands, so
|
||||
those tests check if factory generate them right.
|
||||
""")
|
||||
@Title("Unit tests for TestCommandQueueFactory")
|
||||
class TestCommandQueueFactorySpec extends Specification {
|
||||
def "Factory generate the queue and its size is 2."() {
|
||||
given: "I have a list of tests"
|
||||
def tests = [Mock(SimpleThenTest), Mock(SimpleThenTestWithoutTitle)]
|
||||
|
||||
and: "I have a test factory"
|
||||
def testFactory = Stub(TestCommandFactory)
|
||||
testFactory.create() >>> [Mock(BlockDecorator<Test>)]*2
|
||||
|
||||
and: "I have the factory"
|
||||
@Subject
|
||||
def factory = new TestCommandQueueFactory(tests, testFactory)
|
||||
|
||||
when: "Factory build the queue"
|
||||
def queue = factory.create()
|
||||
|
||||
then: "the size is 2"
|
||||
2 == queue.size()
|
||||
}
|
||||
}
|
||||
|
||||
+25
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package space.kklochko.simple_jbdd.tests.loaders
|
||||
|
||||
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTest
|
||||
import spock.lang.Narrative
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
import spock.lang.Title
|
||||
|
||||
@Narrative("""The loader must return a class or null, so
|
||||
those tests check if responses are right.
|
||||
""")
|
||||
@Title("Integrated tests for ClassLoader.")
|
||||
class IntegratedSingleClassLoader extends Specification {
|
||||
def "The class has been run."() {
|
||||
given: "I have a class loader"
|
||||
@Subject
|
||||
def loader = new SingleClassLoader(className);
|
||||
|
||||
when: "The class was loaded"
|
||||
def aClass = loader.load()
|
||||
|
||||
then: "Checking that the test result is expected"
|
||||
aClass == expectedClass
|
||||
|
||||
where: "Possible variants of tests"
|
||||
className || expectedClass
|
||||
"fourHundredFour" || null
|
||||
"space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTest" || SimpleThenTest
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user