Skip to content

Commit d20848a

Browse files
Christian Hujermpkorstanje
Christian Hujer
authored andcommitted
[Java8] Allow lambda steps to throw checked Exceptions
Related issues: - #1001
1 parent 177cc3a commit d20848a

File tree

7 files changed

+32
-13
lines changed

7 files changed

+32
-13
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [2.0.0-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.5...master) (In Git)
22

3+
* [Java8] Allow lambda steps to throw checked Exceptions ([#1001](https://github.com/cucumber/cucumber-jvm/issues/1001), [#1110](https://github.com/cucumber/cucumber-jvm/pull/1110) Christian Hujer)
34
* [JUnit] Add `--[no-]step-notifications` option to JunitOptions ([#1135](https://github.com/cucumber/cucumber-jvm/pull/1135), [#263](https://github.com/cucumber/cucumber-jvm/issues/263), [#577](https://github.com/cucumber/cucumber-jvm/issues/577) mpkorstanje)
45
* [JUnit] Use deterministic unique ids in Descriptions ([#1134](https://github.com/cucumber/cucumber-jvm/pull/1134), [#1120](https://github.com/cucumber/cucumber-jvm/issues/1120) mpkorstanje)
56
* [All] Support [Tag Expressions](https://github.com/cucumber/cucumber/tree/master/tag-expressions) (part of [#1035](https://github.com/cucumber/cucumber-jvm/pull/1035) Björn Rasmusson)

java/src/main/java/cucumber/api/java8/HookBody.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import cucumber.api.Scenario;
44

55
public interface HookBody {
6-
void accept(Scenario scenario);
6+
void accept(Scenario scenario) throws Throwable;
77
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package cucumber.api.java8;
22

33
public interface HookNoArgsBody {
4-
void accept();
4+
void accept() throws Throwable;
55
}

java/src/main/java/cucumber/api/java8/StepdefBody.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,42 @@
22

33
public interface StepdefBody {
44
public static interface A0 extends StepdefBody {
5-
void accept();
5+
void accept() throws Throwable;
66
}
77

88
public static interface A1<T1> extends StepdefBody {
9-
void accept(T1 p1);
9+
void accept(T1 p1) throws Throwable;
1010
}
1111

1212
public static interface A2<T1, T2> extends StepdefBody {
13-
void accept(T1 p1, T2 p2);
13+
void accept(T1 p1, T2 p2) throws Throwable;
1414
}
1515

1616
public static interface A3<T1, T2, T3> extends StepdefBody {
17-
void accept(T1 p1, T2 p2, T3 p3);
17+
void accept(T1 p1, T2 p2, T3 p3) throws Throwable;
1818
}
1919

2020
public static interface A4<T1, T2, T3, T4> extends StepdefBody {
21-
void accept(T1 p1, T2 p2, T3 p3, T4 p4);
21+
void accept(T1 p1, T2 p2, T3 p3, T4 p4) throws Throwable;
2222
}
2323

2424
public static interface A5<T1, T2, T3, T4, T5> extends StepdefBody {
25-
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5);
25+
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) throws Throwable;
2626
}
2727

2828
public static interface A6<T1, T2, T3, T4, T5, T6> extends StepdefBody {
29-
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6);
29+
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6) throws Throwable;
3030
}
3131

3232
public static interface A7<T1, T2, T3, T4, T5, T6, T7> extends StepdefBody {
33-
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7);
33+
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7) throws Throwable;
3434
}
3535

3636
public static interface A8<T1, T2, T3, T4, T5, T6, T7, T8> extends StepdefBody {
37-
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8);
37+
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8) throws Throwable;
3838
}
3939

4040
public static interface A9<T1, T2, T3, T4, T5, T6, T7, T8, T9> extends StepdefBody {
41-
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8, T9 p9);
41+
void accept(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8, T9 p9) throws Throwable;
4242
}
4343
}

java/src/test/java/cucumber/runtime/java/java8test/AnonInnerClassStepdefs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class AnonInnerClassStepdefs implements GlueBase {
1111
public AnonInnerClassStepdefs() {
1212
JavaBackend.INSTANCE.get().addStepDefinition("^I have (\\d+) cukes in my (.*)", 0, new StepdefBody.A2<Integer, String>() {
1313
@Override
14-
public void accept(Integer cukes, String what) {
14+
public void accept(Integer cukes, String what) throws Throwable {
1515
assertEquals(42, cukes.intValue());
1616
assertEquals("belly", what);
1717
}

java8/src/test/java/cucumber/runtime/java8/test/LambdaStepdefs.java

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public LambdaStepdefs() {
1818
lastInstance = this;
1919
});
2020

21+
Before(this::methodThatDeclaresException);
22+
23+
Before(this::hookWithArgs);
24+
25+
2126
Given("^this data table:$", (DataTable peopleTable) -> {
2227
List<Person> people = peopleTable.asList(Person.class);
2328
assertEquals("Hellesøy", people.get(0).last);
@@ -49,8 +54,18 @@ public LambdaStepdefs() {
4954
assertEquals("three", c);
5055
assertEquals((Integer) 4, d);
5156
});
57+
58+
Given("^A lambda that declares an exception$", this::methodThatDeclaresException);
59+
}
60+
61+
private void methodThatDeclaresException() throws Throwable {
5262
}
5363

64+
65+
private void hookWithArgs(Scenario scenario) throws Throwable {
66+
}
67+
68+
5469
public static class Person {
5570
String first;
5671
String last;

java8/src/test/resources/cucumber/runtime/java8/test/java8.feature

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ Feature: Java8
1919
| first | last |
2020
| Aslak | Hellesøy |
2121
| Donald | Duck |
22+
23+
Scenario: using lambdas with exceptions
24+
Given A lambda that declares an exception

0 commit comments

Comments
 (0)