Order of evaluation of Hamcrest CombinableMatcher

70 views
Skip to first unread message

hamcrest_user

unread,
Aug 23, 2021, 12:19:50 PM8/23/21
to Hamcrest Java Users

I wanted to write a logic for matcher like matcher_1 AND matcher_2 OR matcher_3 and matcher_4 where matcher_i are just placeholder for hamcrest matchers.

I decided to write it using CombinableMatcher like this -

new CombinableMatcher<String>(matcher_1).and(matcher_2).or(matcher_3).and(matcher_4)

Now, the question is in which order matchers will be evaluated ?

Will it be ((((matcher_1) AND matcher_2) OR matcher_3) and matcher_4) or any other order like ((matcher_1 AND matcher_2) OR (matcher_3 and matcher_4)) ?

hamcrest_user

unread,
Aug 27, 2021, 12:53:53 AM8/27/21
to Hamcrest Java Users

Steve Freeman

unread,
Aug 28, 2021, 10:22:02 AM8/28/21
to Hamcrest Java Users
Also posted to that stackoverflow question.

Good to see that someone understands the idea of composing matchers.

I'm wondering why you're concerned with the ordering of matchers? Ideally it shouldn't matter, since you also don't know how often a matcher will be called.

If you have issues at this level of detail, it might be best to write a custom matcher.

Reply all
Reply to author
Forward
0 new messages