Var args for StringAssert::contains() #120

Open
tedyoung opened this Issue Oct 27, 2012 · 2 comments

Projects

None yet

2 participants

@tedyoung
Collaborator

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.

@joel-costigliola
Collaborator

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

@joel-costigliola
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment