diff --git a/org.jbehave.eclipse/src/org/jbehave/eclipse/editor/step/MethodToStepCandidateReducer.java b/org.jbehave.eclipse/src/org/jbehave/eclipse/editor/step/MethodToStepCandidateReducer.java index b3eb46d..ae65ac8 100644 --- a/org.jbehave.eclipse/src/org/jbehave/eclipse/editor/step/MethodToStepCandidateReducer.java +++ b/org.jbehave.eclipse/src/org/jbehave/eclipse/editor/step/MethodToStepCandidateReducer.java @@ -82,7 +82,7 @@ public void reduce(final IMethod method, if (basicStep) { String stepPattern = getValue(annotationAttributes, "value"); - priority = getValue(annotationAttributes, "priority"); + priority = getPriority(annotationAttributes); patterns = extractPatternVariants(patterns, stepPattern); } else if (Aliases.class.getName().equals(fullQualifiedName)) { @@ -137,6 +137,17 @@ private List extractPatternVariants(List patterns, return patterns; } + private Integer getPriority(IMemberValuePair[] annotationAttributes) { + try { + return getValue(annotationAttributes, "priority"); + } + catch (ClassCastException ex) { + // The priority was a constant or expression. + // TODO it should be possible to get the value of a constant, at least + return null; + } + } + @SuppressWarnings("unchecked") public static T getValue(IMemberValuePair[] memberValuePairs, String key) { for (IMemberValuePair kv : memberValuePairs) { diff --git a/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/step/MethodToStepCandidateReducerTest.java b/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/step/MethodToStepCandidateReducerTest.java index 9c14d3d..1b809e9 100644 --- a/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/step/MethodToStepCandidateReducerTest.java +++ b/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/step/MethodToStepCandidateReducerTest.java @@ -15,6 +15,8 @@ import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; +import static java.util.Arrays.asList; + @RunWith(MockitoJUnitRunner.class) public class MethodToStepCandidateReducerTest { @@ -82,6 +84,17 @@ public void testListenerInformedWithPriority_WhenProvided() "a priority", 1); } + @Test + public void testListenerNotInformedWithPriority_WhenNotRecognized() + throws JavaModelException { + givenAnnotation("Given", "a priority", "PRIORITY"); + + whenTheMethodWasProcessed(); + + thenListenerShouldHaveBeenInformedOnlyWith(StepType.GIVEN, + "a priority", null); + } + @Test public void testListenerInformedWithFirst_WhenTwoAnnotations() throws JavaModelException { @@ -263,19 +276,23 @@ public void givenNoAnnotation() { } public void givenAnnotation(String elementName, String value) { - givenAnnotation(elementName, value, null); + final List attributes = new ArrayList(); + + attributes.add(getMemberValuePair("value", value)); + + givenAnnotation(elementName, getMemberValuePair("value", value)); } public void givenAnnotation(String elementName, String value, - Integer priority) { + Object priority) { final List attributes = new ArrayList(); attributes.add(getMemberValuePair("value", value)); - if (priority != null) { - attributes.add(getMemberValuePair("priority", priority)); - } + attributes.add(getMemberValuePair("priority", priority)); - givenAnnotation(elementName, attributes); + givenAnnotation(elementName, + getMemberValuePair("value", value), + getMemberValuePair("priority", priority)); } public void givenAliases(String[] values) { @@ -285,6 +302,11 @@ public void givenAliases(String[] values) { givenAnnotation("Aliases", attributes); } + private void givenAnnotation(String elementName, + IMemberValuePair... attributes) { + givenAnnotation(elementName, asList(attributes)); + } + private void givenAnnotation(String elementName, List attributes) { final IAnnotation annotation = Mockito.mock(IAnnotation.class);