liangzai-cool / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

provide Matcher accepting overloads for IsIn #120

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
IsIn should accept custom matchers, as the counterpart IsCollectionContaining 
does.

So you could do something like that:

assertThat(actualValue, isIn(possibleValues, new ItemMatcher<String>() {
  Matcher<String> apply(String item) {
    return equalToIgnoringCase(item);
  }
}));

(Could be much shorter, with the Java 7 closures, if they will become reality 
one day)

assertThat(actualValue, isIn(possibleValues, 
  #(String item) (equalToIgnoringCase(item)))
);

Best regard,
Daniel

Original issue reported on code.google.com by drothma...@googlemail.com on 12 Aug 2010 at 3:08

GoogleCodeExporter commented 9 years ago
tagged Java

Original comment by t.denley on 12 May 2012 at 10:46

GoogleCodeExporter commented 9 years ago
I'm assuming in your test case possible values is just a static array of values:
String[] possibleValues = {"a", "b", "c"};

If this is the case, then is there are reason why your assertion can't be 
expressed by this:

assertThat(actualValue, is(anyOf(equalToIgnoringCase("a"),
                                 equalToIgnoringCase("b"),
                                 equalToIgnoringCase("c"))))

Original comment by t.denley on 20 May 2012 at 4:50

GoogleCodeExporter commented 9 years ago
Closing as the requested feature seems achievable via other means and the 
sponsoring user has gone dark.

Original comment by t.denley on 29 Jul 2012 at 9:54