java.lang.AssertionError: Expected exception: javax.validation.ConstraintViolationException

Hibernate JIRA | Pavel | 2 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I have an entity with UUID primary key {code} @Id @Type(type = "pg-uuid") @Column(name = "gid") @GeneratedValue(generator = "hibernate-uuid") @GenericGenerator(name = "hibernate-uuid", strategy = "uuid2") private UUID id; @NotBlank @Column(name = "full_name") private String fullName; {code} When I save an object with null or empty fullName via org.springframework.data.repository.CrudRepository in production or debug mode of application all is OK. But I have a Junit-test {code} @RunWith(SpringJUnit4ClassRunner.class) @SpringWebApplicationTestCase public class OrganizationTest extends AbstractTestConfig { @Autowired OrganizationRepository organizationRepository; private Organization organization; @Before public void setUp() throws Exception { organization = new Organization(); } @Test(expected = ConstraintViolationException.class) public void createOrganizationValidation() throws Exception { organizationRepository.save(organization); } } {code} It fails because validation not fired. I found that there is a method "execute" in EntityInsertAction which not fired. {code} Expected exception: javax.validation.ConstraintViolationException java.lang.AssertionError: Expected exception: javax.validation.ConstraintViolationException at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:32) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) {code} {noformat} ext.junitVersion = '4.12' ext.springVersion = '4.2.0.RELEASE' ext.springDataJpaVersion = '1.8.2.RELEASE' ext.hibernateVersion = '4.3.10.Final' ext.hibernateValidatorVersion = '5.2.1.Final' {noformat}

    Hibernate JIRA | 2 years ago | Pavel
    java.lang.AssertionError: Expected exception: javax.validation.ConstraintViolationException
  2. 0

    I have an entity with UUID primary key {code} @Id @Type(type = "pg-uuid") @Column(name = "gid") @GeneratedValue(generator = "hibernate-uuid") @GenericGenerator(name = "hibernate-uuid", strategy = "uuid2") private UUID id; @NotBlank @Column(name = "full_name") private String fullName; {code} When I save an object with null or empty fullName via org.springframework.data.repository.CrudRepository in production or debug mode of application all is OK. But I have a Junit-test {code} @RunWith(SpringJUnit4ClassRunner.class) @SpringWebApplicationTestCase public class OrganizationTest extends AbstractTestConfig { @Autowired OrganizationRepository organizationRepository; private Organization organization; @Before public void setUp() throws Exception { organization = new Organization(); } @Test(expected = ConstraintViolationException.class) public void createOrganizationValidation() throws Exception { organizationRepository.save(organization); } } {code} It fails because validation not fired. I found that there is a method "execute" in EntityInsertAction which not fired. {code} Expected exception: javax.validation.ConstraintViolationException java.lang.AssertionError: Expected exception: javax.validation.ConstraintViolationException at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:32) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) {code} {noformat} ext.junitVersion = '4.12' ext.springVersion = '4.2.0.RELEASE' ext.springDataJpaVersion = '1.8.2.RELEASE' ext.hibernateVersion = '4.3.10.Final' ext.hibernateValidatorVersion = '5.2.1.Final' {noformat}

    Hibernate JIRA | 2 years ago | Pavel
    java.lang.AssertionError: Expected exception: javax.validation.ConstraintViolationException
  3. 0

    Unable to pass junit test for uniqueConstraintException with hibernate

    Stack Overflow | 3 years ago | naoru
    java.lang.AssertionError: Expected exception: org.hibernate.exception.ConstraintViolationException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    junit test runs OK locally and in jenkins but not in bamboo

    Stack Overflow | 2 years ago
    java.lang.AssertionError: Expected exception: com.vaadin.data.fieldgroup.FieldGroup$CommitException
  6. 0

    GitHub comment 4142#125491144

    GitHub | 2 years ago | hasancelik
    java.lang.AssertionError: Expected exception: java.util.concurrent.CancellationException

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.AssertionError

      Expected exception: javax.validation.ConstraintViolationException

      at org.junit.internal.runners.statements.ExpectException.evaluate()
    2. JUnit
      RunBefores.evaluate
      1. org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:32)
      2. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      2 frames