Creates the permutation of
texts which might be useful in
SeleniumHelper.assertMessagesContainsAny in order to reflect that validation constraint violoations are generally in undefined order since
Validator.validate returns a
Set.This methods creates
n faculty (
n!) items for
n items in
text which can take a long time to check (five items can already take up to a minute). Note that the type of the collection used for
texts determines whether the return value contains the item more than once or not. An example for steam fetichist (involving SteamEx stream extension):
createMessagePermutation(StreamEx.of(entities.stream()) .map(prop -> String.format("invalid: key '%s' mustn't be mapped to null", prop.getName())) .append("invalid: mapping for this entity isn't valid. Details should have been given to you.") .collect(Collectors.toSet())) .stream() .map(perm -> StreamEx.of(perm) .joining("\n", String.format("%s\n" + "The following constraints are violated:\n", BackingBean.X_FAILED_ERROR_SUMMARY), String.format("\nFix the corresponding values in the components."))) //joining isn't necessary because \n could have been //added to each of the permutation items, this was //used as a way to get to know the awesome StreamEx //library .collect(Collectors.toSet());