DATAJPA-177 - Throw exception if entity to delete does not exist.
We now do an exists check inside SimpleJpaRepository.delete(ID id) before actually triggering the deletion to avoid an exception when trying to delete a null value. We throw an EmptyResultDataAccessException to indicate the nonexistent entity now.
This commit is contained in:
@@ -27,6 +27,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.sample.User;
|
||||
|
||||
@@ -81,4 +82,13 @@ public class SimpleJpaRepositoryUnitTests {
|
||||
|
||||
verify(query, times(0)).getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-177
|
||||
*/
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void throwsExceptionIfEntityToDeleteDoesNotExist() {
|
||||
|
||||
repo.delete(4711L);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user