Open japgolly opened 11 years ago
I think we could :)
That's great! This will be good in conjunction with Android testing because with older versions of Android, the JVM or compiler doesn't inline getters (or something to that effect) so using fields directly rather than getter methods improves actually performance.
You can use FEST-Reflect to extract the field. No need to duplicate that in FEST-Assert. The question would be if FEST-Reflect works with Android. If not, we can fix FEST-Reflect.
I don't think it's an "so" easy fix, because the instrospection used by the extractProperty (see PropertySupport#propertyValue) is based on PropertyDescriptor, and according to the javadoc, it "describes one property that a Java Bean exports via a pair of accessor methods".
by extension to this issue, it can be usefull to have an extract method, and not only for properties.
class Basket {
public BigDecimal price() {
return a_computed_price;
}
}
and the associated test can looks like :
assertThat(extract("price").from(baskets)).containsOnly("12.65", "42.00", "66.60");
For your information, this issue has been fixed in AssertJ a fork of Fest Assert 2.0M10.
The syntax is a little different though :
// "name" need to be either a property or a public field of TolkienCharacter class.
assertThat(fellowshipOfTheRing).extracting("name")
.contains("Boromir", "Gandalf", "Frodo", "Legolas")
.doesNotContain("Sauron", "Elrond");
It also supports extracting several fields/properties :
// tuple comes from : import static org.assertj.core.api.Assertions.tuple;
assertThat(fellowshipOfTheRing).extracting("name", "age", "race.name")
.contains(tuple("Boromir", 37, "Man"),
tuple("Sam", 38, "Hobbit"),
tuple("Legolas", 1000, "Elf"));
Nice. So that means that this will be in the next version of Fest Assert, like 2.0M11?
It is available in AssertJhttps://github.com/joel-costigliola/assertj-core#readme, but I can't tell if it will be in Fest Assert, only Alex can answer that.
Regards,
Joel
On Sun, Apr 28, 2013 at 2:27 AM, David Barri notifications@github.comwrote:
Nice. So that means that this will be in the next version of Fest Assert, like 2.0M11?
— Reply to this email directly or view it on GitHubhttps://github.com/alexruiz/fest-assert-2.x/issues/128#issuecomment-17125946 .
Any chance we could have extractProperty() fall back to supporting fields when a getter doesn't exist.
E.g.