diff --git a/src/main/java/space/kklochko/simple_jbdd/tests/factories/TestCommandQueueFactory.java b/src/main/java/space/kklochko/simple_jbdd/tests/factories/TestCommandQueueFactory.java new file mode 100644 index 0000000..d3ab38b --- /dev/null +++ b/src/main/java/space/kklochko/simple_jbdd/tests/factories/TestCommandQueueFactory.java @@ -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 tests; + private TestCommandFactory factory; + + public TestCommandQueueFactory(ArrayList tests, TestCommandFactory factory) { + setTests(tests); + setFactory(factory); + } + + public ArrayList> create() { + ArrayList> commands = new ArrayList>(); + + for(Test test : getTests()) { + AbstractTestCommand command = getFactory().create(test); + commands.add(command); + } + + return commands; + } + + public ArrayList getTests() { + return tests; + } + + public void setTests(ArrayList tests) { + this.tests = tests; + } + + public TestCommandFactory getFactory() { + return factory; + } + + public void setFactory(TestCommandFactory factory) { + this.factory = factory; + } +} + diff --git a/src/test/groovy/space/kklochko/simple_jbdd/tests/factories/IntegratedTestCommandQueueFactorySpec.groovy b/src/test/groovy/space/kklochko/simple_jbdd/tests/factories/IntegratedTestCommandQueueFactorySpec.groovy new file mode 100644 index 0000000..30a018a --- /dev/null +++ b/src/test/groovy/space/kklochko/simple_jbdd/tests/factories/IntegratedTestCommandQueueFactorySpec.groovy @@ -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" + } +} + diff --git a/src/test/groovy/space/kklochko/simple_jbdd/tests/factories/TestCommandQueueFactorySpec.groovy b/src/test/groovy/space/kklochko/simple_jbdd/tests/factories/TestCommandQueueFactorySpec.groovy new file mode 100644 index 0000000..800d67b --- /dev/null +++ b/src/test/groovy/space/kklochko/simple_jbdd/tests/factories/TestCommandQueueFactorySpec.groovy @@ -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)]*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() + } +} +