Skip to content

Commit

Permalink
Support of nested reporting of composite steps
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed May 21, 2019
1 parent bbebd36 commit 4fd1c46
Showing 1 changed file with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -258,7 +260,12 @@ public void beforeStep(String title) {
if (testState.currentStep == testState.currentStoryDescription) {
testState.currentStep = testState.currentScenario;
}
if (testState.currentStepStatus == StepStatus.STARTED) {
testState.parentSteps.push(testState.currentStep);
testState.moveToNextStep();
}
notifier.fireTestStarted(testState.currentStep);
testState.currentStepStatus = StepStatus.STARTED;
}
}

Expand All @@ -271,9 +278,8 @@ public void failed(String step, Throwable e) {
notifier.fireTestStarted(testState.currentStep);
}
notifier.fireTestFailure(new Failure(testState.currentStep, thrownException));
notifier.fireTestFinished(testState.currentStep);
testState.failedSteps.add(testState.currentStep);
prepareNextStep();
finishStep(testState);
}
}

Expand All @@ -282,9 +288,10 @@ public void successful(String step) {
TestState testState = this.testState.get();
if (!testState.isGivenStoryRunning()) {
if (testState.currentStep != null) {
notifier.fireTestFinished(testState.currentStep);
finishStep(testState);
} else {
prepareNextStep();
}
prepareNextStep();
}
}

Expand All @@ -305,6 +312,16 @@ private void prepareNextStep() {
}
}

private void finishStep(TestState testState) {
if (testState.currentStepStatus == StepStatus.FINISHED && !testState.parentSteps.isEmpty()) {
notifier.fireTestFinished(testState.parentSteps.poll());
} else {
notifier.fireTestFinished(testState.currentStep);
testState.currentStepStatus = StepStatus.FINISHED;
prepareNextStep();
}
}

@Override
public void pending(String step) {
TestState testState = this.testState.get();
Expand All @@ -316,12 +333,11 @@ public void pending(String step) {
// Pending step strategy says to fail so treat this step as
// having failed.
testState.failedSteps.add(testState.currentStep);
notifier.fireTestFinished(testState.currentStep);
finishStep(testState);
} else {
notifier.fireTestIgnored(testState.currentStep);
prepareNextStep();
}

prepareNextStep();
}
}

Expand All @@ -330,6 +346,7 @@ public void ignorable(String step) {
TestState testState = this.testState.get();
if (!testState.isGivenStoryRunning()) {
notifier.fireTestIgnored(testState.currentStep);
testState.currentStepStatus = StepStatus.FINISHED;
prepareNextStep();
}
}
Expand Down Expand Up @@ -359,6 +376,8 @@ public void usePendingStepStrategy(PendingStepStrategy pendingStepStrategy) {

private class TestState {
private Description currentStep;
private StepStatus currentStepStatus;
private final Deque<Description> parentSteps = new LinkedList<>();
private Iterator<Description> stepDescriptions;

private Description currentScenario;
Expand Down Expand Up @@ -393,4 +412,8 @@ private <T> T getNextOrNull(Iterator<T> iterator) {
return iterator.hasNext() ? iterator.next() : null;
}
}

private enum StepStatus {
STARTED, FINISHED
}
}

0 comments on commit 4fd1c46

Please sign in to comment.