Skip to content

Commit

Permalink
Tighten up naming and parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Jun 8, 2019
1 parent 6c19a59 commit 3d6c495
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 121 deletions.
17 changes: 7 additions & 10 deletions core/src/main/java/cucumber/runtime/Runtime.java
Expand Up @@ -18,7 +18,7 @@
import cucumber.runtime.io.ResourceLoaderClassFinder; import cucumber.runtime.io.ResourceLoaderClassFinder;
import cucumber.runtime.model.CucumberFeature; import cucumber.runtime.model.CucumberFeature;
import cucumber.runtime.model.FeatureLoader; import cucumber.runtime.model.FeatureLoader;
import cucumber.runtime.order.OrderType; import cucumber.runtime.order.PickleOrder;
import gherkin.events.PickleEvent; import gherkin.events.PickleEvent;
import io.cucumber.core.logging.Logger; import io.cucumber.core.logging.Logger;
import io.cucumber.core.logging.LoggerFactory; import io.cucumber.core.logging.LoggerFactory;
Expand All @@ -45,15 +45,13 @@ public class Runtime {


private final ExitStatus exitStatus; private final ExitStatus exitStatus;


private final RuntimeOptions runtimeOptions;

private final RunnerSupplier runnerSupplier; private final RunnerSupplier runnerSupplier;
private final Filters filters; private final Filters filters;
private final EventBus bus; private final EventBus bus;
private final FeatureSupplier featureSupplier; private final FeatureSupplier featureSupplier;
private final Plugins plugins; private final Plugins plugins;
private final ExecutorService executor; private final ExecutorService executor;
private final OrderType orderType; private final PickleOrder pickleOrder;


public Runtime(final Plugins plugins, public Runtime(final Plugins plugins,
final RuntimeOptions runtimeOptions, final RuntimeOptions runtimeOptions,
Expand All @@ -62,17 +60,16 @@ public Runtime(final Plugins plugins,
final RunnerSupplier runnerSupplier, final RunnerSupplier runnerSupplier,
final FeatureSupplier featureSupplier, final FeatureSupplier featureSupplier,
final ExecutorService executor, final ExecutorService executor,
final OrderType orderType) { final PickleOrder pickleOrder) {


this.plugins = plugins; this.plugins = plugins;
this.runtimeOptions = runtimeOptions;
this.filters = filters; this.filters = filters;
this.bus = bus; this.bus = bus;
this.runnerSupplier = runnerSupplier; this.runnerSupplier = runnerSupplier;
this.featureSupplier = featureSupplier; this.featureSupplier = featureSupplier;
this.executor = executor; this.executor = executor;
this.exitStatus = new ExitStatus(runtimeOptions); this.exitStatus = new ExitStatus(runtimeOptions);
this.orderType = orderType; this.pickleOrder = pickleOrder;
exitStatus.setEventPublisher(bus); exitStatus.setEventPublisher(bus);
} }


Expand All @@ -95,7 +92,7 @@ public void run() {
} }
} }


final List<PickleEvent> orderedEvents = orderType.orderPickleEvents(filteredEvents); final List<PickleEvent> orderedEvents = pickleOrder.orderPickleEvents(filteredEvents);
final List<PickleEvent> limitedEvents = filters.limitPickleEvents(orderedEvents); final List<PickleEvent> limitedEvents = filters.limitPickleEvents(orderedEvents);


final List<Future<?>> executingPickles = new ArrayList<>(); final List<Future<?>> executingPickles = new ArrayList<>();
Expand Down Expand Up @@ -241,8 +238,8 @@ public Runtime build() {
: new FeaturePathFeatureSupplier(featureLoader, this.runtimeOptions); : new FeaturePathFeatureSupplier(featureLoader, this.runtimeOptions);


final Filters filters = new Filters(this.runtimeOptions); final Filters filters = new Filters(this.runtimeOptions);
final OrderType orderType = runtimeOptions.getOrderType(); final PickleOrder pickleOrder = runtimeOptions.getPickleOrder();
return new Runtime(plugins, this.runtimeOptions, eventBus, filters, runnerSupplier, featureSupplier, executor, orderType); return new Runtime(plugins, this.runtimeOptions, eventBus, filters, runnerSupplier, featureSupplier, executor, pickleOrder);
} }
} }


Expand Down
22 changes: 18 additions & 4 deletions core/src/main/java/cucumber/runtime/RuntimeOptions.java
Expand Up @@ -4,6 +4,7 @@
import cucumber.runtime.formatter.PluginFactory; import cucumber.runtime.formatter.PluginFactory;
import cucumber.runtime.io.MultiLoader; import cucumber.runtime.io.MultiLoader;
import cucumber.runtime.io.ResourceLoader; import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.order.PickleOrder;
import cucumber.runtime.order.OrderType; import cucumber.runtime.order.OrderType;
import io.cucumber.core.model.FeaturePath; import io.cucumber.core.model.FeaturePath;
import io.cucumber.core.model.FeatureWithLines; import io.cucumber.core.model.FeatureWithLines;
Expand Down Expand Up @@ -70,13 +71,22 @@ public String map(String keyword) {
private boolean wip = false; private boolean wip = false;
private SnippetType snippetType = SnippetType.UNDERSCORE; private SnippetType snippetType = SnippetType.UNDERSCORE;
private int threads = 1; private int threads = 1;
private OrderType orderType = OrderType.NONE; private PickleOrder pickleOrder = OrderType.NONE;
private int count = 0; private int count = 0;


private final List<String> pluginFormatterNames = new ArrayList<String>(); private final List<String> pluginFormatterNames = new ArrayList<String>();
private final List<String> pluginStepDefinitionReporterNames = new ArrayList<String>(); private final List<String> pluginStepDefinitionReporterNames = new ArrayList<String>();
private final List<String> pluginSummaryPrinterNames = new ArrayList<String>(); private final List<String> pluginSummaryPrinterNames = new ArrayList<String>();


private final Map<String, PickleOrder> orderOptions = createOrderOptions();

private static Map<String, PickleOrder> createOrderOptions() {
Map<String, PickleOrder> orderOptions = new HashMap<>();
orderOptions.put("random", OrderType.RANDOM);
orderOptions.put("reverse", OrderType.REVERSE);
return orderOptions;
}



/** /**
* Create a new instance from a string of options, for example: * Create a new instance from a string of options, for example:
Expand Down Expand Up @@ -184,7 +194,11 @@ private void parse(List<String> args) {
} else if (arg.equals("--wip") || arg.equals("-w")) { } else if (arg.equals("--wip") || arg.equals("-w")) {
wip = true; wip = true;
} else if (arg.equals("--order")) { } else if (arg.equals("--order")) {
orderType = OrderType.getOrderType(args.remove(0)); String orderOption = args.remove(0);
if(!orderOptions.containsKey(orderOption)){
throw new CucumberException("Unknown order: " + orderOption);
}
pickleOrder = orderOptions.get(orderOption);
} else if (arg.equals("--count")) { } else if (arg.equals("--count")) {
count = Integer.parseInt(args.remove(0)); count = Integer.parseInt(args.remove(0));
if (this.count < 1) { if (this.count < 1) {
Expand Down Expand Up @@ -392,8 +406,8 @@ public int getThreads() {
return threads; return threads;
} }


public OrderType getOrderType() { public PickleOrder getPickleOrder() {
return orderType; return pickleOrder;
} }


class ParsedPluginData { class ParsedPluginData {
Expand Down
10 changes: 0 additions & 10 deletions core/src/main/java/cucumber/runtime/order/OrderPickleEvents.java

This file was deleted.

70 changes: 30 additions & 40 deletions core/src/main/java/cucumber/runtime/order/OrderType.java
@@ -1,41 +1,31 @@
package cucumber.runtime.order; package cucumber.runtime.order;


import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;


import cucumber.runtime.CucumberException; import gherkin.events.PickleEvent;
import gherkin.events.PickleEvent;

public enum OrderType implements PickleOrder {
public enum OrderType implements OrderPickleEvents {

NONE {
NONE { @Override
@Override public List<PickleEvent> orderPickleEvents(List<PickleEvent> pickleEvents) {
public List<PickleEvent> orderPickleEvents(List<PickleEvent> pickleEvents) { return pickleEvents;
return pickleEvents; }
} },
}, REVERSE {
REVERSE { @Override
@Override public List<PickleEvent> orderPickleEvents(List<PickleEvent> pickleEvents) {
public List<PickleEvent> orderPickleEvents(List<PickleEvent> pickleEvents) { Collections.reverse(pickleEvents);
Collections.reverse(pickleEvents); return pickleEvents;
return pickleEvents; }
} },
}, RANDOM {
RANDOM { @Override
@Override public List<PickleEvent> orderPickleEvents(List<PickleEvent> pickleEvents) {
public List<PickleEvent> orderPickleEvents(List<PickleEvent> pickleEvents) { Collections.shuffle(pickleEvents);
Collections.shuffle(pickleEvents); return pickleEvents;
return pickleEvents; }
} }
};


public static OrderType getOrderType(String name) {
for (OrderType orderType : OrderType.values()) {
if (name.equalsIgnoreCase(orderType.name())) {
return orderType;
}
}
throw new CucumberException(String.format("Unrecognized OrderType %s", name));
}
} }
10 changes: 10 additions & 0 deletions core/src/main/java/cucumber/runtime/order/PickleOrder.java
@@ -0,0 +1,10 @@
package cucumber.runtime.order;

import java.util.List;

import gherkin.events.PickleEvent;

public interface PickleOrder {

List<PickleEvent> orderPickleEvents(List<PickleEvent> pickleEvents);
}
3 changes: 1 addition & 2 deletions core/src/main/resources/cucumber/api/cli/USAGE.txt
Expand Up @@ -47,8 +47,7 @@ Options:




--order Run the scenarios in a different order. --order Run the scenarios in a different order.
The various options are 'reverse' and The options are 'reverse' and 'random'.
'random'.


--count Number of scenarios to be executed. If not --count Number of scenarios to be executed. If not
specified all scenarios are run. specified all scenarios are run.
Expand Down
15 changes: 5 additions & 10 deletions core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java
Expand Up @@ -14,6 +14,7 @@
import cucumber.runtime.io.ResourceLoader; import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.order.OrderType; import cucumber.runtime.order.OrderType;


import cucumber.runtime.order.PickleOrder;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hamcrest.TypeSafeDiagnosingMatcher;
Expand Down Expand Up @@ -451,31 +452,25 @@ public void set_snippet_type() {
@Test @Test
public void ordertype_default_none() { public void ordertype_default_none() {
RuntimeOptions options = new RuntimeOptions(Collections.<String>emptyList()); RuntimeOptions options = new RuntimeOptions(Collections.<String>emptyList());
assertThat(options.getOrderType(), is(OrderType.NONE)); assertThat(options.getPickleOrder(), is((PickleOrder) OrderType.NONE));
}

@Test
public void ensure_ordertype_none_is_used() {
RuntimeOptions options = new RuntimeOptions(asList("--order", "none"));
assertThat(options.getOrderType(), is(OrderType.NONE));
} }


@Test @Test
public void ensure_ordertype_reverse_is_used() { public void ensure_ordertype_reverse_is_used() {
RuntimeOptions options = new RuntimeOptions(asList("--order", "reverse")); RuntimeOptions options = new RuntimeOptions(asList("--order", "reverse"));
assertThat(options.getOrderType(), is(OrderType.REVERSE)); assertThat(options.getPickleOrder(), is((PickleOrder) OrderType.REVERSE));
} }


@Test @Test
public void ensure_ordertype_random_is_used() { public void ensure_ordertype_random_is_used() {
RuntimeOptions options = new RuntimeOptions(asList("--order", "random")); RuntimeOptions options = new RuntimeOptions(asList("--order", "random"));
assertThat(options.getOrderType(), is(OrderType.RANDOM)); assertThat(options.getPickleOrder(), is((PickleOrder) OrderType.RANDOM));
} }


@Test @Test
public void ensure_invalid_ordertype_is_not_allowed() { public void ensure_invalid_ordertype_is_not_allowed() {
expectedException.expect(CucumberException.class); expectedException.expect(CucumberException.class);
expectedException.expectMessage("Unrecognized OrderType invalid"); expectedException.expectMessage("Unknown order: invalid");
new RuntimeOptions(asList("--order", "invalid")); new RuntimeOptions(asList("--order", "invalid"));
} }


Expand Down
45 changes: 0 additions & 45 deletions core/src/test/java/cucumber/runtime/order/OrderTypeTest.java

This file was deleted.

0 comments on commit 3d6c495

Please sign in to comment.