Skip to content

Commit 70254b5

Browse files
committed
Simplify
1 parent db5944f commit 70254b5

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,8 @@ public Optional<TestStepResult> findMostSevereTestStepResultBy(TestCaseStarted t
177177

178178
public Optional<TestStepResult> findMostSevereTestStepResultBy(TestCaseFinished testCaseFinished) {
179179
requireNonNull(testCaseFinished);
180-
return findTestStepsFinishedBy(testCaseFinished)
181-
.stream()
182-
.map(TestStepFinished::getTestStepResult)
183-
.max(testStepResultComparator);
180+
return findTestCaseStartedBy(testCaseFinished)
181+
.flatMap(this::findMostSevereTestStepResultBy);
184182
}
185183

186184
public String findNameOf(GherkinDocument element, NamingStrategy namingStrategy) {
@@ -260,7 +258,7 @@ public Optional<Pickle> findPickleBy(TestCaseStarted testCaseStarted) {
260258

261259
public Optional<Pickle> findPickleBy(TestCaseFinished testCaseFinished) {
262260
requireNonNull(testCaseFinished);
263-
return findTestCaseBy(testCaseFinished)
261+
return findTestCaseStartedBy(testCaseFinished)
264262
.flatMap(this::findPickleBy);
265263
}
266264

@@ -340,13 +338,8 @@ public Optional<Duration> findTestCaseDurationBy(TestCaseStarted testCaseStarted
340338

341339
public Optional<Duration> findTestCaseDurationBy(TestCaseFinished testCaseFinished) {
342340
requireNonNull(testCaseFinished);
343-
Timestamp finished = testCaseFinished.getTimestamp();
344341
return findTestCaseStartedBy(testCaseFinished)
345-
.map(TestCaseStarted::getTimestamp)
346-
.map(started -> Duration.between(
347-
Convertor.toInstant(started),
348-
Convertor.toInstant(finished)
349-
));
342+
.flatMap(this::findTestCaseDurationBy);
350343
}
351344

352345
public Optional<TestCaseStarted> findTestCaseStartedBy(TestStepStarted testStepStarted) {
@@ -419,10 +412,9 @@ public List<TestStepFinished> findTestStepsFinishedBy(TestCaseStarted testCaseSt
419412

420413
public List<TestStepFinished> findTestStepsFinishedBy(TestCaseFinished testCaseFinished) {
421414
requireNonNull(testCaseFinished);
422-
List<TestStepFinished> testStepsFinished = testStepsFinishedByTestCaseStartedId.
423-
getOrDefault(testCaseFinished.getTestCaseStartedId(), emptyList());
424-
// Concurrency
425-
return new ArrayList<>(testStepsFinished);
415+
return findTestCaseStartedBy(testCaseFinished)
416+
.map(this::findTestStepsFinishedBy)
417+
.orElseGet(ArrayList::new);
426418
}
427419

428420
public List<Entry<TestStepFinished, TestStep>> findTestStepFinishedAndTestStepBy(TestCaseStarted testCaseStarted) {

0 commit comments

Comments
 (0)