Using @Transform in Java 8 version of Cucumber

1,093 views
Skip to first unread message

ralp...@gmail.com

unread,
Nov 29, 2016, 7:21:44 PM11/29/16
to Cukes
Hi all,

as someone who is very new to Cucumber, I decided to work myself into the topic by using the 'Cucumber for Java' book.
The book is not up to date for using the Java 8 verison of Cucumber, so I am just trying out.
I specifically have a problem with the @Transform annotation which does not seem to be recognized correctly.

Using the following step definitions:

public final class Steps implements En
{
  public Steps()
  {
    Given( "^I have deposited \\$(\\d+\\.\\d+) in my account$", (
      @Transform( MoneyTransformer.class ) Money amount ) ->
    {
      Account myAccount = new Account();
      myAccount.deposit( amount );
      assertEquals( "Incorrect account balance - ", amount, myAccount.getBalance() );
    } );

    // ...
  }
}


and the Transformer:

public final class MoneyTransformer extends Transformer< Money >
{
  @Override
  public Money transform(
    String amount )
  {
    String[] numbers = amount.split( "\\." );
    return new Money( Integer.valueOf( numbers[0] ), Integer.valueOf( numbers[1] ) );
  }
}

It seem that the transformer is never being called:

...
Given I have deposited $100.00 in my account(Scenario: Successful withdrawal from an account in credit)  Time elapsed: 0.006 sec  <<< ERROR!
cucumber.runtime.CucumberException:
Don't know how to convert "100.00" into nicebank.Money.
Try writing your own converter:

@cucumber.deps.com.thoughtworks.xstream.annotations.XStreamConverter(MoneyConverter.class)
public class Money {}
...

Is that a known issue?
Am I using it wrong?
Is there an example of how parameter transformation should be done in Java 8?

Thanks for the help,
Ralph

Reply all
Reply to author
Forward
0 new messages