Skip to content

Commit c9447a1

Browse files
committed
Add Javadoc to spec processor and spec orderers
Relates to #1443.
1 parent 81a9307 commit c9447a1

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/AlphabeticalSpecOrderer.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,46 @@
11
package org.spockframework.runtime.extension.builtin.orderer;
22

3+
import org.spockframework.runtime.model.FeatureInfo;
34
import org.spockframework.runtime.model.SpecInfo;
45

56
import java.util.Collection;
67
import java.util.concurrent.atomic.AtomicInteger;
78

9+
/**
10+
* Orderer capable of assigning specification and/or feature method run orders according to spec/feature display names,
11+
* comparing them alphabetically. There is no locale-specific collation, only simple string comparison based on the
12+
* default JVM locale, using by {@link String#compareTo(String)}.
13+
*/
814
public class AlphabeticalSpecOrderer extends SpecOrderer {
915
private final boolean ascending;
1016

17+
/**
18+
* Create an alphabetical spec orderer
19+
*
20+
* @param orderSpecs modify specification run order (yes/no)?
21+
* @param orderFeatures modify feature run order within a specification (yes/no)?
22+
* @param ascending sort in ascending order (yes/no)?
23+
*/
1124
public AlphabeticalSpecOrderer(boolean orderSpecs, boolean orderFeatures, boolean ascending) {
1225
super(orderSpecs, orderFeatures);
1326
this.ascending = ascending;
1427
}
1528

29+
/**
30+
* Create an alphabetical spec orderer with a default ascending sort order
31+
*
32+
* @param orderSpecs modify specification run order (yes/no)?
33+
* @param orderFeatures modify feature run order within a specification (yes/no)?
34+
* @see #AlphabeticalSpecOrderer(boolean, boolean, boolean)
35+
*/
1636
public AlphabeticalSpecOrderer(boolean orderSpecs, boolean orderFeatures) {
1737
this(orderSpecs, orderFeatures, true);
1838
}
1939

40+
/**
41+
* Create an alphabetical spec orderer with default values. This is a shorthand for calling
42+
* {@link #AlphabeticalSpecOrderer(boolean, boolean, boolean)} with parameters {@code true, true, true}.
43+
*/
2044
public AlphabeticalSpecOrderer() {
2145
this(true, true);
2246
}

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/AnnotatationBasedSpecOrderer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66

77
import java.util.Collection;
88

9+
/**
10+
* Spec orderer for usef-defined, manual specification and/or feature method ordering, to be used in connection with
11+
* {@link Order @Order} annotations. See the Spock user manual for more details.
12+
*/
913
public class AnnotatationBasedSpecOrderer extends SpecOrderer {
14+
/**
15+
* Create an annotation-based spec orderer
16+
* @see Order
17+
*/
1018
public AnnotatationBasedSpecOrderer() {
1119
super(true, true);
1220
}

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/DefaultSpecOrderer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
import java.util.Collection;
77

8+
/**
9+
* No-op spec orderer, used as a default if no other orderer is configured
10+
*/
811
public class DefaultSpecOrderer extends SpecOrderer {
12+
/**
13+
* Create a no-op spec orderer
14+
*/
915
public DefaultSpecOrderer() {
1016
super(false, false);
1117
}

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/RandomSpecOrderer.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,42 @@
66
import java.util.Collection;
77
import java.util.Random;
88

9+
/**
10+
* Orderer capable of randomizing specification and/or feature method run order
11+
*/
912
public class RandomSpecOrderer extends SpecOrderer {
1013
private final Random random;
1114

15+
/**
16+
* Create a random spec orderer
17+
*
18+
* @param orderSpecs modify specification run order (yes/no)?
19+
* @param orderFeatures modify feature run order within a specification (yes/no)?
20+
* @param seed random seed to be used in {@link Random#Random(long)}; setting this to a fixed value enables
21+
* you to create test runs with repeatable pseudo-random run ordering, which can be helpful when
22+
* e.g. debugging tests failing due to a particular run order, making them more independent of
23+
* each other in the process
24+
*/
1225
public RandomSpecOrderer(boolean orderSpecs, boolean orderFeatures, long seed) {
1326
super(orderSpecs, orderFeatures);
1427
random = new Random(seed);
1528
}
1629

30+
/**
31+
* Create a random spec orderer with a default random seed of {@code System.currentTimeMillis()}
32+
*
33+
* @param orderSpecs modify specification run order (yes/no)?
34+
* @param orderFeatures modify feature run order within a specification (yes/no)?
35+
* @see #RandomSpecOrderer(boolean, boolean, long)
36+
*/
1737
public RandomSpecOrderer(boolean orderSpecs, boolean orderFeatures) {
1838
this(orderSpecs, orderFeatures, System.currentTimeMillis());
1939
}
2040

41+
/**
42+
* Create a random spec orderer with default values. This is a shorthand for calling
43+
* {@link #RandomSpecOrderer(boolean, boolean, long)} with parameters {@code true, true, System.currentTimeMillis()}.
44+
*/
2145
public RandomSpecOrderer() {
2246
this(true, true);
2347
}

spock-core/src/main/java/org/spockframework/runtime/extension/builtin/orderer/SpecOrderer.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
package org.spockframework.runtime.extension.builtin.orderer;
22

33
import org.spockframework.runtime.SpecProcessor;
4+
import org.spockframework.runtime.model.FeatureInfo;
45
import org.spockframework.runtime.model.SpecInfo;
56

67
import java.util.Collection;
78

9+
/**
10+
* Abstract base class for specification and feature method orderers, i.e. workers modifying the corresponding execution
11+
* order properties of spec-info and feature-info instances.
12+
*
13+
* @see DefaultSpecOrderer
14+
* @see RandomSpecOrderer
15+
* @see AnnotatationBasedSpecOrderer
16+
* @see AlphabeticalSpecOrderer
17+
*/
818
public abstract class SpecOrderer implements SpecProcessor {
919
protected final boolean orderSpecs;
1020
protected final boolean orderFeatures;
1121

22+
/**
23+
* Create a spec-orderer with a user-defined operational scope
24+
*
25+
* @param orderSpecs modify specification run order (yes/no)?
26+
* @param orderFeatures modify feature run order within a specification (yes/no)?
27+
*/
1228
public SpecOrderer(boolean orderSpecs, boolean orderFeatures) {
1329
this.orderSpecs = orderSpecs;
1430
this.orderFeatures = orderFeatures;
1531
}
1632

33+
/**
34+
* Dispatch to {@link #orderSpecs(Collection)} and then to {@link #orderFeatures(Collection)} for each spec-info
35+
*
36+
* @param specs spec-info instances to be processed
37+
*/
1738
@Override
1839
public void process(Collection<SpecInfo> specs) {
1940
if (orderSpecs)
@@ -24,8 +45,43 @@ public void process(Collection<SpecInfo> specs) {
2445
orderFeatures(spec.getAllFeatures());
2546
}
2647

48+
/**
49+
* Assign values to specification run orders. Implementors are expected to modify the corresponding object state
50+
* in place, e.g. like this:
51+
* <pre>
52+
* for (SpecInfo spec : specs)
53+
* spec.setExecutionOrder(random.nextInt());
54+
* </pre>
55+
* Or maybe:
56+
* <pre>
57+
* AtomicInteger i = new AtomicInteger();
58+
* specs.stream()
59+
* .sorted(myComparator)
60+
* .forEach(specInfo -> specInfo.setExecutionOrder(i.getAndIncrement()));
61+
* </pre>
62+
*
63+
* @param specs spec-info instances to be ordered
64+
*/
65+
2766
protected abstract void orderSpecs(Collection<SpecInfo> specs);
2867

68+
/**
69+
* Assign values to feature run orders. Implementors are expected to modify the corresponding object state
70+
* in place, e.g. like this:
71+
* <pre>
72+
* for (FeatureInfo feature : features)
73+
* feature.setExecutionOrder(random.nextInt());
74+
* </pre>
75+
* Or maybe:
76+
* <pre>
77+
* AtomicInteger i = new AtomicInteger();
78+
* features.stream()
79+
* .sorted(myComparator)
80+
* .forEach(featureInfo -> featureInfo.setExecutionOrder(i.getAndIncrement()));
81+
* </pre>
82+
*
83+
* @param features feature-info instances to be ordered
84+
*/
2985
protected abstract void orderFeatures(Collection<FeatureInfo> features);
3086

3187
public boolean isOrderSpecs() {

spock-core/src/main/java/spock/lang/Order.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
* runner {
3131
* orderer new AnnotatationBasedSpecOrderer()
3232
* }</pre>
33+
* <p>
34+
* See the Spock user manual for more details.
3335
*/
3436
@Retention(RetentionPolicy.RUNTIME)
3537
@Target({ ElementType.TYPE, ElementType.METHOD })

0 commit comments

Comments
 (0)