Skip to content

Feature/string contains in any order - #173

Open
tpraxl wants to merge 2 commits into
hamcrest:masterfrom
tpraxl:feature/string-contains-in-any-order
Open

tpraxl wants to merge 2 commits into
hamcrest:masterfrom
tpraxl:feature/string-contains-in-any-order

Conversation

@tpraxl

@tpraxl tpraxl commented Feb 22, 2017

Copy link
Copy Markdown

I kindly request to add stringContainsInAnyOrder as a complement to stringContainsInOrder. It matches if all of the substrings are contained within the subject, regardless of the order.

I'm aware that you are able to achieve the same with

assertThat("this is a string", allOf(
  contains("string"),
  contains("this"),
  contains("a")));

But there are cases when you need to work with an unknown list of strings, like String[] or List.

For these cases, it would be nice to have

String[] tokens = classUnderTest.getTokens();
String subject = getTemplate();
assertThat(subject, stringContainsInAnyOrder(tokens))

@yankee42

Copy link
Copy Markdown

Just as another workaround for now, if you are on Java8:

assertThat(
    subject,
    allOf(Stream.of(tokens).map(Matchers::containsString).collect(Collectors.toList()))
);

@nhojpatrick

Copy link
Copy Markdown
Member

@tpraxl looks a good idea, happy to look at getting merged if rebased from master as hamcrest-core and hamcrest-library has been merged into hamcrest so can't currently merge in at the moment.

@nhojpatrick

Copy link
Copy Markdown
Member

Going to try and kick start hamcrest, so if you want to get it merged, please rebase from the branch v2.3-candidates.
Still trying to understand how has permissions to perform a release.

This branch has not been deployed

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

Projects

No open projects
Status: Awaiting rebase

Development

Successfully merging this pull request may close these issues.

3 participants