Skip to content

Commit f0ad9b4

Browse files
committed
Add more queries
1 parent d1545b4 commit f0ad9b4

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
@@ -307,13 +307,25 @@ public Optional<TestCase> findTestCaseBy(TestCaseStarted testCaseStarted) {
307307
requireNonNull(testCaseStarted);
308308
return ofNullable(testCaseById.get(testCaseStarted.getTestCaseId()));
309309
}
310+
311+
public Optional<TestCase> findTestCaseBy(TestCaseFinished testCaseFinished) {
312+
requireNonNull(testCaseFinished);
313+
return findTestCaseStartedBy(testCaseFinished)
314+
.flatMap(this::findTestCaseBy);
315+
}
310316

311317
public Optional<TestCase> findTestCaseBy(TestStepStarted testStepStarted) {
312318
requireNonNull(testStepStarted);
313319
return findTestCaseStartedBy(testStepStarted)
314320
.flatMap(this::findTestCaseBy);
315321
}
316322

323+
public Optional<TestCase> findTestCaseBy(TestStepFinished testStepFinished) {
324+
requireNonNull(testStepFinished);
325+
return findTestCaseStartedBy(testStepFinished)
326+
.flatMap(this::findTestCaseBy);
327+
}
328+
317329
public Optional<Duration> findTestCaseDurationBy(TestCaseStarted testCaseStarted) {
318330
requireNonNull(testCaseStarted);
319331
Timestamp started = testCaseStarted.getTimestamp();
@@ -324,13 +336,36 @@ public Optional<Duration> findTestCaseDurationBy(TestCaseStarted testCaseStarted
324336
Convertor.toInstant(finished)
325337
));
326338
}
339+
340+
public Optional<Duration> findTestCaseDurationBy(TestCaseFinished testCaseFinished) {
341+
requireNonNull(testCaseFinished);
342+
Timestamp finished = testCaseFinished.getTimestamp();
343+
return findTestCaseStartedBy(testCaseFinished)
344+
.map(TestCaseStarted::getTimestamp)
345+
.map(started -> Duration.between(
346+
Convertor.toInstant(started),
347+
Convertor.toInstant(finished)
348+
));
349+
}
327350

328351
public Optional<TestCaseStarted> findTestCaseStartedBy(TestStepStarted testStepStarted) {
329352
requireNonNull(testStepStarted);
330353
String testCaseStartedId = testStepStarted.getTestCaseStartedId();
331354
return ofNullable(testCaseStartedById.get(testCaseStartedId));
332355
}
333356

357+
private Optional<TestCaseStarted> findTestCaseStartedBy(TestCaseFinished testCaseFinished) {
358+
requireNonNull(testCaseFinished);
359+
String testCaseStartedId = testCaseFinished.getTestCaseStartedId();
360+
return ofNullable(testCaseStartedById.get(testCaseStartedId));
361+
}
362+
363+
public Optional<TestCaseStarted> findTestCaseStartedBy(TestStepFinished testStepFinished) {
364+
requireNonNull(testStepFinished);
365+
String testCaseStartedId = testStepFinished.getTestCaseStartedId();
366+
return ofNullable(testCaseStartedById.get(testCaseStartedId));
367+
}
368+
334369
public Optional<TestCaseFinished> findTestCaseFinishedBy(TestCaseStarted testCaseStarted) {
335370
requireNonNull(testCaseStarted);
336371
return ofNullable(testCaseFinishedByTestCaseStartedId.get(testCaseStarted.getId()));

0 commit comments

Comments
 (0)