fest-assert-2.x icon indicating copy to clipboard operation
fest-assert-2.x copied to clipboard

Var args for StringAssert::contains()

Open tedyoung opened this issue 12 years ago • 2 comments

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.

tedyoung avatar Oct 27 '12 01:10 tedyoung

I agree it would be handy, thanks for reporting this.

joel-costigliola avatar Nov 17 '12 22:11 joel-costigliola

For your information, this issue has been fixed in AssertJ a fork of Fest Assert 2.0M10.

joel-costigliola avatar Apr 15 '13 09:04 joel-costigliola