Skip to content

Commit b75b940

Browse files
committed
[Core] Add TimeStampMillis to TimeStampedEvent
A timestamp is more useful when that timestamp is relative to the epoch. Unlike `System.currentTimeMillis`, `System.nanoTime` is relative to some arbitrary point in time. Additionally the extra granularity has no practical benefit. This is evidenced by the stats, junit and, testng formatter which all express the elapsed time in milliseconds.
1 parent 6698a38 commit b75b940

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+241
-166
lines changed

core/src/main/java/cucumber/api/Result.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public final class Result {
1212

13-
public final static Comparator<Result> SEVERITY = new Comparator<Result>() {
13+
public static final Comparator<Result> SEVERITY = new Comparator<Result>() {
1414

1515
@Override
1616
public int compare(Result a, Result b) {

core/src/main/java/cucumber/api/event/CanonicalEventOrder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ private static final class TestCaseEventComparator implements Comparator<TestCas
6262

6363
@Override
6464
public int compare(TestCaseEvent a, TestCaseEvent b) {
65-
int uri = a.testCase.getUri().compareTo(b.testCase.getUri());
65+
int uri = a.getTestCase().getUri().compareTo(b.getTestCase().getUri());
6666
if (uri != 0) {
6767
return uri;
6868
}
6969

70-
int line = Integer.compare(a.testCase.getLine(), b.testCase.getLine());
70+
int line = Integer.compare(a.getTestCase().getLine(), b.getTestCase().getLine());
7171
if(line != 0){
7272
return line;
7373
}
7474

75-
return Long.compare(a.getTimeStamp(), b.getTimeStamp());
75+
return Long.compare(a.getTimeStampMillis(), b.getTimeStampMillis());
7676
}
7777
}
7878
}

core/src/main/java/cucumber/api/event/EmbedEvent.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ public final class EmbedEvent extends TestCaseEvent {
66
public final byte[] data;
77
public final String mimeType;
88

9+
@Deprecated
910
public EmbedEvent(Long timeStamp, TestCase testCase, byte[] data, String mimeType) {
10-
super(timeStamp, testCase);
11+
this(timeStamp, 0, testCase, data, mimeType);
12+
}
13+
14+
public EmbedEvent(Long timeStamp, long timeStampMillis, TestCase testCase, byte[] data, String mimeType) {
15+
super(timeStamp, timeStampMillis, testCase);
1116
this.data = data;
1217
this.mimeType = mimeType;
1318
}

core/src/main/java/cucumber/api/event/Event.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ public interface Event {
3030
*/
3131
Comparator<Event> CANONICAL_ORDER = new CanonicalEventOrder();
3232

33+
/**
34+
* Returns a timestamp in nano seconds.
35+
*
36+
* @return timestamp in nano seconds
37+
* @see System#nanoTime()
38+
*/
39+
@Deprecated
3340
Long getTimeStamp();
3441

42+
/**
43+
* Returns a timestamp in miliseconds since the epoch.
44+
*
45+
* @return timestamp in milli seconds
46+
* @see System#currentTimeMillis()
47+
*/
48+
long getTimeStampMillis();
49+
3550
}

core/src/main/java/cucumber/api/event/SnippetsSuggestedEvent.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ public class SnippetsSuggestedEvent extends TimeStampedEvent {
1010
public final List<PickleLocation> stepLocations;
1111
public final List<String> snippets;
1212

13+
@Deprecated
1314
public SnippetsSuggestedEvent(Long timeStamp, String uri, List<PickleLocation> stepLocations, List<String> snippets) {
14-
super(timeStamp);
15+
this(timeStamp, 0, uri, stepLocations, snippets);
16+
}
17+
18+
public SnippetsSuggestedEvent(Long timeStamp, long timeStampMillis, String uri, List<PickleLocation> stepLocations, List<String> snippets) {
19+
super(timeStamp, timeStampMillis);
1520
this.uri = uri;
1621
this.stepLocations = stepLocations;
1722
this.snippets = Collections.unmodifiableList(snippets);

core/src/main/java/cucumber/api/event/TestCaseEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
public abstract class TestCaseEvent extends TimeStampedEvent {
66

7-
final TestCase testCase;
7+
private final TestCase testCase;
88

9-
TestCaseEvent(Long timeStamp, TestCase testCase) {
10-
super(timeStamp);
9+
TestCaseEvent(Long timeStamp, long timeStampMillis, TestCase testCase) {
10+
super(timeStamp, timeStampMillis);
1111
this.testCase = testCase;
1212
}
1313

core/src/main/java/cucumber/api/event/TestCaseFinished.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ public final class TestCaseFinished extends TestCaseEvent {
77
public final Result result;
88
public final TestCase testCase;
99

10+
@Deprecated
1011
public TestCaseFinished(Long timeStamp, TestCase testCase, Result result) {
11-
super(timeStamp, testCase);
12+
this(timeStamp, 0, testCase, result);
13+
}
14+
15+
public TestCaseFinished(Long timeStamp, long timeStampMillis, TestCase testCase, Result result) {
16+
super(timeStamp, timeStampMillis, testCase);
1217
this.testCase = testCase;
1318
this.result = result;
1419
}

core/src/main/java/cucumber/api/event/TestCaseStarted.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@
44

55
public final class TestCaseStarted extends TestCaseEvent {
66
public final TestCase testCase;
7-
private final long timeStampMillis;
8-
7+
98
@Deprecated
109
public TestCaseStarted(Long timeStamp, TestCase testCase) {
1110
this(timeStamp, 0L, testCase);
1211
}
1312

14-
public TestCaseStarted(Long timeStamp, Long timeStampMillis, TestCase testCase) {
15-
super(timeStamp, testCase);
13+
public TestCaseStarted(Long timeStamp, long timeStampMillis, TestCase testCase) {
14+
super(timeStamp, timeStampMillis, testCase);
1615
this.testCase = testCase;
17-
this.timeStampMillis = timeStampMillis;
1816
}
1917

20-
public long getTimeStampMillis() {
21-
return timeStampMillis;
22-
}
2318
}

core/src/main/java/cucumber/api/event/TestRunFinished.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
public final class TestRunFinished extends TimeStampedEvent {
44

5+
@Deprecated
56
public TestRunFinished(Long timeStamp) {
6-
super(timeStamp);
7+
this(timeStamp, 0);
8+
}
9+
10+
public TestRunFinished(Long timeStamp, long timeStampMillis) {
11+
super(timeStamp, timeStampMillis);
712
}
813
}

core/src/main/java/cucumber/api/event/TestRunStarted.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
public final class TestRunStarted extends TimeStampedEvent {
44

5+
@Deprecated
56
public TestRunStarted(Long timeStamp) {
6-
super(timeStamp);
7+
this(timeStamp, 0);
8+
}
9+
10+
public TestRunStarted(Long timeStamp, long timeStampMillis) {
11+
super(timeStamp, timeStampMillis);
712
}
813
}

0 commit comments

Comments
 (0)