|
|
|
@ -74,7 +74,7 @@ public class TestEntityManagerTests {
|
|
|
|
|
public void persistAndGetIdShouldPersistAndGetId() throws Exception {
|
|
|
|
|
bindEntityManager();
|
|
|
|
|
TestEntity entity = new TestEntity();
|
|
|
|
|
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(null, 123);
|
|
|
|
|
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
|
|
|
|
Object result = this.testEntityManager.persistAndGetId(entity);
|
|
|
|
|
verify(this.entityManager).persist(entity);
|
|
|
|
|
assertThat(result).isEqualTo(123);
|
|
|
|
@ -84,7 +84,7 @@ public class TestEntityManagerTests {
|
|
|
|
|
public void persistAndGetIdForTypeShouldPersistAndGetId() throws Exception {
|
|
|
|
|
bindEntityManager();
|
|
|
|
|
TestEntity entity = new TestEntity();
|
|
|
|
|
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(null, 123);
|
|
|
|
|
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
|
|
|
|
Integer result = this.testEntityManager.persistAndGetId(entity, Integer.class);
|
|
|
|
|
verify(this.entityManager).persist(entity);
|
|
|
|
|
assertThat(result).isEqualTo(123);
|
|
|
|
@ -99,17 +99,6 @@ public class TestEntityManagerTests {
|
|
|
|
|
assertThat(result).isSameAs(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void persistWhenAlreadyHasIdShouldThrowException() throws Exception {
|
|
|
|
|
bindEntityManager();
|
|
|
|
|
TestEntity entity = new TestEntity();
|
|
|
|
|
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
|
|
|
|
this.thrown.expect(IllegalStateException.class);
|
|
|
|
|
this.thrown.expectMessage(
|
|
|
|
|
"Entity " + TestEntity.class.getName() + " already has an ID");
|
|
|
|
|
this.testEntityManager.persistAndGetId(entity, Integer.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void persistAndFlushShouldPersistAndFlush() throws Exception {
|
|
|
|
|
bindEntityManager();
|
|
|
|
@ -125,7 +114,7 @@ public class TestEntityManagerTests {
|
|
|
|
|
bindEntityManager();
|
|
|
|
|
TestEntity entity = new TestEntity();
|
|
|
|
|
TestEntity found = new TestEntity();
|
|
|
|
|
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(null, 123);
|
|
|
|
|
given(this.persistenceUnitUtil.getIdentifier(entity)).willReturn(123);
|
|
|
|
|
given(this.entityManager.find(TestEntity.class, 123)).willReturn(found);
|
|
|
|
|
TestEntity result = this.testEntityManager.persistFlushFind(entity);
|
|
|
|
|
verify(this.entityManager).persist(entity);
|
|
|
|
|