fest-assert-2.x icon indicating copy to clipboard operation
fest-assert-2.x copied to clipboard

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

Open wires opened this issue 12 years ago • 4 comments

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.

wires avatar Nov 15 '12 18:11 wires

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).

joel-costigliola avatar Nov 17 '12 14:11 joel-costigliola

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?

wires avatar Nov 19 '12 16:11 wires

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

alexruiz avatar Jan 10 '13 15:01 alexruiz

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

wires avatar Feb 19 '13 16:02 wires