No, this is the area where Hamcrest is better than AssertJ.
To write the following statement:
Set<String> goodTags = newLinkedHashSet("Fine", "Good"); Set<String> badTags = newLinkedHashSet("Bad!", "Awful"); Set<String> tags = newLinkedHashSet("Fine", "Good", "Ok", "?");
you need to create this condition:
import static org.assertj.core.util.Lists.newArrayList; import java.util.Collection; import org.assertj.core.api.Condition; public class ContainsCondition extends Condition<Iterable<String>> { private Collection<String> collection; public ContainsCondition(Iterable<String> values) { super("contains " + values); this.collection = newArrayList(values); } static ContainsCondition contains(Collection<String> set) { return new ContainsCondition(set); } @Override public boolean matches(Iterable<String> actual) { Collection<String> values = newArrayList(actual); for (String string : collection) { if (!values.contains(string)) return false; } return true; }; }
Perhaps this is not the case if you expect that the presence of your tags in one collection means that they are not in another.
source share