JpaUnitContext implements ExecutionContext { public static synchronized JpaUnitContext getInstance(final Class<?> testClass) { return CTX_MAP.computeIfAbsent(testClass, JpaUnitContext::new); } private  JpaUnitContext(final Class<?> testClass); static synchronized JpaUnitContext getInstance(final Class<?> testClass); @Override Field getPersistenceField(); @Override void storeData(final String key, final Object value); @Override Object getData(final String key); @Override PersistenceUnitDescriptor getDescriptor();  }
@Test public void testExceptionIsThrownIfNeitherEntityManagerFactoryNorEntityManagerFieldIsPresent() throws Exception { expectedException.expect(IllegalArgumentException.class); JpaUnitContext.getInstance(ClassWithoutPersistenceFields.class); }
@Test public void testExceptionIsThrownIfBothEntityManagerFactoryAndEntityManagerFieldArePresent() throws Exception { expectedException.expect(IllegalArgumentException.class); JpaUnitContext.getInstance(ClassWithEntitiyManagerAndEntityManagerFactory.class); }
@Test public void testExceptionIsThrownIfMultipleEntityManagerFactoryFieldsArePresent() throws Exception { expectedException.expect(IllegalArgumentException.class); JpaUnitContext.getInstance(ClassWithTwoEntityManagerFactoryFields.class); }
@Test public void testExceptionIsThrownIfMultipleEntityManagerFieldsArePresent() throws Exception { expectedException.expect(IllegalArgumentException.class); JpaUnitContext.getInstance(ClassWithTwoEntitiyManagerFields.class); }
@Test public void testExceptionIsThrownIfFieldAnnotatedWithPersistenceContextIsNotOfTypeEntityManager() throws Exception { expectedException.expect(IllegalArgumentException.class); JpaUnitContext.getInstance(ClassWithWrongPersistenceContextType.class); }
@Test public void testExceptionIsThrownIfFieldAnnotatedWithPersistenceUnitIsNotOfTypeEntityManagerFactory() throws Exception { expectedException.expect(IllegalArgumentException.class); JpaUnitContext.getInstance(ClassWithWrongPersistenceUnitType.class); }
@Test public void testExceptionIsThrownIfNoDescriptorsForSpecifiedUnitNameCanBeFound() throws Exception { expectedException.expect(JpaUnitException.class); JpaUnitContext.getInstance(ClassWithPersistenceContextWithoutDescriptors.class); }
@Test public void testExceptionIsThrownIfMultipleDescriptorsForSpecifiedUnitNameAreFound() throws Exception { expectedException.expect(JpaUnitException.class); JpaUnitContext.getInstance(ClassWithPersistenceContextWithMultipleDescriptors.class); }