cucumber-jvm: Enum conversion not working: IllegalArgumentException: argument type mismatch for step argument

Summary

Regression between 3.0.2 and 2.4.0 breaks converting enum parameters of steps

Expected Behavior

After reverting to 2.4.0:

> Task :cucumber
Feature: Calculations

  Scenario: Divide              # src/test/resources/calculation.feature:2
Doing Division
    When Division is calculated # CalculationStepdefs.splitInfoPfShiftIsSelected(CalculationType)

1 Scenarios (1 passed)
1 Steps (1 passed)

Current Behavior

> Task :cucumber FAILED
Feature: Calculations

  Scenario: Divide              # src/test/resources/calculation.feature:2
    When Division is calculated # CalculationStepdefs.splitInfoPfShiftIsSelected(CalculationType)
      cucumber.runtime.CucumberException: Failed to invoke com.example.CalculationStepdefs.splitInfoPfShiftIsSelected(CalculationType) in file:/home/piotr-kubowicz/temp/bugs/cucumber3/build/classes/java/test/, caused by java.lang.IllegalArgumentException: argument type mismatch                                                                                                                            
        at cucumber.runtime.Utils$1.call(Utils.java:29)                                                                               
        at cucumber.runtime.Timeout.timeout(Timeout.java:16)                                                                          
        at cucumber.runtime.Utils.invoke(Utils.java:20)                                                                               
        at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)                                               
        at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)                                      
        at cucumber.runner.TestStep.executeStep(TestStep.java:55)                                                                     
        at cucumber.runner.TestStep.run(TestStep.java:42)                                                                             
        at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:53)                                                         
        at cucumber.runner.TestCase.run(TestCase.java:47)                                                                             
        at cucumber.runner.Runner.runPickle(Runner.java:44)                                                                           
        at cucumber.runtime.Runtime.runFeature(Runtime.java:120)                                                                      
        at cucumber.runtime.Runtime.run(Runtime.java:106)                                                                             
        at cucumber.api.cli.Main.run(Main.java:35)                                                                                    
        at cucumber.api.cli.Main.main(Main.java:18)                                                                                   
Caused by: java.lang.IllegalArgumentException: argument type mismatch                                                                 
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                                              
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                      
        at java.lang.reflect.Method.invoke(Method.java:498)                                                                           
        at cucumber.runtime.Utils$1.call(Utils.java:26)                                                                               
        ... 13 more                                                                                                                   

Possible Solution

Steps to Reproduce (for bugs)

src/test/resources/calculation.feature

Feature: Calculations
  Scenario: Divide
    When Division is calculated
package com.example;

import cucumber.api.java.en.When;

public class CalculationStepdefs {

    @When("([\\S]+) is calculated")
    public void splitInfoPfShiftIsSelected(CalculationType calculationType) {
        System.out.println("Doing " + calculationType);
    }
}
package com.example;

public enum CalculationType {
    Multiplication,
    Division
}

build.gradle

plugins { id 'java-library' }

def cucumberVersion = '3.0.2'
dependencies {
    testImplementation "io.cucumber:cucumber-java8:$cucumberVersion"
}

repositories {
    jcenter()
}

task cucumber() {
    dependsOn testClasses
    doLast {
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = configurations.testRuntimeClasspath + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'com.example', 'src/test/resources']
        }
    }
}
build.dependsOn cucumber

Context & Motivation

This blocks me from upgrading to 3.0.2.

Your Environment

Java™ SE Runtime Environment (build 1.8.0_172-b11) Ubuntu 17.10

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (17 by maintainers)

Commits related to this issue

Most upvoted comments

The commit with the fix has a descendant tagged with a release version. But it was the release of datatable not cucumber expressions. Hence the confusion.

@mlvandijk Thanks for the invite. Signed up.

@aslakhellesoy This worked fine (without any custom conversion code) in 2.4.0 so I consider this a regression bug or at least a breaking change. Change log for release 3 did not mention anything similar.