You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bval.apache.org by "John Myers (JIRA)" <ji...@apache.org> on 2016/10/19 17:56:58 UTC

[jira] [Updated] (BVAL-149) ConstraintViolation contains wrong property

     [ https://issues.apache.org/jira/browse/BVAL-149?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

John Myers updated BVAL-149:
----------------------------
    Description: 
The following test case fails with:

{noformat}
java.lang.AssertionError: expected [booleanFalse] but found [booleanTrue]
Expected :booleanFalse
Actual   :booleanTrue
{noformat}

{code}
import com.google.common.collect.Iterables;
import org.apache.bval.jsr.ApacheValidationProvider;
import org.testng.annotations.Test;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.constraints.AssertTrue;

import static org.testng.Assert.assertEquals;

public class TestValidation
{
    private static final Validator VALIDATOR = Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator();

    @Test
    public void testViolationIdentifiesCorrectAttribute()
    {
        TestingObject trueObject = new TestingObject();
        assertViolationMatches(trueObject, "booleanFalse", "boolean is false");
    }

    private static void assertViolationMatches(TestingObject object, String property, String message)
    {
        ConstraintViolation<TestingObject> violation = Iterables.getOnlyElement(VALIDATOR.validate(object));
        assertEquals(violation.getMessage(), message);
        assertEquals(violation.getPropertyPath().toString(), property);

    }

    private static class TestingObject
    {
        @AssertTrue(message = "boolean is true")
        private boolean isBooleanTrue()
        {
            return true;
        }

        @AssertTrue(message = "boolean is false")
        private boolean isBooleanFalse()
        {
            return false;
        }
    }
}
{code}

  was:
The following test case fails with:

{noformat}
java.lang.AssertionError: expected [booleanFalse] but found [booleanTrue]
Expected :booleanFalse
Actual   :booleanTrue
{noformat}

{code}
import com.google.common.collect.Iterables;
import org.apache.bval.jsr.ApacheValidationProvider;
import org.testng.annotations.Test;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.constraints.AssertTrue;

import static org.testng.Assert.assertEquals;

public class TestValidation
{
    private static final Validator VALIDATOR = Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator();

    @Test
    public void testViolationIdentifiesCorrectAttribute()
    {
        TestingObject trueObject = new TestingObject(true);
        assertViolationMatches(trueObject, "booleanFalse", "boolean is false");
    }

    private static void assertViolationMatches(TestingObject object, String property, String message)
    {
        ConstraintViolation<TestingObject> violation = Iterables.getOnlyElement(VALIDATOR.validate(object));
        assertEquals(violation.getMessage(), message);
        assertEquals(violation.getPropertyPath().toString(), property);

    }

    private static class TestingObject
    {
        private final boolean bool;

        public TestingObject(boolean bool)
        {
            this.bool = bool;
        }

        @AssertTrue(message = "boolean is true")
        private boolean isBooleanTrue()
        {
            return bool;
        }

        @AssertTrue(message = "boolean is false")
        private boolean isBooleanFalse()
        {
            return !bool;
        }
    }
}
{code}


> ConstraintViolation contains wrong property
> -------------------------------------------
>
>                 Key: BVAL-149
>                 URL: https://issues.apache.org/jira/browse/BVAL-149
>             Project: BVal
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>            Reporter: John Myers
>
> The following test case fails with:
> {noformat}
> java.lang.AssertionError: expected [booleanFalse] but found [booleanTrue]
> Expected :booleanFalse
> Actual   :booleanTrue
> {noformat}
> {code}
> import com.google.common.collect.Iterables;
> import org.apache.bval.jsr.ApacheValidationProvider;
> import org.testng.annotations.Test;
> import javax.validation.ConstraintViolation;
> import javax.validation.Validation;
> import javax.validation.Validator;
> import javax.validation.constraints.AssertTrue;
> import static org.testng.Assert.assertEquals;
> public class TestValidation
> {
>     private static final Validator VALIDATOR = Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator();
>     @Test
>     public void testViolationIdentifiesCorrectAttribute()
>     {
>         TestingObject trueObject = new TestingObject();
>         assertViolationMatches(trueObject, "booleanFalse", "boolean is false");
>     }
>     private static void assertViolationMatches(TestingObject object, String property, String message)
>     {
>         ConstraintViolation<TestingObject> violation = Iterables.getOnlyElement(VALIDATOR.validate(object));
>         assertEquals(violation.getMessage(), message);
>         assertEquals(violation.getPropertyPath().toString(), property);
>     }
>     private static class TestingObject
>     {
>         @AssertTrue(message = "boolean is true")
>         private boolean isBooleanTrue()
>         {
>             return true;
>         }
>         @AssertTrue(message = "boolean is false")
>         private boolean isBooleanFalse()
>         {
>             return false;
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)