Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Feature request: extractProperty() to use fields directly #128

Open
japgolly opened this Issue Nov 19, 2012 · 7 comments

Comments

Projects
None yet
4 participants

Any chance we could have extractProperty() fall back to supporting fields when a getter doesn't exist.

E.g.

class Animal {
    public String name;
}
Contributor

joel-costigliola commented Nov 19, 2012

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.

Owner

alexruiz commented Jan 10, 2013

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");
Contributor

joel-costigliola commented Apr 15, 2013

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?

Contributor

joel-costigliola commented Apr 28, 2013

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
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment