bval-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Myers (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (BVAL-149) ConstraintViolation contains wrong property
Date Wed, 19 Oct 2016 18:01:02 GMT

     [ 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();
        ConstraintViolation<TestingObject> violation = Iterables.getOnlyElement(VALIDATOR.validate(trueObject));
        assertEquals(violation.getMessage(), "boolean is false");
        assertEquals(violation.getPropertyPath().toString(), "booleanFalse");
    }

    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();
        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}


> 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();
>         ConstraintViolation<TestingObject> violation = Iterables.getOnlyElement(VALIDATOR.validate(trueObject));
>         assertEquals(violation.getMessage(), "boolean is false");
>         assertEquals(violation.getPropertyPath().toString(), "booleanFalse");
>     }
>     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)

Mime
View raw message