Skip to content

Commit a5b89f4

Browse files
committed
Add more queries
1 parent 072e795 commit a5b89f4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

java/src/main/java/io/cucumber/query/Query.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,25 @@ public Optional<TestCase> findTestCaseBy(TestCaseStarted testCaseStarted) {
280280
requireNonNull(testCaseStarted);
281281
return ofNullable(testCaseById.get(testCaseStarted.getTestCaseId()));
282282
}
283+
284+
public Optional<TestCase> findTestCaseBy(TestCaseFinished testCaseFinished) {
285+
requireNonNull(testCaseFinished);
286+
return findTestCaseStartedBy(testCaseFinished)
287+
.flatMap(this::findTestCaseBy);
288+
}
283289

284290
public Optional<TestCase> findTestCaseBy(TestStepStarted testStepStarted) {
285291
requireNonNull(testStepStarted);
286292
return findTestCaseStartedBy(testStepStarted)
287293
.flatMap(this::findTestCaseBy);
288294
}
289295

296+
public Optional<TestCase> findTestCaseBy(TestStepFinished testStepFinished) {
297+
requireNonNull(testStepFinished);
298+
return findTestCaseStartedBy(testStepFinished)
299+
.flatMap(this::findTestCaseBy);
300+
}
301+
290302
public Optional<Duration> findTestCaseDurationBy(TestCaseStarted testCaseStarted) {
291303
requireNonNull(testCaseStarted);
292304
Timestamp started = testCaseStarted.getTimestamp();
@@ -297,13 +309,36 @@ public Optional<Duration> findTestCaseDurationBy(TestCaseStarted testCaseStarted
297309
Convertor.toInstant(finished)
298310
));
299311
}
312+
313+
public Optional<Duration> findTestCaseDurationBy(TestCaseFinished testCaseFinished) {
314+
requireNonNull(testCaseFinished);
315+
Timestamp finished = testCaseFinished.getTimestamp();
316+
return findTestCaseStartedBy(testCaseFinished)
317+
.map(TestCaseStarted::getTimestamp)
318+
.map(started -> Duration.between(
319+
Convertor.toInstant(started),
320+
Convertor.toInstant(finished)
321+
));
322+
}
300323

301324
public Optional<TestCaseStarted> findTestCaseStartedBy(TestStepStarted testStepStarted) {
302325
requireNonNull(testStepStarted);
303326
String testCaseStartedId = testStepStarted.getTestCaseStartedId();
304327
return ofNullable(testCaseStartedById.get(testCaseStartedId));
305328
}
306329

330+
private Optional<TestCaseStarted> findTestCaseStartedBy(TestCaseFinished testCaseFinished) {
331+
requireNonNull(testCaseFinished);
332+
String testCaseStartedId = testCaseFinished.getTestCaseStartedId();
333+
return ofNullable(testCaseStartedById.get(testCaseStartedId));
334+
}
335+
336+
public Optional<TestCaseStarted> findTestCaseStartedBy(TestStepFinished testStepFinished) {
337+
requireNonNull(testStepFinished);
338+
String testCaseStartedId = testStepFinished.getTestCaseStartedId();
339+
return ofNullable(testCaseStartedById.get(testCaseStartedId));
340+
}
341+
307342
public Optional<TestCaseFinished> findTestCaseFinishedBy(TestCaseStarted testCaseStarted) {
308343
requireNonNull(testCaseStarted);
309344
return ofNullable(testCaseFinishedByTestCaseStartedId.get(testCaseStarted.getId()));

0 commit comments

Comments
 (0)