Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
1.6
-
None
-
None
-
Groovy 1.5.7 and 1.6.0
Description
Groovy in Action listing 7.23 no longer works, because when a gpath property refers to a list, this list is no longer flattenend.
So the original listing:
class Invoice { List items Date date } class LineItem { Product product int count int total() { return product.dollar * count } } class Product { String name def dollar } def ulcDate = new Date(107,0,1) def ulc = new Product(dollar:1499, name:'ULC') def ve = new Product(dollar:499, name:'Visual Editor') def invoices = [ new Invoice(date:ulcDate, items: [ new LineItem(count:5, product:ulc), new LineItem(count:1, product:ve) ]), new Invoice(date:[107,1,2], items: [ new LineItem(count:4, product:ve) ]) ] assert [5*1499, 499, 4*499] == invoices.items*.total() assert ['ULC'] == invoices.items.grep{it.total() > 7000}.product.name def searchDates = invoices.grep{ it.items.any{it.product == ulc} }.date*.toString() assert [ulcDate.toString()] == searchDates
would need to change its assertions to
assert [5*1499, 499, 4*499] == invoices.items.flatten()*.total() assert ['ULC'] == invoices.items.flatten().grep{it.total() > 7000}.product.name def searchDates = invoices.grep{ it.items.flatten().any{it.product == ulc} }.date*.toString()