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

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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}
    via by Pavel,
  • 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}
    via by Pavel,
  • GitHub comment 4142#125491144
    via GitHub by hasancelik
    ,
  • SocketInterceptorTest failing
    via GitHub by dpocock
    ,
    • 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)

    Users with the same issue

    Axelo
    Axelo1 times, last one,
    andyglick
    andyglick3 times, last one,
    bernardpaulus
    bernardpaulus4 times, last one,
    osvzs
    osvzs1 times, last one,
    olle.hallin
    olle.hallin1 times, last one,
    5 more bugmates