2012-01-11 82 views
0

在jbehave 3个的例子,我可以看到参数为“双”,所以我试图用其他类型除了字符串,但是当我尝试添加一个布尔参数这样Jbehave布尔命名参数

public void theUserShouldBeRedirectedToHomePage(@Named("should?") boolean should) 

我得到的参数类型错误:

java.lang.IllegalArgumentException: argument type mismatch 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.jbehave.scenario.steps.CandidateStep$1.perform(CandidateStep.java:225) 
    at org.jbehave.scenario.ScenarioRunner$FineSoFar.run(ScenarioRunner.java:112) 

(也,我使用的是2.3版本,而不是jbehave 3)

是它与我的jbehave版中的问题?这是使用布尔参数的正确方法?

回答

0

如果您将通过此参数反正其他方法,有时更容易这样做:

公共无效theUserShouldBeRedirectedToHomePage(@Named( “应该?”)字符串应该){

myNextMethod(Boolean.valueOf(should)); }

0

Jbehave版本3与布尔运行良好。以下面的例子,它在我的代码中工作得很好。

@Then("I verify the response has _success as $_success and _warning as $_warning and _info as $_info and _messages as $_messages") 
      public void pidOrPidColorDeleteResponse(
        @Named("_success") Boolean _success, 
        @Named("_warning") Boolean _warning, 
        @Named("_info") Boolean _info, 
        @Named("_messages") List<String> _messages) { 

      } 

随着Jbehave版本2需要检查。