Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e803452389 | ||
|
|
08c85459a7 | ||
|
|
9edbca09cf |
@@ -0,0 +1,13 @@
|
||||
package space.kklochko.simple_jbdd.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Title {
|
||||
String value() default "Title";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package space.kklochko.simple_jbdd.tests;
|
||||
|
||||
public abstract class Test {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories;
|
||||
|
||||
import space.kklochko.simple_jbdd.annotations.Given;
|
||||
import space.kklochko.simple_jbdd.annotations.Then;
|
||||
import space.kklochko.simple_jbdd.annotations.When;
|
||||
import space.kklochko.simple_jbdd.tests.Test;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class TestCommandFactory {
|
||||
public <T extends Test> void create(T input) {
|
||||
Class<?> aClass = input.getClass();
|
||||
Map<String, Method> test_methods = this.getTestMethods(aClass);
|
||||
}
|
||||
|
||||
protected <T extends Test> Map<String, Method> getTestMethods(Class<?> aClass) {
|
||||
Map<String, Method> test_methods = new TreeMap<String, Method>();
|
||||
|
||||
for(Method method : aClass.getDeclaredMethods()) {
|
||||
Annotation[] annotations = method.getAnnotations();
|
||||
|
||||
if (annotations.length == 0)
|
||||
continue;
|
||||
|
||||
if(method.isAnnotationPresent(Given.class))
|
||||
test_methods.put("Given", method);
|
||||
|
||||
if(method.isAnnotationPresent(When.class))
|
||||
test_methods.put("When", method);
|
||||
|
||||
if(method.isAnnotationPresent(Then.class))
|
||||
test_methods.put("Then", method);
|
||||
}
|
||||
|
||||
return test_methods;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package space.kklochko.simple_jbdd.tests.factories
|
||||
|
||||
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTest
|
||||
import space.kklochko.simple_jbdd.tests.factories.TestCommandFactory;
|
||||
import spock.lang.Specification
|
||||
|
||||
class TestCommandFactorySpec extends Specification {
|
||||
def "If the map of methods have one test block."() {
|
||||
given: "I have a TestCommandFactory object"
|
||||
def factory = new TestCommandFactory();
|
||||
|
||||
and: "I also have a SimpleThenTest object"
|
||||
def simpleThenTest = new SimpleThenTest()
|
||||
|
||||
when: "If a test have only one block"
|
||||
def map = factory.getTestMethods(simpleThenTest.getClass())
|
||||
|
||||
then: "the map size is 1 method"
|
||||
1 == map.size()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user