Package org.qi4j.api.constraint

Examples of org.qi4j.api.constraint.ConstraintViolation


        else
        {
            if( value == null )
            {
                violations = new ArrayList<ConstraintViolation>();
                violations.add( new ConstraintViolation( name, OPTIONAL, null ) );
            }
        }

        if( violations == null && value != null )
        {
            for( ConstraintInstance constraint : constraints )
            {
                boolean valid;
                try
                {
                    valid = constraint.isValid( value );
                }
                catch( NullPointerException e )
                {
                    // A NPE is the same as a failing constraint
                    valid = false;
                }

                if( !valid )
                {
                    if( violations == null )
                    {
                        violations = new ArrayList<ConstraintViolation>();
                    }
                    ConstraintViolation violation = new ConstraintViolation( name, constraint.annotation(), value );
                    violations.add( violation );
                }
            }
        }
View Full Code Here


        catch( ConstraintViolationException e )
        {
            // expected
            Collection<ConstraintViolation> violations = e.constraintViolations();
            assertEquals( 1, violations.size() );
            ConstraintViolation violation = violations.iterator().next();
            assertEquals( "not optional", violation.constraint().toString() );
            assertEquals( "param1", violation.name() );
        }
    }
View Full Code Here

        else
        {
            if( value == null )
            {
                violations = new ArrayList<>();
                violations.add( new ConstraintViolation( name, OPTIONAL, null ) );
            }
        }

        if( violations == null && value != null )
        {
            for( ConstraintInstance constraint : constraints )
            {
                boolean valid;
                try
                {
                    valid = constraint.isValid( value );
                }
                catch( NullPointerException e )
                {
                    // A NPE is the same as a failing constraint
                    valid = false;
                }

                if( !valid )
                {
                    if( violations == null )
                    {
                        violations = new ArrayList<>();
                    }
                    ConstraintViolation violation = new ConstraintViolation( name, constraint.annotation(), value );
                    violations.add( violation );
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.qi4j.api.constraint.ConstraintViolation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.