Skip to content
Open
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 @@ -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)) {
Expand Down Expand Up @@ -137,6 +137,17 @@ private List<String> extractPatternVariants(List<String> 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> T getValue(IMemberValuePair[] memberValuePairs, String key) {
for (IMemberValuePair kv : memberValuePairs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -263,19 +276,23 @@ public void givenNoAnnotation() {
}

public void givenAnnotation(String elementName, String value) {
givenAnnotation(elementName, value, null);
final List<IMemberValuePair> attributes = new ArrayList<IMemberValuePair>();

attributes.add(getMemberValuePair("value", value));

givenAnnotation(elementName, getMemberValuePair("value", value));
}

public void givenAnnotation(String elementName, String value,
Integer priority) {
Object priority) {
final List<IMemberValuePair> attributes = new ArrayList<IMemberValuePair>();

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) {
Expand All @@ -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<IMemberValuePair> attributes) {
final IAnnotation annotation = Mockito.mock(IAnnotation.class);
Expand Down