Skip to content

Commit

Permalink
Cucumber for Java. Checking .isAnnotationType before annotation usage…
Browse files Browse the repository at this point in the history
… search
  • Loading branch information
avokin committed Jul 27, 2015
1 parent 92c4980 commit cff069f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
Expand Up @@ -105,9 +105,11 @@ public List<AbstractStepDefinition> loadStepsFor(@Nullable PsiFile featureFile,
final List<AbstractStepDefinition> result = new ArrayList<AbstractStepDefinition>();
final Query<PsiClass> stepDefAnnotations = AnnotatedElementsSearch.searchPsiClasses(stepDefAnnotationClass, dependenciesScope);
for (PsiClass annotationClass : stepDefAnnotations) {
final Query<PsiMethod> javaStepDefinitions = AnnotatedElementsSearch.searchPsiMethods(annotationClass, dependenciesScope);
for (PsiMethod stepDefMethod : javaStepDefinitions) {
result.add(new JavaStepDefinition(stepDefMethod));
if (annotationClass.isAnnotationType()) {
final Query<PsiMethod> javaStepDefinitions = AnnotatedElementsSearch.searchPsiMethods(annotationClass, dependenciesScope);
for (PsiMethod stepDefMethod : javaStepDefinitions) {
result.add(new JavaStepDefinition(stepDefMethod));
}
}
}
return result;
Expand Down
Expand Up @@ -20,4 +20,8 @@ public void testResolveToStepWithTimeout() throws Exception {
public void testStrictStartAndEndRegexOptions() throws Exception {
doTest("strictStartAndEndRegexOptions", "I have sh<caret>ort step", "I_have_short_step");
}

public void testStepDefContainerMarkedWithStepDefAnnotation() throws Exception {
doTest("stepDefContainerMarkedWithStepDefAnnotation", "the follo<caret>wing grocerie", "the_following_groceries");
}
}
@@ -0,0 +1,40 @@
package cucumber.examples.java.calculator;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

import cucumber.runtime.java.StepDefAnnotation;

import java.util.List;

import static org.junit.Assert.assertEquals;

@StepDefAnnotation
public class ShoppingStepdefs {
private RpnCalculator calc = new RpnCalculator();

@Given("^the following groceries:$")
public void the_following_groceries(List<Grocery> groceries) {
for (Grocery grocery : groceries) {
calc.push(grocery.price);
calc.push("+");
}
}

@When("^I pay (\\d+)$")
public void i_pay(int amount) {
calc.push(amount);
calc.push("-");
}

@Then("^my change should be (\\d+)$")
public void my_change_should_be_(int change) {
assertEquals(-calc.value().intValue(), change);
}

public static class Grocery {
public String name;
public int price;
}
}
@@ -0,0 +1,10 @@
Feature: Shopping

Scenario: Give correct change
Given the following groceries:
| name | price |
| milk | 9 |
| bread | 7 |
| soap | 5 |
When I pay 25
Then my change should be 4

0 comments on commit cff069f

Please sign in to comment.