Skip to content

Commit e12fbd3

Browse files
committed
avoid EntityManager close() exception through isOpen() check (SPR-7215)
1 parent 928f542 commit e12fbd3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

org.springframework.orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ public void testPropertiesForTransactionalEntityManager() {
573573
EntityManager em = (EntityManager) emC.getMock();
574574
emfMc.expectAndReturn(mockEmf.createEntityManager(props), em);
575575
emC.expectAndReturn(em.getDelegate(), new Object());
576+
emC.expectAndReturn(em.isOpen(), true);
576577
em.close();
577578

578579
emfMc.replay();
@@ -602,6 +603,7 @@ public void testPropertiesForSharedEntityManager1() {
602603
// only one call made - the first EM definition wins (in this case the one w/ the properties)
603604
emfMc.expectAndReturn(mockEmf.createEntityManager(props), em);
604605
emC.expectAndReturn(em.getDelegate(), new Object(), 2);
606+
emC.expectAndReturn(em.isOpen(), true);
605607
em.close();
606608

607609
emfMc.replay();
@@ -639,6 +641,7 @@ public void testPropertiesForSharedEntityManager2() {
639641
// only one call made - the first EM definition wins (in this case the one w/o the properties)
640642
emfMc.expectAndReturn(mockEmf.createEntityManager(), em);
641643
emC.expectAndReturn(em.getDelegate(), new Object(), 2);
644+
emC.expectAndReturn(em.isOpen(), true);
642645
em.close();
643646

644647
emfMc.replay();
@@ -832,6 +835,9 @@ private static class DummyInvocationHandler implements InvocationHandler, Serial
832835
public static boolean closed;
833836

834837
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
838+
if ("isOpen".equals(method.getName())) {
839+
return true;
840+
}
835841
if ("close".equals(method.getName())) {
836842
closed = true;
837843
return null;

0 commit comments

Comments
 (0)