I have an integration test method that should throw the following exception (because of a unique constrain on the email column of the users table):
Code:
javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException
Here is the test:
Code:
@Test
@ExpectedException(PersistenceException.class)
public void save_UserTestDataUpdateUserNonUniqueEmail_PersistenceException() {
User powerUser = dao.findById("poweruser");
powerUser.setEmail("kuser@null.com");
dao.save(powerUser);
}
But no exception is thrown! I am using Spring Test and so the unit of work will be rolledback at the end of the method.
However, if AFTER the dao.save(...) call I make a call to flush() or FindAll()....then I get my exception.
Is this the way it is supposed to work?