Skip to content

[Core] Replace TimeService with Java Time API #1620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public int compare(TestCaseEvent a, TestCaseEvent b) {
return line;
}

return Long.compare(a.getTimeStamp(), b.getTimeStamp());
return a.getTimeInstant().compareTo(b.getTimeInstant());
}
}
}
9 changes: 9 additions & 0 deletions core/src/main/java/io/cucumber/core/api/event/EmbedEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.core.api.event;

import java.time.Instant;

public final class EmbedEvent extends TestCaseEvent {
public final byte[] data;
public final String mimeType;
Expand All @@ -9,10 +11,17 @@ public EmbedEvent(Long timeStamp, TestCase testCase, byte[] data, String mimeTyp
this(timeStamp, 0, testCase, data, mimeType);
}

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

public EmbedEvent(Instant timeInstant, TestCase testCase, byte[] data, String mimeType) {
super(timeInstant, testCase);
this.data = data;
this.mimeType = mimeType;
}

}
8 changes: 8 additions & 0 deletions core/src/main/java/io/cucumber/core/api/event/Event.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.cucumber.core.api.event;

import java.time.Instant;
import java.util.Comparator;

public interface Event {
Expand Down Expand Up @@ -40,4 +41,11 @@ public interface Event {
@Deprecated
Long getTimeStamp();

/**
* Returns instant from epoch.
*
* @return time instant in Instant
* @see Instant#now()
*/
Instant getTimeInstant();
}
16 changes: 9 additions & 7 deletions core/src/main/java/io/cucumber/core/api/event/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.Duration;
import java.util.Comparator;
import java.util.Objects;

import static java.time.Duration.ZERO;
import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;

Expand All @@ -19,9 +21,9 @@ public int compare(Result a, Result b) {
};

private final Type status;
private final Long duration;
private final Duration duration;
private final Throwable error;
public static final Result UNDEFINED = new Result(Result.Type.UNDEFINED, 0L, null);
public static final Result UNDEFINED = new Result(Result.Type.UNDEFINED, ZERO, null);
public enum Type {
PASSED,
SKIPPED,
Expand Down Expand Up @@ -49,10 +51,10 @@ public String firstLetterCapitalizedName() {
* The result of a step or scenario
*
* @param status status of the step or scenario
* @param duration the duration in nanoseconds
* @param duration the duration
* @param error the error that caused the failure if any
*/
public Result(Result.Type status, Long duration, Throwable error) {
public Result(Result.Type status, Duration duration, Throwable error) {
this.status = requireNonNull(status);
this.duration = requireNonNull(duration);
this.error = error;
Expand All @@ -62,10 +64,10 @@ public Result.Type getStatus() {
return status;
}

public Long getDuration() {
public Duration getDuration() {
return duration;
}

public String getErrorMessage() {
return error != null ? getErrorMessage(error) : null;
}
Expand Down Expand Up @@ -101,7 +103,7 @@ private String getErrorMessage(Throwable error) {
public String toString() {
return "Result{" +
"status=" + status +
", duration=" + duration +
", duration=" + duration.getSeconds() +
", error=" + error +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gherkin.pickles.PickleLocation;

import java.time.Instant;
import java.util.Collections;
import java.util.List;

Expand All @@ -15,11 +16,19 @@ public SnippetsSuggestedEvent(Long timeStamp, String uri, List<PickleLocation> s
this(timeStamp, 0, uri, stepLocations, snippets);
}

@Deprecated
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);
}

public SnippetsSuggestedEvent(Instant timeInstant, String uri, List<PickleLocation> stepLocations, List<String> snippets) {
super(timeInstant);
this.uri = uri;
this.stepLocations = stepLocations;
this.snippets = Collections.unmodifiableList(snippets);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package io.cucumber.core.api.event;

import java.time.Instant;

public abstract class TestCaseEvent extends TimeStampedEvent {

private final TestCase testCase;

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

TestCaseEvent(Instant timeInstant, TestCase testCase) {
super(timeInstant);
this.testCase = testCase;
}

public TestCase getTestCase() {
return testCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.core.api.event;

import java.time.Instant;

public final class TestCaseFinished extends TestCaseEvent {
public final Result result;
public final TestCase testCase;
Expand All @@ -9,10 +11,16 @@ public TestCaseFinished(Long timeStamp, TestCase testCase, Result result) {
this(timeStamp, 0, testCase, result);
}

@Deprecated
public TestCaseFinished(Long timeStamp, long timeStampMillis, TestCase testCase, Result result) {
super(timeStamp, timeStampMillis, testCase);
this.testCase = testCase;
this.result = result;
}

public TestCaseFinished(Instant timeInstant, TestCase testCase, Result result) {
super(timeInstant, testCase);
this.testCase = testCase;
this.result = result;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.core.api.event;

import java.time.Instant;

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

Expand All @@ -8,9 +10,15 @@ public TestCaseStarted(Long timeStamp, TestCase testCase) {
this(timeStamp, 0L, testCase);
}

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

public TestCaseStarted(Instant timeInstant, TestCase testCase) {
super(timeInstant, testCase);
this.testCase = testCase;
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package io.cucumber.core.api.event;

import java.time.Instant;

public final class TestRunFinished extends TimeStampedEvent {

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

@Deprecated
public TestRunFinished(Long timeStamp, long timeStampMillis) {
super(timeStamp, timeStampMillis);
}

public TestRunFinished(Instant timeInstant) {
super(timeInstant);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package io.cucumber.core.api.event;

import java.time.Instant;

public final class TestRunStarted extends TimeStampedEvent {

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

@Deprecated
public TestRunStarted(Long timeStamp, long timeStampMillis) {
super(timeStamp, timeStampMillis);
}

public TestRunStarted(Instant timeInstant) {
super(timeInstant);
}
}
10 changes: 10 additions & 0 deletions core/src/main/java/io/cucumber/core/api/event/TestSourceRead.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.core.api.event;

import java.time.Instant;

public final class TestSourceRead extends TimeStampedEvent {
public final String uri;
public final String source;
Expand All @@ -9,10 +11,18 @@ public TestSourceRead(Long timeStamp, String uri, String source) {
this(timeStamp, 0, uri, source);
}

@Deprecated
public TestSourceRead(Long timeStamp, long timeStampMillis, String uri, String source) {
super(timeStamp, timeStampMillis);
this.uri = uri;
this.source = source;
}


public TestSourceRead(Instant timeInstant, String uri, String source) {
super(timeInstant);
this.uri = uri;
this.source = source;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.core.api.event;

import java.time.Instant;

/**
* A test step finished event is broadcast when ever a step finishes.
* <p>
Expand All @@ -25,10 +27,17 @@ public TestStepFinished(Long timeStamp, TestCase testCase, TestStep testStep, Re
this(timeStamp, 0, testCase, testStep, result);
}

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

public TestStepFinished(Instant timeInstant, TestCase testCase, TestStep testStep, Result result) {
super(timeInstant, testCase);
this.testStep = testStep;
this.result = result;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.core.api.event;

import java.time.Instant;

/**
* A test step started event is broadcast when ever a step starts.
* <p>
Expand All @@ -25,9 +27,15 @@ public TestStepStarted(Long timeStamp, TestCase testCase, TestStep testStep) {
this(timeStamp, 0, testCase, testStep);
}

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

public TestStepStarted(Instant timeInstant, TestCase testCase, TestStep testStep) {
super(timeInstant, testCase);
this.testStep = testStep;
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package io.cucumber.core.api.event;

import java.time.Instant;

abstract class TimeStampedEvent implements Event {

private final Long timeStamp;
private final long timeStampMillis;
private final Instant timeInstant;

@Deprecated
TimeStampedEvent(Long timeStamp, Long timeStampMillis) {
this.timeStamp = timeStamp;
this.timeStampMillis = timeStampMillis;
this.timeInstant = Instant.EPOCH;
}

TimeStampedEvent(Instant timeInstant) {
this.timeStamp = 0L;
this.timeStampMillis = 0L;
this.timeInstant = timeInstant;
}

/**
* {@inheritDoc}
*/

@Deprecated
@Override
public Long getTimeStamp() {
return timeStamp;
Expand All @@ -24,7 +37,17 @@ public Long getTimeStamp() {
* @return timestamp in milli seconds
* @see System#currentTimeMillis()
*/

@Deprecated
public long getTimeStampMillis() {
return timeStampMillis;
}

/**
* {@inheritDoc}
*/
@Override
public Instant getTimeInstant() {
return timeInstant;
}
}
Loading