Add the queue factory for test commands.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

main 0.5.4
KKlochko 2 years ago
parent 9056c8d047
commit 75e30ddae9

@ -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,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"
}
}

@ -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()
}
}
Loading…
Cancel
Save