fest-assert-2.x
fest-assert-2.x copied to clipboard
Var args for StringAssert::contains()
Recently I've found myself doing this:
String json = getPolicyInfoFromRemoteSystem();
assertThat(json)
.contains("{")
.contains("}")
.contains("coverages");
Yes, I could use a regex, but then it looks like this:
assertThat(json)
.matches("\{.*coverages.*\}");
Which while more concise, is a bit ugly because of the escaping needed. It gets worse, though, if I don't know (and/or care about) the order, e.g., if I want to assert that the string contains {
, }
, coverages
, and vehicle
:
.matches("\{.*((vehicle)|(coverages)).*\}");
So it'd be nice if the contains()
method on StringAssert
took a var args of String
, e.g.:
.contains("{", "}", "coverages", "vehicle");
It's similar to the usage of contains()
for iterables.
I agree it would be handy, thanks for reporting this.