mardi 18 octobre 2016

How to assert that all elements in the collection have a property which is equal among them?

I have a collection of Objects (let's say Cars). Each car has a property of type Company which can be identified by its id.

Now I want to assert that all cars in my collection belong to the same company, i.e. each car's company is equal to all the others.

Note, that in my test I do not know the value of the company ID in advance. I don't care about the value, the only important thing it that is is the same among all cars.

I would imagine something like:

assertThat(allCars, Matchers.equalAmongAll(hasProperty("company", hasProperty("id"))));

Aucun commentaire:

Enregistrer un commentaire