Skip to content

Commit

Permalink
Merge #1131 'Use gherkin4 review nitpicks'
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 94d507d
Author: Björn Rasmusson <B.Rasmusson@computer.org>
Date:   Fri May 26 11:16:53 2017 +0200

    [TestNG] Revert TestNGCucumberRunner to be public.

    TestNGCucumberRunner needs to be public for the use cases when the
    runner class need to inherit from another base class than
    AbstractTestNGCucumberTests.

commit 458f139
Author: mpkorstanje <rien.korstanje@gmail.com>
Date:   Mon May 22 22:08:18 2017 +0200

    [TestNG] Updated testng for the use of Gherkin v4.0.0. -- nitpicks

commit 95569a2
Author: mpkorstanje <rien.korstanje@gmail.com>
Date:   Mon May 22 22:02:37 2017 +0200

    [TestNG] Updated testng for the use of Gherkin v4.0.0. -- nitpicks

commit 7141152
Author: mpkorstanje <rien.korstanje@gmail.com>
Date:   Wed May 17 23:35:24 2017 +0200

    [Core] Updated core for the use of Gherkin v4.0.0. -- review nitpicks

commit efc05db
Author: mpkorstanje <rien.korstanje@gmail.com>
Date:   Wed May 17 23:34:53 2017 +0200

    [Junit] update to Gherkin5. -- review nit picks

commit 90cb9e5
Author: mpkorstanje <rien.korstanje@gmail.com>
Date:   Sat May 13 22:32:23 2017 +0200

    [Junit] update to Gherkin5. -- review nit picks
  • Loading branch information
brasmusson committed May 26, 2017
1 parent e7a2720 commit ac1b214
Show file tree
Hide file tree
Showing 38 changed files with 74 additions and 98 deletions.
6 changes: 1 addition & 5 deletions core/src/main/java/cucumber/api/DataTable.java
Expand Up @@ -257,12 +257,8 @@ public DataTable transpose() {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (!(o instanceof DataTable)) return false; if (!(o instanceof DataTable)) return false;

DataTable dataTable = (DataTable) o; DataTable dataTable = (DataTable) o;

return raw.equals(dataTable.raw);
if (!raw.equals(dataTable.raw)) return false;

return true;
} }


@Override @Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/TestCase.java
Expand Up @@ -56,7 +56,7 @@ public int getLine() {
} }


private String fileColonLine(PickleLocation location) { private String fileColonLine(PickleLocation location) {
return pickleEvent.uri + ":" + Integer.toString(location.getLine()); return pickleEvent.uri + ":" + location.getLine();
} }


public List<PickleTag> getTags() { public List<PickleTag> getTags() {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/cucumber/api/TestStep.java
Expand Up @@ -94,13 +94,12 @@ private Result.Type mapThrowableToStatus(Throwable t) {


private Result mapStatusToResult(Result.Type status, Throwable error, long duration) { private Result mapStatusToResult(Result.Type status, Throwable error, long duration) {
Long resultDuration = duration; Long resultDuration = duration;
Throwable resultError = error;
if (status == Result.Type.SKIPPED) { if (status == Result.Type.SKIPPED) {
return Result.SKIPPED; return Result.SKIPPED;
} }
if (status == Result.Type.UNDEFINED) { if (status == Result.Type.UNDEFINED) {
return new Result(status, null, null, definitionMatch.getSnippets()); return new Result(status, null, null, definitionMatch.getSnippets());
} }
return new Result(status, resultDuration, resultError); return new Result(status, resultDuration, error);
} }
} }
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/event/EmbedEvent.java
@@ -1,6 +1,6 @@
package cucumber.api.event; package cucumber.api.event;


public class EmbedEvent extends TimeStampedEvent { public final class EmbedEvent extends TimeStampedEvent {
public final byte[] data; public final byte[] data;
public final String mimeType; public final String mimeType;


Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/event/EventHandler.java
Expand Up @@ -2,6 +2,6 @@


public interface EventHandler<T extends Event> { public interface EventHandler<T extends Event> {


public void receive(T event); void receive(T event);


} }
2 changes: 0 additions & 2 deletions core/src/main/java/cucumber/api/event/EventListener.java
@@ -1,7 +1,5 @@
package cucumber.api.event; package cucumber.api.event;


import cucumber.api.event.EventPublisher;

/** /**
* This is the interface you should implement if you want your own custom * This is the interface you should implement if you want your own custom
* formatter. * formatter.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/event/EventPublisher.java
@@ -1,5 +1,5 @@
package cucumber.api.event; package cucumber.api.event;


public interface EventPublisher { public interface EventPublisher {
void registerHandlerFor(Class<? extends Event> eventType, EventHandler<? extends Event> handler); <T extends Event> void registerHandlerFor(Class<T> eventType, EventHandler<T> handler);
} }
Expand Up @@ -3,7 +3,7 @@
import cucumber.api.Result; import cucumber.api.Result;
import cucumber.api.TestCase; import cucumber.api.TestCase;


public class TestCaseFinished extends TimeStampedEvent { public final class TestCaseFinished extends TimeStampedEvent {
public final Result result; public final Result result;
public final TestCase testCase; public final TestCase testCase;


Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/event/TestCaseStarted.java
Expand Up @@ -2,7 +2,7 @@


import cucumber.api.TestCase; import cucumber.api.TestCase;


public class TestCaseStarted extends TimeStampedEvent { public final class TestCaseStarted extends TimeStampedEvent {
public final TestCase testCase; public final TestCase testCase;


public TestCaseStarted(Long timeStamp, TestCase testCase) { public TestCaseStarted(Long timeStamp, TestCase testCase) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/event/TestRunFinished.java
@@ -1,6 +1,6 @@
package cucumber.api.event; package cucumber.api.event;


public class TestRunFinished extends TimeStampedEvent { public final class TestRunFinished extends TimeStampedEvent {


public TestRunFinished(Long timeStamp) { public TestRunFinished(Long timeStamp) {
super(timeStamp); super(timeStamp);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/event/TestSourceRead.java
@@ -1,6 +1,6 @@
package cucumber.api.event; package cucumber.api.event;


public class TestSourceRead extends TimeStampedEvent { public final class TestSourceRead extends TimeStampedEvent {
public final String path; public final String path;
public final String language; public final String language;
public final String source; public final String source;
Expand Down
Expand Up @@ -3,7 +3,7 @@
import cucumber.api.Result; import cucumber.api.Result;
import cucumber.api.TestStep; import cucumber.api.TestStep;


public class TestStepFinished extends TimeStampedEvent { public final class TestStepFinished extends TimeStampedEvent {
public final TestStep testStep; public final TestStep testStep;
public final Result result; public final Result result;


Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/event/TestStepStarted.java
Expand Up @@ -2,7 +2,7 @@


import cucumber.api.TestStep; import cucumber.api.TestStep;


public class TestStepStarted extends TimeStampedEvent { public final class TestStepStarted extends TimeStampedEvent {
public final TestStep testStep; public final TestStep testStep;


public TestStepStarted(Long timeStamp, TestStep testStep) { public TestStepStarted(Long timeStamp, TestStep testStep) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/api/event/TimeStampedEvent.java
@@ -1,9 +1,9 @@
package cucumber.api.event; package cucumber.api.event;


abstract class TimeStampedEvent implements Event { abstract class TimeStampedEvent implements Event {
private Long timeStamp; private final Long timeStamp;


public TimeStampedEvent(Long timeStamp) { TimeStampedEvent(Long timeStamp) {
this.timeStamp = timeStamp; this.timeStamp = timeStamp;
} }


Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/event/WriteEvent.java
@@ -1,6 +1,6 @@
package cucumber.api.event; package cucumber.api.event;


public class WriteEvent extends TimeStampedEvent { public final class WriteEvent extends TimeStampedEvent {
public final String text; public final String text;


public WriteEvent(Long timeStamp, String text) { public WriteEvent(Long timeStamp, String text) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/formatter/StrictAware.java
@@ -1,5 +1,5 @@
package cucumber.api.formatter; package cucumber.api.formatter;


public interface StrictAware { public interface StrictAware {
public void setStrict(boolean strict); void setStrict(boolean strict);
} }
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runner/EventBus.java
Expand Up @@ -24,13 +24,14 @@ public Long getTime() {
public void send(Event event) { public void send(Event event) {
if (handlers.containsKey(event.getClass())) { if (handlers.containsKey(event.getClass())) {
for (EventHandler handler : handlers.get(event.getClass())) { for (EventHandler handler : handlers.get(event.getClass())) {
//noinspection unchecked: protected by registerHandlerFor
handler.receive(event); handler.receive(event);
} }
} }
} }


@Override @Override
public void registerHandlerFor(Class<? extends Event> eventType, EventHandler<? extends Event> handler) { public <T extends Event> void registerHandlerFor(Class<T> eventType, EventHandler<T> handler) {
if (handlers.containsKey(eventType)) { if (handlers.containsKey(eventType)) {
handlers.get(eventType).add(handler); handlers.get(eventType).add(handler);
} else { } else {
Expand All @@ -39,5 +40,4 @@ public void registerHandlerFor(Class<? extends Event> eventType, EventHandler<?
handlers.put(eventType, list); handlers.put(eventType, list);
} }
} }

} }
5 changes: 2 additions & 3 deletions core/src/main/java/cucumber/runner/Runner.java
Expand Up @@ -52,7 +52,7 @@ public Runner(Glue glue, EventBus bus, Collection<? extends Backend> backends, R
public void runUnreportedStep(String featurePath, String language, String stepName, int line, List<PickleRow> dataTableRows, PickleString docString) throws Throwable { public void runUnreportedStep(String featurePath, String language, String stepName, int line, List<PickleRow> dataTableRows, PickleString docString) throws Throwable {
List<Argument> arguments = new ArrayList<Argument>(); List<Argument> arguments = new ArrayList<Argument>();
if (dataTableRows != null && !dataTableRows.isEmpty()) { if (dataTableRows != null && !dataTableRows.isEmpty()) {
arguments.add((Argument) new PickleTable(dataTableRows)); arguments.add(new PickleTable(dataTableRows));
} else if (docString != null) { } else if (docString != null) {
arguments.add(docString); arguments.add(docString);
} }
Expand Down Expand Up @@ -98,8 +98,7 @@ private TestCase createTestCaseForPickle(PickleEvent pickleEvent) {
if (!runtimeOptions.isDryRun()) { if (!runtimeOptions.isDryRun()) {
addTestStepsForAfterHooks(testSteps, pickleEvent.pickle.getTags()); addTestStepsForAfterHooks(testSteps, pickleEvent.pickle.getTags());
} }
TestCase testCase = new TestCase(testSteps, pickleEvent); return new TestCase(testSteps, pickleEvent);
return testCase;
} }


private void addTestStepsForPickleSteps(List<TestStep> testSteps, PickleEvent pickleEvent) { private void addTestStepsForPickleSteps(List<TestStep> testSteps, PickleEvent pickleEvent) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/runner/TimeService.java
Expand Up @@ -10,7 +10,7 @@ public long time() {
} }
}; };


public static class Stub implements TimeService { class Stub implements TimeService {
private final long duration; private final long duration;
private final ThreadLocal<Long> currentTime = new ThreadLocal<Long>(); private final ThreadLocal<Long> currentTime = new ThreadLocal<Long>();


Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runtime/Match.java
Expand Up @@ -3,14 +3,14 @@
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;


// public for testing with mockito.
public class Match { public class Match {
private static final long serialVersionUID = 1L;


private final List<Argument> arguments; private final List<Argument> arguments;
private final String location; private final String location;
public static final Match UNDEFINED = new Match(Collections.<Argument>emptyList(), null); public static final Match UNDEFINED = new Match(Collections.<Argument>emptyList(), null);


public Match(List<Argument> arguments, String location) { Match(List<Argument> arguments, String location) {
this.arguments = arguments; this.arguments = arguments;
this.location = location; this.location = location;
} }
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/runtime/PicklePredicate.java
Expand Up @@ -2,7 +2,7 @@


import gherkin.events.PickleEvent; import gherkin.events.PickleEvent;


public interface PicklePredicate { interface PicklePredicate {


boolean apply(PickleEvent pickleEvent); boolean apply(PickleEvent pickleEvent);
} }
Expand Up @@ -122,7 +122,7 @@ public HTMLFormatter(URL htmlReportDir) {
this.htmlReportDir = htmlReportDir; this.htmlReportDir = htmlReportDir;
} }


HTMLFormatter(URL htmlReportDir, NiceAppendable jsOut) { public HTMLFormatter(URL htmlReportDir, NiceAppendable jsOut) {
this(htmlReportDir); this(htmlReportDir);
this.jsOut = jsOut; this.jsOut = jsOut;
} }
Expand Down
Expand Up @@ -34,10 +34,9 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


public class JSONFormatter implements Formatter { class JSONFormatter implements Formatter {
private String currentFeatureFile; private String currentFeatureFile;
private List<Map<String, Object>> featureMaps = new ArrayList<Map<String, Object>>(); private List<Map<String, Object>> featureMaps = new ArrayList<Map<String, Object>>();
private Map<String, Object> currentFeatureMap;
private List<Map<String, Object>> currentElementsList; private List<Map<String, Object>> currentElementsList;
private Map<String, Object> currentElementMap; private Map<String, Object> currentElementMap;
private Map<String, Object> currentTestCaseMap; private Map<String, Object> currentTestCaseMap;
Expand Down Expand Up @@ -112,7 +111,7 @@ private void handleTestSourceRead(TestSourceRead event) {
private void handleTestCaseStarted(TestCaseStarted event) { private void handleTestCaseStarted(TestCaseStarted event) {
if (currentFeatureFile == null || !currentFeatureFile.equals(event.testCase.getPath())) { if (currentFeatureFile == null || !currentFeatureFile.equals(event.testCase.getPath())) {
currentFeatureFile = event.testCase.getPath(); currentFeatureFile = event.testCase.getPath();
currentFeatureMap = createFeatureMap(event.testCase); Map<String, Object> currentFeatureMap = createFeatureMap(event.testCase);
featureMaps.add(currentFeatureMap); featureMaps.add(currentFeatureMap);
currentElementsList = (List<Map<String, Object>>) currentFeatureMap.get("elements"); currentElementsList = (List<Map<String, Object>>) currentFeatureMap.get("elements");
} }
Expand Down
16 changes: 3 additions & 13 deletions core/src/main/java/cucumber/runtime/formatter/PluginFactory.java
Expand Up @@ -40,7 +40,6 @@
* </ul> * </ul>
* Plugins must implement one of the following interfaces: * Plugins must implement one of the following interfaces:
* <ul> * <ul>
* <li>{@link cucumber.api.Formatter}</li>
* <li>{@link cucumber.api.StepDefinitionReporter}</li> * <li>{@link cucumber.api.StepDefinitionReporter}</li>
* </ul> * </ul>
*/ */
Expand Down Expand Up @@ -191,26 +190,17 @@ private Appendable defaultOutOrFailIfAlreadyUsed(String formatterString) {


public static boolean isFormatterName(String name) { public static boolean isFormatterName(String name) {
Class pluginClass = getPluginClass(name); Class pluginClass = getPluginClass(name);
if (Formatter.class.isAssignableFrom(pluginClass)) { return Formatter.class.isAssignableFrom(pluginClass);
return true;
}
return false;
} }


public static boolean isStepDefinitionResporterName(String name) { public static boolean isStepDefinitionResporterName(String name) {
Class pluginClass = getPluginClass(name); Class pluginClass = getPluginClass(name);
if (StepDefinitionReporter.class.isAssignableFrom(pluginClass)) { return StepDefinitionReporter.class.isAssignableFrom(pluginClass);
return true;
}
return false;
} }


public static boolean isSummaryPrinterName(String name) { public static boolean isSummaryPrinterName(String name) {
Class pluginClass = getPluginClass(name); Class pluginClass = getPluginClass(name);
if (SummaryPrinter.class.isAssignableFrom(pluginClass)) { return SummaryPrinter.class.isAssignableFrom(pluginClass);
return true;
}
return false;
} }


private static Class getPluginClass(String name) { private static Class getPluginClass(String name) {
Expand Down
Expand Up @@ -28,7 +28,7 @@


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


public class PrettyFormatter implements Formatter, ColorAware { class PrettyFormatter implements Formatter, ColorAware {
private static final String SCENARIO_INDENT = " "; private static final String SCENARIO_INDENT = " ";
private static final String STEP_INDENT = " "; private static final String STEP_INDENT = " ";
private static final String EXAMPLES_INDENT = " "; private static final String EXAMPLES_INDENT = " ";
Expand Down Expand Up @@ -209,7 +209,7 @@ private void printStep(TestStep testStep, Result result) {


String formatStepText(String keyword, String stepText, Format textFormat, Format argFormat, List<Argument> arguments) { String formatStepText(String keyword, String stepText, Format textFormat, Format argFormat, List<Argument> arguments) {
int textStart = 0; int textStart = 0;
StringBuffer result = new StringBuffer(textFormat.text(keyword)); StringBuilder result = new StringBuilder(textFormat.text(keyword));
for (Argument argument : arguments) { for (Argument argument : arguments) {
// can be null if the argument is missing. // can be null if the argument is missing.
if (argument.getOffset() != null) { if (argument.getOffset() != null) {
Expand Down
Expand Up @@ -30,7 +30,7 @@ public static List<CucumberFeature> load(ResourceLoader resourceLoader, List<Str
final List<CucumberFeature> cucumberFeatures = load(resourceLoader, featurePaths); final List<CucumberFeature> cucumberFeatures = load(resourceLoader, featurePaths);
if (cucumberFeatures.isEmpty()) { if (cucumberFeatures.isEmpty()) {
if (featurePaths.isEmpty()) { if (featurePaths.isEmpty()) {
out.println(String.format("Got no path to feature directory or feature file")); out.println("Got no path to feature directory or feature file");
} else { } else {
out.println(String.format("No features found at %s", featurePaths)); out.println(String.format("No features found at %s", featurePaths));
} }
Expand Down Expand Up @@ -79,8 +79,7 @@ public static List<String> loadRerunFile(ResourceLoader resourceLoader, String r


private static String read(Resource resource) { private static String read(Resource resource) {
try { try {
String source = Encoding.readFile(resource); return Encoding.readFile(resource);
return source;
} catch (IOException e) { } catch (IOException e) {
throw new CucumberException("Failed to read resource:" + resource.getPath(), e); throw new CucumberException("Failed to read resource:" + resource.getPath(), e);
} }
Expand Down
8 changes: 4 additions & 4 deletions core/src/test/java/cucumber/runtime/RuntimeTest.java
Expand Up @@ -5,7 +5,6 @@
import cucumber.api.Scenario; import cucumber.api.Scenario;
import cucumber.api.StepDefinitionReporter; import cucumber.api.StepDefinitionReporter;
import cucumber.api.TestStep; import cucumber.api.TestStep;
import cucumber.runtime.formatter.JSONFormatter;
import cucumber.runtime.formatter.FormatterSpy; import cucumber.runtime.formatter.FormatterSpy;
import cucumber.runtime.io.ClasspathResourceLoader; import cucumber.runtime.io.ClasspathResourceLoader;
import cucumber.runtime.io.Resource; import cucumber.runtime.io.Resource;
Expand Down Expand Up @@ -65,7 +64,8 @@ public void runs_feature_with_json_formatter() throws Exception {
" Scenario: scenario name\n" + " Scenario: scenario name\n" +
" When s\n"); " When s\n");
StringBuilder out = new StringBuilder(); StringBuilder out = new StringBuilder();
JSONFormatter jsonFormatter = new JSONFormatter(out);
// JSONFormatter jsonFormatter = new JSONFormatter(out);
List<Backend> backends = asList(mock(Backend.class)); List<Backend> backends = asList(mock(Backend.class));
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions(""); RuntimeOptions runtimeOptions = new RuntimeOptions("");
Expand Down Expand Up @@ -222,8 +222,8 @@ public void reports_step_definitions_to_plugin() throws IOException, NoSuchMetho
} }


public static class StepdefsPrinter implements StepDefinitionReporter { public static class StepdefsPrinter implements StepDefinitionReporter {
public static StepdefsPrinter instance; static StepdefsPrinter instance;
public StepDefinition stepDefinition; StepDefinition stepDefinition;


public StepdefsPrinter() { public StepdefsPrinter() {
instance = this; instance = this;
Expand Down
2 changes: 0 additions & 2 deletions junit/src/main/java/cucumber/api/junit/Cucumber.java
Expand Up @@ -23,8 +23,6 @@
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;


/** /**
* <p> * <p>
Expand Down

0 comments on commit ac1b214

Please sign in to comment.