Skip to content

Commit

Permalink
Reduce Throwable to Exception in JavaSnippet
Browse files Browse the repository at this point in the history
Tests are allowed to fail by throwing an(y) exception. As such #318
added `throws Throwable` to the JavaSnippet. Aside from being a bad
practice this results in unnecessary checkstyle warnings. As such the
generated snippet should not explicitly declare `Throwable`.

Reducing `Throwable` to `Exception` should be sufficient.

Fixes #1207
  • Loading branch information
mpkorstanje committed Aug 28, 2017
1 parent 0ea7b43 commit f998151
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion java/src/main/java/cucumber/runtime/java/JavaSnippet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protected String getArgType(Class<?> argType) {
@Override
public String template() {
return "@{0}(\"{1}\")\n" +
"public void {2}({3}) throws Throwable '{'\n" +
"public void {2}({3}) throws Exception '{'\n" +
" // {4}\n" +
"{5} throw new PendingException();\n" +
"'}'\n";
Expand Down
26 changes: 13 additions & 13 deletions java/src/test/java/cucumber/runtime/java/JavaSnippetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class JavaSnippetTest {
public void generatesPlainSnippet() {
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes in my \\\"([^\\\"]*)\\\" belly$\")\n" +
"public void i_have_cukes_in_my_belly(int arg1, String arg2) throws Throwable {\n" +
"public void i_have_cukes_in_my_belly(int arg1, String arg2) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -38,7 +38,7 @@ public void generatesPlainSnippet() {
public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Exception {
String expected = "" +
"@Given(\"^before (\\\\d+) after$\")\n" +
"public void before_after(int arg1) throws Throwable {\n" +
"public void before_after(int arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -50,7 +50,7 @@ public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Excep
public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars() {
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes in: my \\\"([^\\\"]*)\\\" red-belly!$\")\n" +
"public void i_have_cukes_in_my_red_belly(int arg1, String arg2) throws Throwable {\n" +
"public void i_have_cukes_in_my_red_belly(int arg1, String arg2) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -61,7 +61,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars(
public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParameter() {
String expected = "" +
"@Given(\"^the DI system receives a message saying \\\"([^\\\"]*)\\\"$\")\n" +
"public void the_DI_system_receives_a_message_saying(String arg1) throws Throwable {\n" +
"public void the_DI_system_receives_a_message_saying(String arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -72,7 +72,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParamet
public void generatesSnippetWithEscapedDollarSigns() {
String expected = "" +
"@Given(\"^I have \\\\$(\\\\d+)$\")\n" +
"public void i_have_$(int arg1) throws Throwable {\n" +
"public void i_have_$(int arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -83,7 +83,7 @@ public void generatesSnippetWithEscapedDollarSigns() {
public void generatesSnippetWithEscapedQuestionMarks() {
String expected = "" +
"@Given(\"^is there an error\\\\?:$\")\n" +
"public void is_there_an_error() throws Throwable {\n" +
"public void is_there_an_error() throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -94,7 +94,7 @@ public void generatesSnippetWithEscapedQuestionMarks() {
public void generatesSnippetWithLotsOfEscapes() {
String expected = "" +
"@Given(\"^\\\\^\\\\(\\\\[a-z\\\\]\\\\*\\\\)\\\\?\\\\.\\\\+\\\\$$\")\n" +
"public void a_z_$() throws Throwable {\n" +
"public void a_z_$() throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -105,7 +105,7 @@ public void generatesSnippetWithLotsOfEscapes() {
public void generatesSnippetWithEscapedParentheses() {
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes \\\\(maybe more\\\\)$\")\n" +
"public void i_have_cukes_maybe_more(int arg1) throws Throwable {\n" +
"public void i_have_cukes_maybe_more(int arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -116,7 +116,7 @@ public void generatesSnippetWithEscapedParentheses() {
public void generatesSnippetWithEscapedBrackets() {
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes \\\\[maybe more\\\\]$\")\n" +
"public void i_have_cukes_maybe_more(int arg1) throws Throwable {\n" +
"public void i_have_cukes_maybe_more(int arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -127,7 +127,7 @@ public void generatesSnippetWithEscapedBrackets() {
public void generatesSnippetWithDocString() {
String expected = "" +
"@Given(\"^I have:$\")\n" +
"public void i_have(String arg1) throws Throwable {\n" +
"public void i_have(String arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand All @@ -139,7 +139,7 @@ public void generatesSnippetWithDocString() {
public void recognisesWordWithNumbers() {
String expected = "" +
"@Given(\"^Then it responds ([^\\\"]*)$\")\n" +
"public void Then_it_responds(String arg1) throws Throwable {\n" +
"public void Then_it_responds(String arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
"}\n";
assertEquals(expected, snippetFor("Then it responds UTF-8"));
Expand All @@ -149,7 +149,7 @@ public void recognisesWordWithNumbers() {
public void generatesSnippetWithDataTable() {
String expected = "" +
"@Given(\"^I have:$\")\n" +
"public void i_have(DataTable arg1) throws Throwable {\n" +
"public void i_have(DataTable arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" // For automatic transformation, change DataTable to one of\n" +
" // List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.\n" +
Expand All @@ -164,7 +164,7 @@ public void generatesSnippetWithDataTable() {
public void generateSnippetWithOutlineParam() {
String expected = "" +
"@Given(\"^Then it responds (.*)$\")\n" +
"public void then_it_responds(String arg1) throws Throwable {\n" +
"public void then_it_responds(String arg1) throws Exception {\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
Expand Down

0 comments on commit f998151

Please sign in to comment.