Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldMatcher is unable to compare private field values #1

Open
ZeroOne3010 opened this issue Nov 28, 2018 · 1 comment
Open

FieldMatcher is unable to compare private field values #1

ZeroOne3010 opened this issue Nov 28, 2018 · 1 comment
Assignees

Comments

@ZeroOne3010
Copy link

The FieldMatcher, which is supposed to work like hasField(String fieldName, Matcher<?> valueMatcher) when comparing field values, is unable to do the comparing if the field is private: it internally gets an exception like java.lang.IllegalAccessException: Class com.nitorcreations.matchers.FieldMatcher can not access a member of class foo.bar.Baz with modifiers "private".

The FieldMatcher is able to find the private fields and assert their existence just fine when used without the value matcher. However, I need to assert the value too. Alternatively, I would need a way to assert the return value of the getter of the private field.

My use case is that I've got a collection of entities where only two fields are interesting and the rest should be ignored:

assertThat(all, containsInAnyOrder(
    allOf(hasField("foo", equalTo("1111")), hasField("bar", equalTo("444"))),
    allOf(hasField("foo", equalTo("2222")), hasField("bar", equalTo("555"))),
    allOf(hasField("foo", equalTo("3333")), hasField("bar", equalTo("666")))
));
@xkr47 xkr47 self-assigned this Nov 29, 2018
xkr47 added a commit that referenced this issue Nov 29, 2018
Also report any field access failure instead of silently ignoring.
@xkr47
Copy link
Member

xkr47 commented Nov 29, 2018

Fixed in #2 - please get someone to review it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants