Skip to content

Commit ba6fdc9

Browse files
author
Glib Briia
committed
Bump version; Cleanup
1 parent 6e6d256 commit ba6fdc9

File tree

4 files changed

+113
-114
lines changed

4 files changed

+113
-114
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,108 @@
1-
package cucumber.api.groovy;
2-
3-
import cucumber.runtime.CucumberException;
4-
import cucumber.runtime.filter.TagPredicate;
5-
import cucumber.runtime.groovy.GroovyBackend;
6-
import groovy.lang.Closure;
7-
8-
import java.util.ArrayList;
9-
import java.util.List;
10-
11-
public class Hooks {
12-
private static final int DEFAULT_ORDER = 10000;
13-
private static final long DEFAULT_TIMEOUT = 0;
14-
15-
public static void World(Closure body) throws Throwable {
16-
GroovyBackend.getInstance().registerWorld(body);
17-
}
18-
19-
/**
20-
* Registers a before hook, which is executed before specific, or all, scenarios.
21-
*
22-
* Following values are expected as hook parameters.
23-
* - Long timeoutMillis: max amount of milliseconds this is allowed to run for. The default is 0 which means no restriction.
24-
* - Integer order: the order in which this hook should run. Lower numbers are run first. The default is 10000.
25-
* - String(s) tags: one or more tag expression to filter the certain scenarios. The default is empty.
26-
* - Closure body: hook body which is executed before scenario. Not null.
27-
*
28-
* @param args the hook parameters
29-
*/
30-
public static void Before(Object... args) {
31-
addHook(args, true, false);
32-
}
33-
34-
/**
35-
* Registers an after hook, which is executed after specific, or all, scenarios.
36-
*
37-
* Following values are expected as hook parameters.
38-
* - Long timeoutMillis: max amount of milliseconds this is allowed to run for. The default is 0 which means no restriction.
39-
* - Integer order: the order in which this hook should run. Higher numbers are run first. The default is 10000.
40-
* - String(s) tags: one or more tag expression to filter the certain scenarios. The default is empty.
41-
* - Closure body: hook body which is executed after scenario. Not null.
42-
*
43-
* @param args the hook parameters
44-
*/
45-
public static void After(Object... args) {
46-
addHook(args, false, false);
47-
}
48-
49-
public static void AfterStep(Object... args) {
50-
addHook(args, false, true);
51-
}
52-
53-
public static void BeforeStep(Object... args) {
54-
addHook(args, true, true);
55-
}
56-
57-
private static void addHook(Object[] tagsExpressionsAndBody, boolean before, boolean forStep) {
58-
long timeoutMillis = DEFAULT_TIMEOUT;
59-
int order = DEFAULT_ORDER;
60-
boolean timeoutSet = false;
61-
boolean orderSet = false;
62-
Closure body = null;
63-
List<String> tagExpressions = new ArrayList<String>();
64-
65-
for (Object o : tagsExpressionsAndBody) {
66-
if (o instanceof String) {
67-
tagExpressions.add((String) o);
68-
} else if (o instanceof Long) {
69-
if (timeoutSet) {
70-
throw new CucumberException("Two timeout (Long) arguments found; " +
71-
Long.toString(timeoutMillis) + ", and; " +
72-
Long.toString((Long) o));
73-
}
74-
timeoutMillis = (Long) o;
75-
timeoutSet = true;
76-
} else if (o instanceof Integer) {
77-
if (orderSet) {
78-
throw new CucumberException("Two order (Integer) arguments found; " +
79-
Integer.toString(order) + ", and; " +
80-
Integer.toString((Integer) o));
81-
}
82-
order = (Integer) o;
83-
orderSet = true;
84-
} else if (o instanceof Closure) {
85-
body = (Closure) o;
86-
} else {
87-
throw new CucumberException("An argument of the type " + o.getClass().getName() + " found, " +
88-
(before ? "Before" : "After") + " only allows the argument types " +
89-
"String - Tag, Long - timeout, Integer - order, and Closure");
90-
}
91-
}
92-
93-
TagPredicate tagPredicate = new TagPredicate(tagExpressions);
94-
if (before) {
95-
if(forStep) {
96-
GroovyBackend.getInstance().addBeforeStepHook(tagPredicate, timeoutMillis, order, body);
97-
}else{
98-
GroovyBackend.getInstance().addBeforeHook(tagPredicate, timeoutMillis, order, body);
99-
}
100-
} else {
101-
if(forStep) {
102-
GroovyBackend.getInstance().addAfterStepHook(tagPredicate, timeoutMillis, order, body);
103-
}else{
104-
GroovyBackend.getInstance().addAfterHook(tagPredicate, timeoutMillis, order, body);
105-
}
106-
}
107-
}
108-
}
1+
package cucumber.api.groovy;
2+
3+
import cucumber.runtime.CucumberException;
4+
import cucumber.runtime.filter.TagPredicate;
5+
import cucumber.runtime.groovy.GroovyBackend;
6+
import groovy.lang.Closure;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
public class Hooks {
12+
private static final int DEFAULT_ORDER = 10000;
13+
private static final long DEFAULT_TIMEOUT = 0;
14+
15+
public static void World(Closure body) {
16+
GroovyBackend.getInstance().registerWorld(body);
17+
}
18+
19+
/**
20+
* Registers a before hook, which is executed before specific, or all, scenarios.
21+
*
22+
* Following values are expected as hook parameters.
23+
* - Long timeoutMillis: max amount of milliseconds this is allowed to run for. The default is 0 which means no restriction.
24+
* - Integer order: the order in which this hook should run. Lower numbers are run first. The default is 10000.
25+
* - String(s) tags: one or more tag expression to filter the certain scenarios. The default is empty.
26+
* - Closure body: hook body which is executed before scenario. Not null.
27+
*
28+
* @param args the hook parameters
29+
*/
30+
public static void Before(Object... args) {
31+
addHook(args, true, false);
32+
}
33+
34+
/**
35+
* Registers an after hook, which is executed after specific, or all, scenarios.
36+
*
37+
* Following values are expected as hook parameters.
38+
* - Long timeoutMillis: max amount of milliseconds this is allowed to run for. The default is 0 which means no restriction.
39+
* - Integer order: the order in which this hook should run. Higher numbers are run first. The default is 10000.
40+
* - String(s) tags: one or more tag expression to filter the certain scenarios. The default is empty.
41+
* - Closure body: hook body which is executed after scenario. Not null.
42+
*
43+
* @param args the hook parameters
44+
*/
45+
public static void After(Object... args) {
46+
addHook(args, false, false);
47+
}
48+
49+
public static void AfterStep(Object... args) {
50+
addHook(args, false, true);
51+
}
52+
53+
public static void BeforeStep(Object... args) {
54+
addHook(args, true, true);
55+
}
56+
57+
private static void addHook(Object[] tagsExpressionsAndBody, boolean before, boolean forStep) {
58+
long timeoutMillis = DEFAULT_TIMEOUT;
59+
int order = DEFAULT_ORDER;
60+
boolean timeoutSet = false;
61+
boolean orderSet = false;
62+
Closure body = null;
63+
List<String> tagExpressions = new ArrayList<String>();
64+
65+
for (Object o : tagsExpressionsAndBody) {
66+
if (o instanceof String) {
67+
tagExpressions.add((String) o);
68+
} else if (o instanceof Long) {
69+
if (timeoutSet) {
70+
throw new CucumberException("Two timeout (Long) arguments found; " +
71+
Long.toString(timeoutMillis) + ", and; " +
72+
Long.toString((Long) o));
73+
}
74+
timeoutMillis = (Long) o;
75+
timeoutSet = true;
76+
} else if (o instanceof Integer) {
77+
if (orderSet) {
78+
throw new CucumberException("Two order (Integer) arguments found; " +
79+
Integer.toString(order) + ", and; " +
80+
Integer.toString((Integer) o));
81+
}
82+
order = (Integer) o;
83+
orderSet = true;
84+
} else if (o instanceof Closure) {
85+
body = (Closure) o;
86+
} else {
87+
throw new CucumberException("An argument of the type " + o.getClass().getName() + " found, " +
88+
(before ? "Before" : "After") + " only allows the argument types " +
89+
"String - Tag, Long - timeout, Integer - order, and Closure");
90+
}
91+
}
92+
93+
TagPredicate tagPredicate = new TagPredicate(tagExpressions);
94+
if (before) {
95+
if(forStep) {
96+
GroovyBackend.getInstance().addBeforeStepHook(tagPredicate, timeoutMillis, order, body);
97+
}else{
98+
GroovyBackend.getInstance().addBeforeHook(tagPredicate, timeoutMillis, order, body);
99+
}
100+
} else {
101+
if(forStep) {
102+
GroovyBackend.getInstance().addAfterStepHook(tagPredicate, timeoutMillis, order, body);
103+
}else{
104+
GroovyBackend.getInstance().addAfterHook(tagPredicate, timeoutMillis, order, body);
105+
}
106+
}
107+
}
108+
}

groovy/src/main/java/cucumber/runtime/groovy/GroovyBackend.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import cucumber.runtime.CucumberException;
66
import cucumber.runtime.Glue;
77
import cucumber.runtime.filter.TagPredicate;
8-
import cucumber.runtime.io.MultiLoader;
98
import cucumber.runtime.io.Resource;
109
import cucumber.runtime.io.ResourceLoader;
1110
import cucumber.runtime.io.ResourceLoaderClassFinder;
@@ -33,14 +32,14 @@
3332

3433

3534
public class GroovyBackend implements Backend {
36-
public static ThreadLocal<GroovyBackend> instanceThreadLocal = new ThreadLocal<GroovyBackend>();
37-
private final Set<Class> scripts = new HashSet<Class>();
35+
public static ThreadLocal<GroovyBackend> instanceThreadLocal = new ThreadLocal<>();
36+
private final Set<Class> scripts = new HashSet<>();
3837
private SnippetGenerator snippetGenerator;
3938
private final ResourceLoader resourceLoader;
4039
private final GroovyShell shell;
4140
private final ClassFinder classFinder;
4241
private TypeRegistry typeRegistry;
43-
private Collection<Closure> worldClosures = new LinkedList<Closure>();
42+
private Collection<Closure> worldClosures = new LinkedList<>();
4443
private GroovyWorld world;
4544
private Glue glue;
4645

groovy/src/main/java/cucumber/runtime/groovy/GroovyWorld.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class GroovyWorld extends GroovyObjectSupport {
1515

1616
public GroovyWorld() {
1717
super();
18-
worlds = new LinkedList<GroovyObject>();
18+
worlds = new LinkedList<>();
1919
}
2020

2121
public void registerWorld(Object world) {

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2424
<minimum.maven.version>3.3</minimum.maven.version>
2525
<outputDirectory>${project.build.directory}</outputDirectory>
26-
<cucumber.version>4.5.3</cucumber.version>
26+
<cucumber.version>4.5.4</cucumber.version>
2727
<gherkin.version>5.1.0</gherkin.version>
2828
<groovy.version>2.4.12</groovy.version>
2929
<junit.version>4.12</junit.version>

0 commit comments

Comments
 (0)