alexruiz / fest-assert-2.x

FEST Fluent Assertions 2.x
http://fest.easytesting.org
Apache License 2.0
402 stars 69 forks source link

Feature request: support for name() instead of getName() style setters for extractProperty #125

Open wires opened 11 years ago

wires commented 11 years ago

Your nice library only supports properties of the form getX setX, so this doesn't work

public class Foo {
   final protected String bar;
   public Foo(String bar) { this.bar = bar; }
   public String bar() { return bar }
}

final ArrayList<Foo> fooList = newArrayList(new Foo("a"),
                         new Foo("b"), new Foo("c"));

assertThat(extractProperty("bar", String.class)
      .from(fooList)).containsOnly("a","b", "c");

It would be very nice (for me :^) ) if we could test code with methods named like that?

It is also not possible to test non public methods or private classes. In principle this shouldn't be a problem, reflection APIs can call private members.

joel-costigliola commented 11 years ago

I would agree on getting properties with non java bean properties accessors but I'm not convinced breaking encapsulation by calling private methods is right (others might have another opinion).

wires commented 11 years ago

Well maybe "private" doesn't make much sense, but for instance I very often give "internal APIs" methods with "package" visibility which are then exposed only to the internal classes building on that API. To me it makes sense to the this internal API.

What do you think?

alexruiz commented 11 years ago

Please use FEST-Reflect. It can access fields, properties, methods and more, via Reflection. It provides a nice fluent interface too.

wires commented 11 years ago

@alexruiz thanks! that is good enough for me, feel free to close the issue