Skip to content

Commit 361f39c

Browse files
committed
Bring back the Java8StepDefinitionTest in the java module.
The Java8StepDefinitionTest class in the java module tests the "genericInterface instanceof ParameterizedType" branch of Java8StepDefinition.getParameterInfos.
1 parent 1bb6340 commit 361f39c

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package cucumber.runtime.java;
2+
3+
import cucumber.api.java8.StepdefBody;
4+
import cucumber.runtime.CucumberException;
5+
import org.junit.Test;
6+
7+
import java.util.List;
8+
import java.util.regex.Pattern;
9+
10+
import static org.junit.Assert.assertEquals;
11+
import static org.junit.Assert.fail;
12+
13+
public class Java8StepDefinitionTest {
14+
15+
@Test
16+
public void should_calculate_parameters_count_from_body_with_one_param() throws Exception {
17+
Java8StepDefinition java8StepDefinition = new Java8StepDefinition(Pattern.compile("^I have (\\d) some step (.*)$"), 0, oneParamStep(), null);
18+
assertEquals(new Integer(1), java8StepDefinition.getParameterCount());
19+
}
20+
21+
@Test
22+
public void should_calculate_parameters_count_from_body_with_two_params() throws Exception {
23+
Java8StepDefinition java8StepDefinition = new Java8StepDefinition(Pattern.compile("^I have some step $"), 0, twoParamStep(), null);
24+
assertEquals(new Integer(2), java8StepDefinition.getParameterCount());
25+
}
26+
27+
@Test
28+
public void should_fail_for_param_with_non_generic_list() throws Exception {
29+
try {
30+
new Java8StepDefinition(Pattern.compile("^I have (\\d) some step (.*)$"), 0, nonGenericListStep(), null);
31+
fail();
32+
} catch (CucumberException expected) {
33+
assertEquals("Can't use java.util.List in lambda step definition. Declare a DataTable argument instead and convert manually with asList/asLists/asMap/asMaps", expected.getMessage());
34+
}
35+
}
36+
37+
@Test
38+
public void should_pass_for_param_with_generic_list() throws Exception {
39+
Java8StepDefinition java8StepDefinition = new Java8StepDefinition(Pattern.compile("^I have (\\d) some step (.*)$"), 0, genericListStep(), null);
40+
assertEquals(new Integer(1), java8StepDefinition.getParameterCount());
41+
}
42+
43+
private StepdefBody oneParamStep() {
44+
return new StepdefBody.A1<String>() {
45+
@Override
46+
public void accept(String p1) {
47+
}
48+
};
49+
}
50+
51+
private StepdefBody twoParamStep() {
52+
return new StepdefBody.A2<String, String>() {
53+
@Override
54+
public void accept(String p1, String p2) {
55+
}
56+
};
57+
}
58+
59+
private StepdefBody genericListStep() {
60+
return new StepdefBody.A1<List<String>>() {
61+
@Override
62+
public void accept(List<String> p1) {
63+
throw new UnsupportedOperationException();
64+
}
65+
};
66+
}
67+
68+
private StepdefBody nonGenericListStep() {
69+
return new StepdefBody.A1<List>() {
70+
@Override
71+
public void accept(List p1) {
72+
throw new UnsupportedOperationException();
73+
}
74+
};
75+
}
76+
}

0 commit comments

Comments
 (0)