Details
-
Type:
New Feature
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: FEST-Assert 1.2
-
Fix Version/s: FEST-Assert 1.3
-
Component/s: Assert
-
Labels:None
-
Number of attachments :
Description
Sometimes you need to control a collection result, but checking all the elements is overkill so you only want to control a specific property on each collection elements.
Example :
Imagine you query a system to find persons, a Person has a name, an age and a unique id.
To check a collection result of Person, it's enough to control that the ids of the returned persons are the expected ones.
The idea is to extract the values of the property on each elements and make some assertion on the extracted values.
// team is a Collection of Person
assertThat(team).onProperty("id").contains(12, 55, 4);
using reflection, onProperty("id") extracts the value of property "id" of each team elements, it returns a new CollectionAssert whose "actual" attribute is composed of ids of team Persons, you can apply then all available Collection assertions ...
It would also be nice to access nested properties with '.' notation, something like :
assertThat(team).onProperty("adress.street").contains("Sesame street", "Boulevard Saint Germain", "Rue de Tolbiac");