cucumber
Annotation Type DateFormat


@Retention(value=RUNTIME)
@Target(value=PARAMETER)
public @interface DateFormat

This annotation can be specified on step definition method parameters to give Cucumber a hint about how to transform a String to a Date or a Calendar. For example, if you have the following Gherkin step with a ISO 8601 date:

 Given the date is 2012-03-01T06:54:12
 

Then the following Java Step Definition would convert that into a Date:

 @Given("^the date is (\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})$")
 public void the_date_is(@DateFormat("yyyy-MM-dd'T'HH:mm:ss") Date date) {
     this.date = date;
 }
 

Or a Calendar:

 @Given("^the date is (\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})$")
 public void the_date_is(@DateFormat("yyyy-MM-dd'T'HH:mm:ss") Calendar cal) {
     this.cal = cal;
 }
 

This annotation also works for data tables that are transformed to a list of beans with Date or Calendar fields.


Required Element Summary
 String value
           
 

Element Detail

value

public abstract String value


Copyright © 2012. All Rights Reserved.