assertTrue(req.test(Arrays.asList(new Object[1])));
}
public void testRequiredIfOthersPresent() {
Rules r = new Rules(Person.class);
PropertyConstraint c = new RequiredIfOthersPresent("zip", "city,state");
r.add(c);
// Ensure that it properly reports all property dependencies
assertTrue(c.isDependentOn("zip"));
assertTrue(c.isDependentOn("city"));
assertTrue(c.isDependentOn("state"));
Person p = new Person();
assertTrue(r.test(p)); // No city or state, so not required
p.setCity("city");
assertTrue(r.test(p)); // Need both city and state, so not required
p.setState("state");
assertFalse(r.test(p));
p.setZip("zip");
assertTrue(r.test(p));
// Now test the OR version
r = new Rules(Person.class);
c = new RequiredIfOthersPresent("zip", "city,state", LogicalOperator.OR);
r.add(c);
assertTrue(c.isDependentOn("zip"));
assertTrue(c.isDependentOn("city"));
assertTrue(c.isDependentOn("state"));
p = new Person();
assertTrue(r.test(p)); // No city or state, so not required