java - I need Matcher<String> containsString(Matcher<String> matcher), am I doing something wrong? -
i'd check string contains string, ignoring case. basically, i'd this:
assertthat(dialogtitle.gettext(), containsstring(equaltoignoringcase("diagram")));
but couldn't find matcher<string>
takes matcher<t>
. there different way how accomplish this?
you can implement own matcher extending substringmatcher
org.hamcrest.core
package:
public class stringcontainsignoringcase extends substringmatcher { public stringcontainsignoringcase(string substring) { super(substring); } @override protected boolean evalsubstringof(string s) { return s.tolowercase().contains(substring.tolowercase()); } @override protected string relationship() { return "containing (ignoring case)"; } public static matcher<string> containsstringignoringcase(string substring) { return new stringcontainsignoringcase(substring); } }
usage:
assertthat(dialogtitle.gettext(), stringcontainsignoringcase.containsstringignoringcase("diagram"));
and readability can make static import of course , get:
assertthat(dialogtitle.gettext(), containsstringignoringcase("diagram"));
the matcher asking in master branch of javahamcrest project unfortunately not in latest release of hamcrest (1.3).
Comments
Post a Comment