Skip to content

Commit

Permalink
JBEHAVE-1595 Fix monitoring of steps without parameters inside compos…
Browse files Browse the repository at this point in the history
…ite steps

Co-authored-by: Andrei Kliuchnikau <andrei_kliuchnikau@epam.com>
  • Loading branch information
draker94 and Andrei Kliuchnikau committed Dec 29, 2023
1 parent 322ce38 commit b39ecbc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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
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

0 comments on commit b39ecbc

Please sign in to comment.