Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBEHAVE-1595 Enable step monitor for steps without parameters inside composite steps #69

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import com.thoughtworks.paranamer.Paranamer;

import org.apache.commons.lang3.StringUtils;
import org.jbehave.core.annotations.AfterScenario.Outcome;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Pending;
Expand Down Expand Up @@ -164,7 +163,9 @@ public boolean matches(String step, String previousNonAndStep) {
}
}
stepMonitor.stepMatchesType(step, previousNonAndStep, matchesType, stepType, method, stepsType);
boolean matchesPattern = stepMatcher.matcher(stripStartingWord(step)).matches();
String stepWithoutStartingWord = stripStartingWord(step);
boolean matchesPattern = stepWithoutStartingWord.equals(patternAsString)
|| stepMatcher.matcher(stepWithoutStartingWord).matches();
stepMonitor.stepMatchesPattern(step, matchesPattern, stepMatcher.pattern(), method, stepsType);
// must match both type and pattern
return matchesType && matchesPattern;
Expand Down Expand Up @@ -239,8 +240,7 @@ private StepCandidate findComposedCandidate(String composedStep, String previous
stepType = keywords.stepTypeFor(composedStep);
}
for (StepCandidate candidate : allCandidates) {
if (stepType == candidate.getStepType() && (StringUtils.endsWith(composedStep,
candidate.getPatternAsString()) || candidate.matches(composedStep, previousNonAndStep))) {
if (stepType == candidate.getStepType() && candidate.matches(composedStep, previousNonAndStep)) {
return candidate;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.jbehave.core.steps.StepCandidateBehaviour.candidateMatchingStep;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -34,6 +37,23 @@ void shouldMatchCompositesFromClassAndCreateComposedStepsUsingMatchedParameters(
shouldMatchCompositesAndCreateComposedStepsUsingMatchedParameters(compositeSteps);
}

@Test
void shouldMatchInnerCompositeStepWithoutParamsAndMonitorIt() {
StepMonitor monitor = mock(StepMonitor.class);
CompositeStepsWithParameterMissing steps = new CompositeStepsWithParameterMissing();
String outerCompositeStep = "Given I am logged in as USER";
String innerCompositeStep = "Given I log in";
List<StepCandidate> listCandidates = steps.listCandidates();

StepCandidate outerCompositeCandidate = candidateMatchingStep(listCandidates, outerCompositeStep);
StepCandidate innerCompositeCandidate = candidateMatchingStep(listCandidates, innerCompositeStep);
innerCompositeCandidate.useStepMonitor(monitor);

outerCompositeCandidate.addComposedSteps(new ArrayList<>(), outerCompositeStep, new HashMap<>(),
listCandidates);
verify(monitor).stepMatchesPattern(eq(innerCompositeStep), eq(true), any(), any(), any());
}

@Test
void shouldMatchCompositesFromFileAndCreateComposedStepsUsingMatchedParameters() {
CandidateSteps compositeSteps = new CompositeCandidateSteps(new MostUsefulConfiguration(),
Expand Down