Package com.tngtech.jgiven.annotation
Annotation Interface NamedFormats
Allow to define a set of identifiable formats (
One usage of such set is to define formats for (part or all) fields of a bean. In this case, every
This set may then be used to define formats for fields of a
NamedFormat
).One usage of such set is to define formats for (part or all) fields of a bean. In this case, every
NamedFormat.name()
in this set should match
a field of this bean.This set may then be used to define formats for fields of a
Table
annotated parameter of a step method.
Example
Some POJO
class CoffeeWithPrice {
String name;
double price_in_EUR;
Date lastPriceDate;
CoffeeWithPrice(String name, double priceInEur, Date lastPriceDate) {
this.name = name;
this.price_in_EUR = priceInEur;
this.lastPriceDate = lastPriceDate;
}
}
The Step Method
@NamedFormats( {
@NamedFormat( name = "lastPriceDate", format = @Format(value = DateFormatter.class, args = "dd/MM/yyyy") )
} )
@Retention( RetentionPolicy.RUNTIME )
public static @interface CoffeeWithPriceFieldFormatSet {}
public SELF the_prices_of_the_coffees_are( @Table(fieldsFormatSetAnnotation=CoffeeWithPriceFieldFormatSet.class) CoffeeWithPrice... prices ) {
...
}
Here we have explicitly set a date formatter (format dd/MM/yyyy
)
for field lastPriceDate
in order to get an easy readable date
(in replacement of the default Date.toString()
representation).
Invocation of the step method
given().the_prices_of_the_coffees_are(
new CoffeeWithPrice("Espresso", 2.0, new Date()),
new CoffeeWithPrice("Cappuccino", 2.5, new Date()));
Text Report
Given the prices of the coffees are
| name | price in EUR | lastPriceDate |
+------------+--------------+---------------+
| Espresso | 2.0 | 18/01/2017 |
| Cappuccino | 2.5 | 18/01/2017 |
- Since:
- 0.15.0
-
Optional Element Summary
-
Element Details
-
value
NamedFormat[] valueArray ofNamedFormat
- Default:
- {}
-