Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/api/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public final class Result {

public final static Comparator<Result> SEVERITY = new Comparator<Result>() {
public static final Comparator<Result> SEVERITY = new Comparator<Result>() {

@Override
public int compare(Result a, Result b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ private static final class TestCaseEventComparator implements Comparator<TestCas

@Override
public int compare(TestCaseEvent a, TestCaseEvent b) {
int uri = a.testCase.getUri().compareTo(b.testCase.getUri());
int uri = a.getTestCase().getUri().compareTo(b.getTestCase().getUri());
if (uri != 0) {
return uri;
}

int line = Integer.compare(a.testCase.getLine(), b.testCase.getLine());
int line = Integer.compare(a.getTestCase().getLine(), b.getTestCase().getLine());
if(line != 0){
return line;
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/cucumber/api/event/EmbedEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ public final class EmbedEvent extends TestCaseEvent {
public final byte[] data;
public final String mimeType;

@Deprecated
public EmbedEvent(Long timeStamp, TestCase testCase, byte[] data, String mimeType) {
super(timeStamp, testCase);
this(timeStamp, 0, testCase, data, mimeType);
}

public EmbedEvent(Long timeStamp, long timeStampMillis, TestCase testCase, byte[] data, String mimeType) {
super(timeStamp, timeStampMillis, testCase);
this.data = data;
this.mimeType = mimeType;
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/cucumber/api/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public interface Event {
*/
Comparator<Event> CANONICAL_ORDER = new CanonicalEventOrder();

/**
* Returns timestamp in nano seconds since an arbitrary start time.
*
* @return timestamp in nano seconds
* @see System#nanoTime()
* @deprecated prefer {@link TimeStampedEvent#getTimeStampMillis()}
*/
@Deprecated
Long getTimeStamp();

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ public class SnippetsSuggestedEvent extends TimeStampedEvent {
public final List<PickleLocation> stepLocations;
public final List<String> snippets;

@Deprecated
public SnippetsSuggestedEvent(Long timeStamp, String uri, List<PickleLocation> stepLocations, List<String> snippets) {
super(timeStamp);
this(timeStamp, 0, uri, stepLocations, snippets);
}

public SnippetsSuggestedEvent(Long timeStamp, long timeStampMillis, String uri, List<PickleLocation> stepLocations, List<String> snippets) {
super(timeStamp, timeStampMillis);
this.uri = uri;
this.stepLocations = stepLocations;
this.snippets = Collections.unmodifiableList(snippets);
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/cucumber/api/event/TestCaseEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

public abstract class TestCaseEvent extends TimeStampedEvent {

final TestCase testCase;
private final TestCase testCase;

TestCaseEvent(Long timeStamp, TestCase testCase) {
super(timeStamp);
TestCaseEvent(Long timeStamp, long timeStampMillis, TestCase testCase) {
super(timeStamp, timeStampMillis);
this.testCase = testCase;
}

Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/cucumber/api/event/TestCaseFinished.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ public final class TestCaseFinished extends TestCaseEvent {
public final Result result;
public final TestCase testCase;

@Deprecated
public TestCaseFinished(Long timeStamp, TestCase testCase, Result result) {
super(timeStamp, testCase);
this(timeStamp, 0, testCase, result);
}

public TestCaseFinished(Long timeStamp, long timeStampMillis, TestCase testCase, Result result) {
super(timeStamp, timeStampMillis, testCase);
this.testCase = testCase;
this.result = result;
}
Expand Down
11 changes: 3 additions & 8 deletions core/src/main/java/cucumber/api/event/TestCaseStarted.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@

public final class TestCaseStarted extends TestCaseEvent {
public final TestCase testCase;
private final long timeStampMillis;


@Deprecated
public TestCaseStarted(Long timeStamp, TestCase testCase) {
this(timeStamp, 0L, testCase);
}

public TestCaseStarted(Long timeStamp, Long timeStampMillis, TestCase testCase) {
super(timeStamp, testCase);
public TestCaseStarted(Long timeStamp, long timeStampMillis, TestCase testCase) {
super(timeStamp, timeStampMillis, testCase);
this.testCase = testCase;
this.timeStampMillis = timeStampMillis;
}

public long getTimeStampMillis() {
return timeStampMillis;
}
}
7 changes: 6 additions & 1 deletion core/src/main/java/cucumber/api/event/TestRunFinished.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

public final class TestRunFinished extends TimeStampedEvent {

@Deprecated
public TestRunFinished(Long timeStamp) {
super(timeStamp);
this(timeStamp, 0);
}

public TestRunFinished(Long timeStamp, long timeStampMillis) {
super(timeStamp, timeStampMillis);
}
}
7 changes: 6 additions & 1 deletion core/src/main/java/cucumber/api/event/TestRunStarted.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

public final class TestRunStarted extends TimeStampedEvent {

@Deprecated
public TestRunStarted(Long timeStamp) {
super(timeStamp);
this(timeStamp, 0);
}

public TestRunStarted(Long timeStamp, long timeStampMillis) {
super(timeStamp, timeStampMillis);
}
}
7 changes: 6 additions & 1 deletion core/src/main/java/cucumber/api/event/TestSourceRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ public final class TestSourceRead extends TimeStampedEvent {
public final String uri;
public final String source;

@Deprecated
public TestSourceRead(Long timeStamp, String uri, String source) {
super(timeStamp);
this(timeStamp, 0, uri, source);
}

public TestSourceRead(Long timeStamp, long timeStampMillis, String uri, String source) {
super(timeStamp, timeStampMillis);
this.uri = uri;
this.source = source;
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/cucumber/api/event/TestStepFinished.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ public final class TestStepFinished extends TestCaseEvent {
public final TestStep testStep;
public final Result result;

@Deprecated
public TestStepFinished(Long timeStamp, TestCase testCase, TestStep testStep, Result result) {
super(timeStamp, testCase);
this(timeStamp, 0, testCase, testStep, result);
}

public TestStepFinished(Long timeStamp, long timeStampMillis, TestCase testCase, TestStep testStep, Result result) {
super(timeStamp, timeStampMillis, testCase);
this.testStep = testStep;
this.result = result;
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/cucumber/api/event/TestStepStarted.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
public final class TestStepStarted extends TestCaseEvent {
public final TestStep testStep;

@Deprecated
public TestStepStarted(Long timeStamp, TestCase testCase, TestStep testStep) {
super(timeStamp, testCase);
this(timeStamp, 0, testCase, testStep);
}

public TestStepStarted(Long timeStamp, long timeStampMillis, TestCase testCase, TestStep testStep) {
super(timeStamp, timeStampMillis, testCase);
this.testStep = testStep;
}

Expand Down
18 changes: 17 additions & 1 deletion core/src/main/java/cucumber/api/event/TimeStampedEvent.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
package cucumber.api.event;

abstract class TimeStampedEvent implements Event {

private final Long timeStamp;
private final long timeStampMillis;

TimeStampedEvent(Long timeStamp) {
TimeStampedEvent(Long timeStamp, Long timeStampMillis) {
this.timeStamp = timeStamp;
this.timeStampMillis = timeStampMillis;
}

/**
* {@inheritDoc}
*/
@Override
public Long getTimeStamp() {
return timeStamp;
}

/**
* Returns timestamp in milliseconds of the epoch.
*
* @return timestamp in milli seconds
* @see System#currentTimeMillis()
*/
public long getTimeStampMillis() {
return timeStampMillis;
}
}
7 changes: 6 additions & 1 deletion core/src/main/java/cucumber/api/event/WriteEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
public final class WriteEvent extends TestCaseEvent {
public final String text;

@Deprecated
public WriteEvent(Long timeStamp, TestCase testCase, String text) {
super(timeStamp, testCase);
this(timeStamp, 0, testCase, text);
}

public WriteEvent(Long timeStamp, long timeStampMillis, TestCase testCase, String text) {
super(timeStamp, timeStampMillis, testCase);
this.text = text;
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runner/EventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public interface EventBus extends EventPublisher {

Long getTime();
Long getTimeStampMillis();

Long getTimeMillis();

void send(Event event);

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/cucumber/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void addTestStepsForPickleSteps(List<PickleStepTestStep> testSteps, Pick
snippets.addAll(snippet);
}
if (!snippets.isEmpty()) {
bus.send(new SnippetsSuggestedEvent(bus.getTime(), pickleEvent.uri, step.getLocations(), snippets));
bus.send(new SnippetsSuggestedEvent(bus.getTime(), bus.getTimeMillis(), pickleEvent.uri, step.getLocations(), snippets));
}
match = new UndefinedPickleStepDefinitionMatch(step);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runner/Scenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public boolean isFailed() {
@Override
public void embed(byte[] data, String mimeType) {
if (bus != null) {
bus.send(new EmbedEvent(bus.getTime(), testCase, data, mimeType));
bus.send(new EmbedEvent(bus.getTime(), bus.getTimeMillis(), testCase, data, mimeType));
}
}

@Override
public void write(String text) {
if (bus != null) {
bus.send(new WriteEvent(bus.getTime(), testCase, text));
bus.send(new WriteEvent(bus.getTime(), bus.getTimeMillis(), testCase, text));
}
}

Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/cucumber/runner/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public TestCase(List<PickleStepTestStep> testSteps,

void run(EventBus bus) {
boolean skipNextStep = this.dryRun;
Long startTime = bus.getTime();
Long startTimeStampMillis = bus.getTimeStampMillis();
bus.send(new TestCaseStarted(startTime, startTimeStampMillis, this));
Long startTimeMillis = bus.getTimeMillis();
Long startTimeNanos = bus.getTime();
bus.send(new TestCaseStarted(startTimeNanos, startTimeMillis, this));
Scenario scenario = new Scenario(bus, this);

for (HookTestStep before : beforeHooks) {
Expand All @@ -50,8 +50,9 @@ void run(EventBus bus) {
after.run(this, bus, scenario, dryRun);
}

Long stopTime = bus.getTime();
bus.send(new TestCaseFinished(stopTime, this, new Result(scenario.getStatus(), stopTime - startTime, scenario.getError())));
Long stopTimeNanos = bus.getTime();
Long stopTimeMillis = bus.getTimeMillis();
bus.send(new TestCaseFinished(stopTimeNanos, stopTimeMillis, this, new Result(scenario.getStatus(), stopTimeNanos - startTimeNanos, scenario.getError())));
}

@Override
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/cucumber/runner/TestStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public String getCodeLocation() {
* @return true iff subsequent skippable steps should be skipped
*/
boolean run(TestCase testCase, EventBus bus, Scenario scenario, boolean skipSteps) {
Long startTime = bus.getTime();
bus.send(new TestStepStarted(startTime, testCase, this));
Long startTimeMillis = bus.getTimeMillis();
Long startTimeNanos = bus.getTime();
bus.send(new TestStepStarted(startTimeNanos, startTimeMillis, testCase, this));
Result.Type status;
Throwable error = null;
try {
Expand All @@ -51,10 +52,11 @@ boolean run(TestCase testCase, EventBus bus, Scenario scenario, boolean skipStep
error = t;
status = mapThrowableToStatus(t);
}
Long stopTime = bus.getTime();
Result result = mapStatusToResult(status, error, stopTime - startTime);
Long stopTimeNanos = bus.getTime();
Long stopTimeMillis = bus.getTimeMillis();
Result result = mapStatusToResult(status, error, stopTimeNanos - startTimeNanos);
scenario.add(result);
bus.send(new TestStepFinished(stopTime, testCase, this, result));
bus.send(new TestStepFinished(stopTimeNanos, stopTimeMillis, testCase, this, result));
return !result.is(Result.Type.PASSED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public void send(final Event event) {
}

@Override
public Long getTimeStampMillis() {
return parent.getTimeStampMillis();
public Long getTimeMillis() {
return parent.getTimeMillis();
}
}

Expand Down Expand Up @@ -109,8 +109,8 @@ public synchronized <T extends Event> void removeHandlerFor(Class<T> eventType,
}

@Override
public Long getTimeStampMillis() {
return delegate.getTimeStampMillis();
public Long getTimeMillis() {
return delegate.getTimeMillis();
}
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runner/TimeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface TimeService {
long time();
long timeStampMillis();
long timeMillis();

TimeService SYSTEM = new TimeService() {
@Override
Expand All @@ -11,7 +11,7 @@ public long time() {
}

@Override
public long timeStampMillis() {
public long timeMillis() {
return System.currentTimeMillis();
}
};
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runner/TimeServiceEventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Long getTime() {
}

@Override
public Long getTimeStampMillis() {
return stopWatch.timeStampMillis();
public Long getTimeMillis() {
return stopWatch.timeMillis();
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Runtime(final Plugins plugins,

public void run() {
final List<CucumberFeature> features = featureSupplier.get();
bus.send(new TestRunStarted(bus.getTime()));
bus.send(new TestRunStarted(bus.getTime(), bus.getTimeMillis()));
for (CucumberFeature feature : features) {
feature.sendTestSourceRead(bus);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public void run() {
throw new CucumberException(e);
}

bus.send(new TestRunFinished(bus.getTime()));
bus.send(new TestRunFinished(bus.getTime(), bus.getTimeMillis()));
}

public byte exitStatus() {
Expand Down
Loading