{code :title=ValidateIterableTest.java|borderStyle=solid } import javax.validation.ConstraintViolation; import javax.validation.Valid; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.constraints.NotNull;
import java.util.Collections; import java.util.Iterator; import java.util.Set;
import org.testng.annotations.Test;
import static org.fest.assertions.api.Assertions.assertThat;
public class ValidateIterableTest { private static class TestNotNullValidation implements Iterable<Object> { @NotNull private Integer cannotBeNull = null;
@Override public Iterator<Object> iterator() { return Collections.emptyIterator(); } }
private static class TestCascadingValidation { @Valid private TestNotNullValidation cannotHaveNull = new TestNotNullValidation(); }
@Test(enabled = false) public void testCascadingValidationWhenCascadedTypeImplementsIterable() { TestCascadingValidation validateThis = new TestCascadingValidation(); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set<ConstraintViolation<TestCascadingValidation>> violations = validator.validate(validateThis); assertThat(violations).isNotEmpty(); } } {code}
|