This commit is contained in:
Stéphane Nicoll
2023-12-30 11:08:09 +01:00
parent 0ad3800f54
commit 9f3fd103ef
23 changed files with 209 additions and 223 deletions

View File

@@ -48,7 +48,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
extends AbstractEntityManagerFactoryIntegrationTests {
@Test
public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
protected void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
boolean condition = entityManagerFactory instanceof EntityManagerFactoryInfo;
assertThat(condition).as("Must have introduced config interface").isTrue();
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
@@ -58,33 +58,33 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
@Test
public void testStateClean() {
void testStateClean() {
assertThat(countRowsInTable("person")).as("Should be no people from previous transactions").isEqualTo(0);
}
@Test
public void testJdbcTx1_1() {
void testJdbcTx1_1() {
testJdbcTx2();
}
@Test
public void testJdbcTx1_2() {
void testJdbcTx1_2() {
testJdbcTx2();
}
@Test
public void testJdbcTx1_3() {
void testJdbcTx1_3() {
testJdbcTx2();
}
@Test
public void testJdbcTx2() {
void testJdbcTx2() {
assertThat(countRowsInTable("person")).as("Any previous tx must have been rolled back").isEqualTo(0);
executeSqlScript("/org/springframework/orm/jpa/insertPerson.sql");
}
@Test
public void testEntityManagerProxyIsProxy() {
void testEntityManagerProxyIsProxy() {
assertThat(Proxy.isProxyClass(sharedEntityManager.getClass())).isTrue();
Query q = sharedEntityManager.createQuery("select p from Person as p");
q.getResultList();
@@ -95,7 +95,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
@Test
public void testBogusQuery() {
void testBogusQuery() {
assertThatRuntimeException().isThrownBy(() -> {
Query query = sharedEntityManager.createQuery("It's raining toads");
// required in OpenJPA case
@@ -104,7 +104,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
@Test
public void testGetReferenceWhenNoRow() {
void testGetReferenceWhenNoRow() {
assertThatException().isThrownBy(() -> {
Person notThere = sharedEntityManager.getReference(Person.class, 666);
// We may get here (as with Hibernate). Either behaviour is valid:
@@ -115,7 +115,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
@Test
public void testLazyLoading() throws Exception {
void testLazyLoading() throws Exception {
try {
Person tony = new Person();
tony.setFirstName("Tony");
@@ -171,13 +171,13 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
@Test
public void testEntityManagerProxyRejectsProgrammaticTxManagement() {
void testEntityManagerProxyRejectsProgrammaticTxManagement() {
assertThatIllegalStateException().as("Should not be able to create transactions on container managed EntityManager").isThrownBy(
sharedEntityManager::getTransaction);
}
@Test
public void testInstantiateAndSaveWithSharedEmProxy() {
void testInstantiateAndSaveWithSharedEmProxy() {
testInstantiateAndSave(sharedEntityManager);
}
@@ -246,7 +246,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
}
@Test
public void testCanSerializeProxies() throws Exception {
void testCanSerializeProxies() throws Exception {
assertThat(SerializationTestUtils.serializeAndDeserialize(entityManagerFactory)).isNotNull();
assertThat(SerializationTestUtils.serializeAndDeserialize(sharedEntityManager)).isNotNull();
}

View File

@@ -40,12 +40,12 @@ public abstract class AbstractEntityManagerFactoryBeanTests {
protected static EntityManagerFactory mockEmf;
@BeforeEach
public void setUp() {
void setUp() {
mockEmf = mock();
}
@AfterEach
public void tearDown() throws Exception {
public void tearDown() {
assertThat(TransactionSynchronizationManager.getResourceMap()).isEmpty();
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();
assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();

View File

@@ -88,7 +88,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
@BeforeEach
public void setup() {
void setup() {
if (applicationContext == null) {
applicationContext = new ClassPathXmlApplicationContext(getConfigLocations());
}

View File

@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Juergen Hoeller
* @since 2.0
*/
public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
class ApplicationManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
@Test
@SuppressWarnings("unchecked")
@@ -54,20 +54,20 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt
}
@Test
public void testEntityManagerProxyAcceptsProgrammaticTxJoining() {
void testEntityManagerProxyAcceptsProgrammaticTxJoining() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
}
@Test
public void testInstantiateAndSave() {
void testInstantiateAndSave() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
doInstantiateAndSave(em);
}
@Test
public void testCannotFlushWithoutGettingTransaction() {
void testCannotFlushWithoutGettingTransaction() {
EntityManager em = entityManagerFactory.createEntityManager();
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
doInstantiateAndSave(em));
@@ -93,12 +93,12 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt
}
@Test
public void testStateClean() {
void testStateClean() {
assertThat(countRowsInTable("person")).as("Should be no people from previous transactions").isEqualTo(0);
}
@Test
public void testReuseInNewTransaction() {
void testReuseInNewTransaction() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
@@ -134,7 +134,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt
}
@Test
public void testRollbackOccurs() {
void testRollbackOccurs() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
doInstantiateAndSave(em);
@@ -143,7 +143,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt
}
@Test
public void testCommitOccurs() {
void testCommitOccurs() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
doInstantiateAndSave(em);

View File

@@ -41,24 +41,24 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Juergen Hoeller
* @since 2.0
*/
public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
class ContainerManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
@Autowired
private AbstractEntityManagerFactoryBean entityManagerFactoryBean;
@Test
public void testExceptionTranslationWithDialectFoundOnIntroducedEntityManagerInfo() throws Exception {
void testExceptionTranslationWithDialectFoundOnIntroducedEntityManagerInfo() throws Exception {
doTestExceptionTranslationWithDialectFound(((EntityManagerFactoryInfo) entityManagerFactory).getJpaDialect());
}
@Test
public void testExceptionTranslationWithDialectFoundOnEntityManagerFactoryBean() throws Exception {
void testExceptionTranslationWithDialectFoundOnEntityManagerFactoryBean() throws Exception {
assertThat(entityManagerFactoryBean.getJpaDialect()).as("Dialect must have been set").isNotNull();
doTestExceptionTranslationWithDialectFound(entityManagerFactoryBean);
}
protected void doTestExceptionTranslationWithDialectFound(PersistenceExceptionTranslator pet) throws Exception {
protected void doTestExceptionTranslationWithDialectFound(PersistenceExceptionTranslator pet) {
RuntimeException in1 = new RuntimeException("in1");
PersistenceException in2 = new PersistenceException();
assertThat(pet.translateExceptionIfPossible(in1)).as("No translation here").isNull();
@@ -84,7 +84,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
// This would be legal, at least if not actually _starting_ a tx
@Test
public void testEntityManagerProxyRejectsProgrammaticTxManagement() {
void testEntityManagerProxyRejectsProgrammaticTxManagement() {
assertThatIllegalStateException().isThrownBy(
createContainerManagedEntityManager()::getTransaction);
}
@@ -94,19 +94,19 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
* We take the view that this is a valid no op.
*/
@Test
public void testContainerEntityManagerProxyAllowsJoinTransactionInTransaction() {
void testContainerEntityManagerProxyAllowsJoinTransactionInTransaction() {
createContainerManagedEntityManager().joinTransaction();
}
@Test
public void testContainerEntityManagerProxyRejectsJoinTransactionWithoutTransaction() {
void testContainerEntityManagerProxyRejectsJoinTransactionWithoutTransaction() {
endTransaction();
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(
createContainerManagedEntityManager()::joinTransaction);
}
@Test
public void testInstantiateAndSave() {
void testInstantiateAndSave() {
EntityManager em = createContainerManagedEntityManager();
doInstantiateAndSave(em);
}
@@ -124,7 +124,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
}
@Test
public void testReuseInNewTransaction() {
void testReuseInNewTransaction() {
EntityManager em = createContainerManagedEntityManager();
doInstantiateAndSave(em);
endTransaction();
@@ -146,7 +146,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
}
@Test
public void testRollbackOccurs() {
void testRollbackOccurs() {
EntityManager em = createContainerManagedEntityManager();
doInstantiateAndSave(em);
endTransaction(); // Should roll back
@@ -154,7 +154,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
}
@Test
public void testCommitOccurs() {
void testCommitOccurs() {
EntityManager em = createContainerManagedEntityManager();
doInstantiateAndSave(em);
setComplete();

View File

@@ -34,12 +34,12 @@ import static org.mockito.Mockito.mock;
* @author Costin Leau
* @author Phillip Webb
*/
public class DefaultJpaDialectTests {
class DefaultJpaDialectTests {
private JpaDialect dialect = new DefaultJpaDialect();
@Test
public void testDefaultTransactionDefinition() throws Exception {
void testDefaultTransactionDefinition() {
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);
assertThatExceptionOfType(TransactionException.class).isThrownBy(() ->
@@ -47,7 +47,7 @@ public class DefaultJpaDialectTests {
}
@Test
public void testDefaultBeginTransaction() throws Exception {
void testDefaultBeginTransaction() throws Exception {
TransactionDefinition definition = new DefaultTransactionDefinition();
EntityManager entityManager = mock();
EntityTransaction entityTx = mock();
@@ -58,7 +58,7 @@ public class DefaultJpaDialectTests {
}
@Test
public void testTranslateException() {
void testTranslateException() {
OptimisticLockException ex = new OptimisticLockException();
assertThat(dialect.translateExceptionIfPossible(ex).getCause()).isEqualTo(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex).getCause());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,10 +24,10 @@ import static org.mockito.Mockito.verify;
* @author Rod Johnson
* @author Phillip Webb
*/
public class EntityManagerFactoryBeanSupportTests extends AbstractEntityManagerFactoryBeanTests {
class EntityManagerFactoryBeanSupportTests extends AbstractEntityManagerFactoryBeanTests {
@Test
public void testHookIsCalled() throws Exception {
void testHookIsCalled() {
DummyEntityManagerFactoryBean demf = new DummyEntityManagerFactoryBean(mockEmf);
demf.afterPropertiesSet();

View File

@@ -45,14 +45,14 @@ import static org.mockito.Mockito.mock;
* @author Juergen Hoeller
* @author Phillip Webb
*/
public class EntityManagerFactoryUtilsTests {
class EntityManagerFactoryUtilsTests {
/*
* Test method for
* 'org.springframework.orm.jpa.EntityManagerFactoryUtils.doGetEntityManager(EntityManagerFactory)'
*/
@Test
public void testDoGetEntityManager() {
void testDoGetEntityManager() {
// test null assertion
assertThatIllegalArgumentException().isThrownBy(() ->
EntityManagerFactoryUtils.doGetTransactionalEntityManager(null, null));
@@ -64,7 +64,7 @@ public class EntityManagerFactoryUtilsTests {
}
@Test
public void testDoGetEntityManagerWithTx() throws Exception {
void testDoGetEntityManagerWithTx() {
try {
EntityManagerFactory factory = mock();
EntityManager manager = mock();
@@ -84,7 +84,7 @@ public class EntityManagerFactoryUtilsTests {
}
@Test
public void testTranslatesIllegalStateException() {
void testTranslatesIllegalStateException() {
IllegalStateException ise = new IllegalStateException();
DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ise);
assertThat(dex.getCause()).isSameAs(ise);
@@ -93,7 +93,7 @@ public class EntityManagerFactoryUtilsTests {
}
@Test
public void testTranslatesIllegalArgumentException() {
void testTranslatesIllegalArgumentException() {
IllegalArgumentException iae = new IllegalArgumentException();
DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(iae);
assertThat(dex.getCause()).isSameAs(iae);
@@ -105,7 +105,7 @@ public class EntityManagerFactoryUtilsTests {
* We do not convert unknown exceptions. They may result from user code.
*/
@Test
public void testDoesNotTranslateUnfamiliarException() {
void testDoesNotTranslateUnfamiliarException() {
UnsupportedOperationException userRuntimeException = new UnsupportedOperationException();
assertThat(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(userRuntimeException)).as("Exception should not be wrapped").isNull();
}

View File

@@ -50,8 +50,7 @@ import static org.mockito.Mockito.verify;
* @author Juergen Hoeller
* @author Phillip Webb
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class JpaTransactionManagerTests {
class JpaTransactionManagerTests {
private EntityManagerFactory factory = mock();
@@ -65,7 +64,7 @@ public class JpaTransactionManagerTests {
@BeforeEach
public void setup() {
void setup() {
given(factory.createEntityManager()).willReturn(manager);
given(manager.getTransaction()).willReturn(tx);
given(manager.isOpen()).willReturn(true);
@@ -81,7 +80,7 @@ public class JpaTransactionManagerTests {
@Test
public void testTransactionCommit() {
void testTransactionCommit() {
given(manager.getTransaction()).willReturn(tx);
final List<String> l = new ArrayList<>();
@@ -106,7 +105,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionCommitWithRollbackException() {
void testTransactionCommitWithRollbackException() {
given(manager.getTransaction()).willReturn(tx);
given(tx.getRollbackOnly()).willReturn(true);
willThrow(new RollbackException()).given(tx).commit();
@@ -138,7 +137,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionRollback() {
void testTransactionRollback() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);
@@ -163,7 +162,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionRollbackWithAlreadyRolledBack() {
void testTransactionRollbackWithAlreadyRolledBack() {
given(manager.getTransaction()).willReturn(tx);
final List<String> l = new ArrayList<>();
@@ -186,7 +185,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionRollbackOnly() {
void testTransactionRollbackOnly() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);
@@ -214,7 +213,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testParticipatingTransactionWithCommit() {
void testParticipatingTransactionWithCommit() {
given(manager.getTransaction()).willReturn(tx);
final List<String> l = new ArrayList<>();
@@ -241,7 +240,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testParticipatingTransactionWithRollback() {
void testParticipatingTransactionWithRollback() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);
@@ -269,7 +268,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testParticipatingTransactionWithRollbackOnly() {
void testParticipatingTransactionWithRollbackOnly() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);
given(tx.getRollbackOnly()).willReturn(true);
@@ -302,7 +301,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testParticipatingTransactionWithRequiresNew() {
void testParticipatingTransactionWithRequiresNew() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
given(factory.createEntityManager()).willReturn(manager);
@@ -333,7 +332,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testParticipatingTransactionWithRequiresNewAndPrebound() {
void testParticipatingTransactionWithRequiresNewAndPrebound() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
given(manager.getTransaction()).willReturn(tx);
@@ -372,7 +371,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testPropagationSupportsAndRequiresNew() {
void testPropagationSupportsAndRequiresNew() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
given(manager.getTransaction()).willReturn(tx);
@@ -403,7 +402,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testPropagationSupportsAndRequiresNewAndEarlyAccess() {
void testPropagationSupportsAndRequiresNewAndEarlyAccess() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
given(factory.createEntityManager()).willReturn(manager);
@@ -438,7 +437,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionWithRequiresNewInAfterCompletion() {
void testTransactionWithRequiresNewInAfterCompletion() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
EntityManager manager2 = mock();
@@ -479,7 +478,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionCommitWithPropagationSupports() {
void testTransactionCommitWithPropagationSupports() {
given(manager.isOpen()).willReturn(true);
final List<String> l = new ArrayList<>();
@@ -507,7 +506,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionRollbackWithPropagationSupports() {
void testTransactionRollbackWithPropagationSupports() {
given(manager.isOpen()).willReturn(true);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
@@ -532,7 +531,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionCommitWithPrebound() {
void testTransactionCommitWithPrebound() {
given(manager.getTransaction()).willReturn(tx);
final List<String> l = new ArrayList<>();
@@ -563,7 +562,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionRollbackWithPrebound() {
void testTransactionRollbackWithPrebound() {
given(manager.getTransaction()).willReturn(tx);
given(tx.isActive()).willReturn(true);
@@ -593,7 +592,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionCommitWithPreboundAndPropagationSupports() {
void testTransactionCommitWithPreboundAndPropagationSupports() {
final List<String> l = new ArrayList<>();
l.add("test");
@@ -624,7 +623,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionRollbackWithPreboundAndPropagationSupports() {
void testTransactionRollbackWithPreboundAndPropagationSupports() {
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
assertThat(TransactionSynchronizationManager.hasResource(factory)).isFalse();
@@ -653,7 +652,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testInvalidIsolation() {
void testInvalidIsolation() {
tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
given(manager.isOpen()).willReturn(true);
@@ -669,7 +668,7 @@ public class JpaTransactionManagerTests {
}
@Test
public void testTransactionFlush() {
void testTransactionFlush() {
given(manager.getTransaction()).willReturn(tx);
assertThat(TransactionSynchronizationManager.hasResource(factory)).isFalse();

View File

@@ -53,7 +53,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
*/
@SuppressWarnings("rawtypes")
public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityManagerFactoryBeanTests {
class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityManagerFactoryBeanTests {
// Static fields set by inner class DummyPersistenceProvider
@@ -63,12 +63,12 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
@Test
public void testValidPersistenceUnit() throws Exception {
void testValidPersistenceUnit() throws Exception {
parseValidPersistenceUnit();
}
@Test
public void testExceptionTranslationWithNoDialect() throws Exception {
void testExceptionTranslationWithNoDialect() throws Exception {
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
cefb.getObject();
assertThat(cefb.getJpaDialect()).as("No dialect set").isNull();
@@ -82,7 +82,7 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
}
@Test
public void testEntityManagerFactoryIsProxied() throws Exception {
void testEntityManagerFactoryIsProxied() throws Exception {
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
EntityManagerFactory emf = cefb.getObject();
assertThat(cefb.getObject()).as("EntityManagerFactory reference must be cached after init").isSameAs(emf);
@@ -99,7 +99,7 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
}
@Test
public void testApplicationManagedEntityManagerWithoutTransaction() throws Exception {
void testApplicationManagedEntityManagerWithoutTransaction() throws Exception {
Object testEntity = new Object();
EntityManager mockEm = mock();
@@ -119,7 +119,7 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
}
@Test
public void testApplicationManagedEntityManagerWithTransaction() throws Exception {
void testApplicationManagedEntityManagerWithTransaction() throws Exception {
Object testEntity = new Object();
EntityTransaction mockTx = mock();
@@ -160,7 +160,7 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
}
@Test
public void testApplicationManagedEntityManagerWithTransactionAndCommitException() throws Exception {
void testApplicationManagedEntityManagerWithTransactionAndCommitException() throws Exception {
Object testEntity = new Object();
EntityTransaction mockTx = mock();
@@ -202,7 +202,7 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
}
@Test
public void testApplicationManagedEntityManagerWithJtaTransaction() throws Exception {
void testApplicationManagedEntityManagerWithJtaTransaction() throws Exception {
Object testEntity = new Object();
// This one's for the tx (shared)
@@ -241,21 +241,20 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
}
public LocalContainerEntityManagerFactoryBean parseValidPersistenceUnit() throws Exception {
LocalContainerEntityManagerFactoryBean emfb = createEntityManagerFactoryBean(
return createEntityManagerFactoryBean(
"org/springframework/orm/jpa/domain/persistence.xml", null,
"Person");
return emfb;
}
@Test
public void testInvalidPersistenceUnitName() throws Exception {
void testInvalidPersistenceUnitName() {
assertThatIllegalArgumentException().isThrownBy(() ->
createEntityManagerFactoryBean("org/springframework/orm/jpa/domain/persistence.xml", null, "call me Bob"));
}
@SuppressWarnings("unchecked")
protected LocalContainerEntityManagerFactoryBean createEntityManagerFactoryBean(
String persistenceXml, Properties props, String entityManagerName) throws Exception {
String persistenceXml, Properties props, String entityManagerName) {
// This will be set by DummyPersistenceProvider
actualPui = null;
@@ -285,7 +284,7 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
}
@Test
public void testRejectsMissingPersistenceUnitInfo() throws Exception {
void testRejectsMissingPersistenceUnitInfo() {
LocalContainerEntityManagerFactoryBean containerEmfb = new LocalContainerEntityManagerFactoryBean();
String entityManagerName = "call me Bob";

View File

@@ -34,7 +34,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
*/
@SuppressWarnings("rawtypes")
public class LocalEntityManagerFactoryBeanTests extends AbstractEntityManagerFactoryBeanTests {
class LocalEntityManagerFactoryBeanTests extends AbstractEntityManagerFactoryBeanTests {
// Static fields set by inner class DummyPersistenceProvider
@@ -43,22 +43,22 @@ public class LocalEntityManagerFactoryBeanTests extends AbstractEntityManagerFac
private static Map actualProps;
@AfterEach
public void verifyClosed() throws Exception {
public void verifyClosed() {
verify(mockEmf).close();
}
@Test
public void testValidUsageWithDefaultProperties() throws Exception {
void testValidUsageWithDefaultProperties() throws Exception {
testValidUsage(null);
}
@Test
public void testValidUsageWithExplicitProperties() throws Exception {
void testValidUsageWithExplicitProperties() throws Exception {
testValidUsage(new Properties());
}
@SuppressWarnings("unchecked")
protected void testValidUsage(Properties props) throws Exception {
protected void testValidUsage(Properties props) {
// This will be set by DummyPersistenceProvider
actualName = null;
actualProps = null;

View File

@@ -43,10 +43,10 @@ import static org.mockito.Mockito.withSettings;
* @author Juergen Hoeller
*/
@ExtendWith(MockitoExtension.class)
public class SharedEntityManagerCreatorTests {
class SharedEntityManagerCreatorTests {
@Test
public void proxyingWorksIfInfoReturnsNullEntityManagerInterface() {
void proxyingWorksIfInfoReturnsNullEntityManagerInterface() {
EntityManagerFactory emf = mock(EntityManagerFactory.class,
withSettings().extraInterfaces(EntityManagerFactoryInfo.class));
// EntityManagerFactoryInfo.getEntityManagerInterface returns null
@@ -54,7 +54,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void transactionRequiredExceptionOnJoinTransaction() {
void transactionRequiredExceptionOnJoinTransaction() {
EntityManagerFactory emf = mock();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(
@@ -62,7 +62,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void transactionRequiredExceptionOnFlush() {
void transactionRequiredExceptionOnFlush() {
EntityManagerFactory emf = mock();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(
@@ -70,7 +70,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void transactionRequiredExceptionOnPersist() {
void transactionRequiredExceptionOnPersist() {
EntityManagerFactory emf = mock();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
@@ -78,7 +78,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void transactionRequiredExceptionOnMerge() {
void transactionRequiredExceptionOnMerge() {
EntityManagerFactory emf = mock();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
@@ -86,7 +86,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void transactionRequiredExceptionOnRemove() {
void transactionRequiredExceptionOnRemove() {
EntityManagerFactory emf = mock();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
@@ -94,7 +94,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void transactionRequiredExceptionOnRefresh() {
void transactionRequiredExceptionOnRefresh() {
EntityManagerFactory emf = mock();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
@@ -102,7 +102,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void deferredQueryWithUpdate() {
void deferredQueryWithUpdate() {
EntityManagerFactory emf = mock();
EntityManager targetEm = mock();
Query query = mock();
@@ -118,7 +118,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void deferredQueryWithSingleResult() {
void deferredQueryWithSingleResult() {
EntityManagerFactory emf = mock();
EntityManager targetEm = mock();
Query query = mock();
@@ -134,7 +134,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void deferredQueryWithResultList() {
void deferredQueryWithResultList() {
EntityManagerFactory emf = mock();
EntityManager targetEm = mock();
Query query = mock();
@@ -150,7 +150,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void deferredQueryWithResultStream() {
void deferredQueryWithResultStream() {
EntityManagerFactory emf = mock();
EntityManager targetEm = mock();
Query query = mock();
@@ -166,7 +166,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void deferredStoredProcedureQueryWithIndexedParameters() {
void deferredStoredProcedureQueryWithIndexedParameters() {
EntityManagerFactory emf = mock();
EntityManager targetEm = mock();
StoredProcedureQuery query = mock();
@@ -197,7 +197,7 @@ public class SharedEntityManagerCreatorTests {
}
@Test
public void deferredStoredProcedureQueryWithNamedParameters() {
void deferredStoredProcedureQueryWithNamedParameters() {
EntityManagerFactory emf = mock();
EntityManager targetEm = mock();
StoredProcedureQuery query = mock();

View File

@@ -29,16 +29,16 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Juergen Hoeller
*/
public class EclipseLinkEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
class EclipseLinkEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
@Test
public void testCanCastNativeEntityManagerFactoryToEclipseLinkEntityManagerFactoryImpl() {
void testCanCastNativeEntityManagerFactoryToEclipseLinkEntityManagerFactoryImpl() {
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
assertThat(emfi.getNativeEntityManagerFactory().getClass().getName()).endsWith("EntityManagerFactoryImpl");
}
@Test
public void testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager() {
void testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager() {
boolean condition = sharedEntityManager instanceof JpaEntityManager;
assertThat(condition).isTrue();
JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager;

View File

@@ -36,8 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller
* @author Rod Johnson
*/
@SuppressWarnings("deprecation")
public class HibernateEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
class HibernateEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
@Override
protected String[] getConfigLocations() {
@@ -47,18 +46,18 @@ public class HibernateEntityManagerFactoryIntegrationTests extends AbstractConta
@Test
public void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() {
void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() {
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
assertThat(emfi.getNativeEntityManagerFactory()).isInstanceOf(SessionFactory.class);
}
@Test
public void testCanCastSharedEntityManagerProxyToHibernateEntityManager() {
void testCanCastSharedEntityManagerProxyToHibernateEntityManager() {
assertThat(((EntityManagerProxy) sharedEntityManager).getTargetEntityManager()).isInstanceOf(Session.class);
}
@Test
public void testCanUnwrapAopProxy() {
void testCanUnwrapAopProxy() {
EntityManager em = entityManagerFactory.createEntityManager();
EntityManager proxy = ProxyFactory.getProxy(EntityManager.class, new SingletonTargetSource(em));
assertThat(proxy.unwrap(Session.class)).isSameAs(em);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
*
* @author Juergen Hoeller
*/
public class HibernateMultiEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
class HibernateMultiEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
@Autowired
private EntityManagerFactory entityManagerFactory2;
@@ -47,7 +47,7 @@ public class HibernateMultiEntityManagerFactoryIntegrationTests extends Abstract
@Override
@Test
public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
protected void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
boolean condition = this.entityManagerFactory instanceof EntityManagerFactoryInfo;
assertThat(condition).as("Must have introduced config interface").isTrue();
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) this.entityManagerFactory;
@@ -57,7 +57,7 @@ public class HibernateMultiEntityManagerFactoryIntegrationTests extends Abstract
}
@Test
public void testEntityManagerFactory2() {
void testEntityManagerFactory2() {
EntityManager em = this.entityManagerFactory2.createEntityManager();
try {
assertThatIllegalArgumentException().isThrownBy(() ->

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller
* @since 5.1
*/
public class HibernateNativeEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
class HibernateNativeEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests {
@Autowired
private SessionFactory sessionFactory;
@@ -55,7 +55,7 @@ public class HibernateNativeEntityManagerFactoryIntegrationTests extends Abstrac
@Override
@Test
public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
protected void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
boolean condition = entityManagerFactory instanceof EntityManagerFactoryInfo;
assertThat(condition).as("Must not have introduced config interface").isFalse();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Yoann Rodiere
* @author Juergen Hoeller
*/
public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests
class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests
extends AbstractEntityManagerFactoryIntegrationTests {
@Autowired
@@ -68,7 +68,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
@Test
public void testCanRetrieveBeanByTypeWithJpaCompliantOptions() {
void testCanRetrieveBeanByTypeWithJpaCompliantOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
@@ -84,7 +84,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testCanRetrieveBeanByNameWithJpaCompliantOptions() {
void testCanRetrieveBeanByNameWithJpaCompliantOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
@@ -101,7 +101,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testCanRetrieveBeanByTypeWithNativeOptions() {
void testCanRetrieveBeanByTypeWithNativeOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
@@ -129,7 +129,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testCanRetrieveBeanByNameWithNativeOptions() {
void testCanRetrieveBeanByNameWithNativeOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
@@ -157,7 +157,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testCanRetrieveFallbackBeanByTypeWithJpaCompliantOptions() {
void testCanRetrieveFallbackBeanByTypeWithJpaCompliantOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer();
@@ -178,7 +178,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testCanRetrieveFallbackBeanByNameWithJpaCompliantOptions() {
void testCanRetrieveFallbackBeanByNameWithJpaCompliantOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer();
@@ -200,7 +200,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testCanRetrieveFallbackBeanByTypeWithNativeOptions() {
void testCanRetrieveFallbackBeanByTypeWithNativeOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer();
@@ -221,7 +221,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testCanRetrieveFallbackBeanByNameWithNativeOptions() {
void testCanRetrieveFallbackBeanByNameWithNativeOptions() {
BeanContainer beanContainer = getBeanContainer();
assertThat(beanContainer).isNotNull();
NoDefinitionInSpringContextTestBeanInstanceProducer fallbackProducer = new NoDefinitionInSpringContextTestBeanInstanceProducer();
@@ -243,7 +243,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testFallbackExceptionInCaseOfNoSpringBeanFound() {
void testFallbackExceptionInCaseOfNoSpringBeanFound() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
getBeanContainer().getBean(NoDefinitionInSpringContextTestBean.class,
NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE
@@ -251,7 +251,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testOriginalExceptionInCaseOfFallbackProducerFailure() {
void testOriginalExceptionInCaseOfFallbackProducerFailure() {
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
getBeanContainer().getBean(AttributeConverter.class,
NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE
@@ -259,7 +259,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testFallbackExceptionInCaseOfNoSpringBeanFoundByName() {
void testFallbackExceptionInCaseOfNoSpringBeanFoundByName() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
getBeanContainer().getBean("some name", NoDefinitionInSpringContextTestBean.class,
NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE
@@ -267,7 +267,7 @@ public class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTe
}
@Test
public void testOriginalExceptionInCaseOfFallbackProducerFailureByName() {
void testOriginalExceptionInCaseOfFallbackProducerFailureByName() {
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
getBeanContainer().getBean("invalid", AttributeConverter.class,
NativeLifecycleOptions.INSTANCE, IneffectiveBeanInstanceProducer.INSTANCE

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,12 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Stephane Nicoll
*/
public class DefaultPersistenceUnitManagerTests {
class DefaultPersistenceUnitManagerTests {
private final DefaultPersistenceUnitManager manager = new DefaultPersistenceUnitManager();
@Test
public void defaultDomainWithScan() {
void defaultDomainWithScan() {
this.manager.setPackagesToScan("org.springframework.orm.jpa.domain");
this.manager.setResourceLoader(new DefaultResourceLoader(
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
@@ -45,7 +45,7 @@ public class DefaultPersistenceUnitManagerTests {
}
@Test
public void defaultDomainWithIndex() {
void defaultDomainWithIndex() {
this.manager.setPackagesToScan("org.springframework.orm.jpa.domain");
this.manager.setResourceLoader(new DefaultResourceLoader(
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),

View File

@@ -47,10 +47,10 @@ import static org.assertj.core.api.Assertions.assertThatRuntimeException;
* @author Juergen Hoeller
* @author Nicholas Williams
*/
public class PersistenceXmlParsingTests {
class PersistenceXmlParsingTests {
@Test
public void testMetaInfCase() throws Exception {
void testMetaInfCase() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml";
@@ -60,15 +60,14 @@ public class PersistenceXmlParsingTests {
assertThat(info).hasSize(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement");
assertThat(info[0].getJarFileUrls()).hasSize(2);
assertThat(info[0].getJarFileUrls()).element(0).isEqualTo(new ClassPathResource("order.jar").getURL());
assertThat(info[0].getJarFileUrls()).element(1).isEqualTo(new ClassPathResource("order-supplemental.jar").getURL());
assertThat(info[0].getJarFileUrls()).containsExactly(
new ClassPathResource("order.jar").getURL(),
new ClassPathResource("order-supplemental.jar").getURL());
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
@Test
public void testExample1() throws Exception {
void testExample1() {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-example1.xml";
@@ -82,7 +81,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testExample2() throws Exception {
void testExample2() {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-example2.xml";
@@ -93,15 +92,14 @@ public class PersistenceXmlParsingTests {
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement2");
assertThat(info[0].getMappingFileNames()).hasSize(1);
assertThat(info[0].getMappingFileNames()).element(0).isEqualTo("mappings.xml");
assertThat(info[0].getMappingFileNames()).containsExactly("mappings.xml");
assertThat(info[0].getProperties()).isEmpty();
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
@Test
public void testExample3() throws Exception {
void testExample3() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-example3.xml";
@@ -111,9 +109,9 @@ public class PersistenceXmlParsingTests {
assertThat(info).hasSize(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement3");
assertThat(info[0].getJarFileUrls()).hasSize(2);
assertThat(info[0].getJarFileUrls()).element(0).isEqualTo(new ClassPathResource("order.jar").getURL());
assertThat(info[0].getJarFileUrls()).element(1).isEqualTo(new ClassPathResource("order-supplemental.jar").getURL());
assertThat(info[0].getJarFileUrls()).containsExactly(
new ClassPathResource("order.jar").getURL(),
new ClassPathResource("order-supplemental.jar").getURL());
assertThat(info[0].getProperties()).isEmpty();
assertThat(info[0].getJtaDataSource()).isNull();
@@ -123,7 +121,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testExample4() throws Exception {
void testExample4() throws Exception {
SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
DataSource ds = new DriverManagerDataSource();
builder.bind("java:comp/env/jdbc/MyDB", ds);
@@ -137,13 +135,10 @@ public class PersistenceXmlParsingTests {
assertThat(info).hasSize(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement4");
assertThat(info[0].getMappingFileNames()).hasSize(1);
assertThat(info[0].getMappingFileNames()).element(0).isEqualTo("order-mappings.xml");
assertThat(info[0].getMappingFileNames()).containsExactly("order-mappings.xml");
assertThat(info[0].getManagedClassNames()).hasSize(3);
assertThat(info[0].getManagedClassNames()).element(0).isEqualTo("com.acme.Order");
assertThat(info[0].getManagedClassNames()).element(1).isEqualTo("com.acme.Customer");
assertThat(info[0].getManagedClassNames()).element(2).isEqualTo("com.acme.Item");
assertThat(info[0].getManagedClassNames()).containsExactly(
"com.acme.Order", "com.acme.Customer", "com.acme.Item");
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should be true when no value.").isTrue();
@@ -154,7 +149,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testExample5() throws Exception {
void testExample5() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-example5.xml";
@@ -164,13 +159,11 @@ public class PersistenceXmlParsingTests {
assertThat(info).hasSize(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement5");
assertThat(info[0].getMappingFileNames()).hasSize(2);
assertThat(info[0].getMappingFileNames()).element(0).isEqualTo("order1.xml");
assertThat(info[0].getMappingFileNames()).element(1).isEqualTo("order2.xml");
assertThat(info[0].getMappingFileNames()).containsExactly("order1.xml", "order2.xml");
assertThat(info[0].getJarFileUrls()).hasSize(2);
assertThat(info[0].getJarFileUrls()).element(0).isEqualTo(new ClassPathResource("order.jar").getURL());
assertThat(info[0].getJarFileUrls()).element(1).isEqualTo(new ClassPathResource("order-supplemental.jar").getURL());
assertThat(info[0].getJarFileUrls()).containsExactly(
new ClassPathResource("order.jar").getURL(),
new ClassPathResource("order-supplemental.jar").getURL());
assertThat(info[0].getPersistenceProviderClassName()).isEqualTo("com.acme.AcmePersistence");
assertThat(info[0].getProperties()).isEmpty();
@@ -179,7 +172,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testExampleComplex() throws Exception {
void testExampleComplex() throws Exception {
DataSource ds = new DriverManagerDataSource();
String resource = "/org/springframework/orm/jpa/persistence-complex.xml";
@@ -200,11 +193,9 @@ public class PersistenceXmlParsingTests {
assertThat(pu1.getPersistenceProviderClassName()).isEqualTo("com.acme.AcmePersistence");
assertThat(pu1.getMappingFileNames()).hasSize(1);
assertThat(pu1.getMappingFileNames()).element(0).isEqualTo("ormap2.xml");
assertThat(pu1.getMappingFileNames()).containsExactly("ormap2.xml");
assertThat(pu1.getJarFileUrls()).hasSize(1);
assertThat(pu1.getJarFileUrls()).element(0).isEqualTo(new ClassPathResource("order.jar").getURL());
assertThat(pu1.getJarFileUrls()).containsExactly(new ClassPathResource("order.jar").getURL());
assertThat(pu1.excludeUnlistedClasses()).isFalse();
@@ -224,8 +215,7 @@ public class PersistenceXmlParsingTests {
assertThat(pu2.getTransactionType()).isSameAs(PersistenceUnitTransactionType.JTA);
assertThat(pu2.getPersistenceProviderClassName()).isEqualTo("com.acme.AcmePersistence");
assertThat(pu2.getMappingFileNames()).hasSize(1);
assertThat(pu2.getMappingFileNames()).element(0).isEqualTo("order2.xml");
assertThat(pu2.getMappingFileNames()).containsExactly("order2.xml");
// the following assertions fail only during coverage runs
// assertEquals(1, pu2.getJarFileUrls().size());
@@ -240,7 +230,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testExample6() throws Exception {
void testExample6() {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-example6.xml";
@@ -254,7 +244,7 @@ public class PersistenceXmlParsingTests {
@Disabled("not doing schema parsing anymore for JPA 2.0 compatibility")
@Test
public void testInvalidPersistence() throws Exception {
void testInvalidPersistence() {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-invalid.xml";
@@ -263,7 +253,7 @@ public class PersistenceXmlParsingTests {
@Disabled("not doing schema parsing anymore for JPA 2.0 compatibility")
@Test
public void testNoSchemaPersistence() throws Exception {
void testNoSchemaPersistence() {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-no-schema.xml";
@@ -271,7 +261,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testPersistenceUnitRootUrl() throws Exception {
void testPersistenceUnitRootUrl() throws Exception {
URL url = PersistenceUnitReader.determinePersistenceUnitRootUrl(new ClassPathResource("/org/springframework/orm/jpa/persistence-no-schema.xml"));
assertThat(url).isNull();
@@ -281,7 +271,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testPersistenceUnitRootUrlWithJar() throws Exception {
void testPersistenceUnitRootUrlWithJar() throws Exception {
ClassPathResource archive = new ClassPathResource("/org/springframework/orm/jpa/jpa-archive.jar");
String newRoot = "jar:" + archive.getURL().toExternalForm() + "!/META-INF/persist.xml";
Resource insideArchive = new UrlResource(newRoot);
@@ -292,7 +282,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testJpa1ExcludeUnlisted() throws Exception {
void testJpa1ExcludeUnlisted() {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-exclude-1.0.xml";
@@ -323,7 +313,7 @@ public class PersistenceXmlParsingTests {
}
@Test
public void testJpa2ExcludeUnlisted() throws Exception {
void testJpa2ExcludeUnlisted() {
PersistenceUnitReader reader = new PersistenceUnitReader(
new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-exclude-2.0.xml";

View File

@@ -60,7 +60,7 @@ import static org.mockito.Mockito.verify;
* @author Chris Beams
* @author Phillip Webb
*/
public class OpenEntityManagerInViewTests {
class OpenEntityManagerInViewTests {
private final TestTaskExecutor taskExecutor = new TestTaskExecutor();
@@ -76,7 +76,7 @@ public class OpenEntityManagerInViewTests {
@BeforeEach
public void setUp() {
void setUp() {
given(factory.createEntityManager()).willReturn(manager);
this.request.setAsyncSupported(true);
}
@@ -90,7 +90,7 @@ public class OpenEntityManagerInViewTests {
}
@Test
public void testOpenEntityManagerInViewInterceptor() {
void testOpenEntityManagerInViewInterceptor() {
OpenEntityManagerInViewInterceptor interceptor = new OpenEntityManagerInViewInterceptor();
interceptor.setEntityManagerFactory(this.factory);
@@ -126,7 +126,7 @@ public class OpenEntityManagerInViewTests {
}
@Test
public void testOpenEntityManagerInViewInterceptorAsyncScenario() throws Exception {
void testOpenEntityManagerInViewInterceptorAsyncScenario() throws Exception {
// Initial request thread
@@ -183,7 +183,7 @@ public class OpenEntityManagerInViewTests {
}
@Test
public void testOpenEntityManagerInViewInterceptorAsyncTimeoutScenario() throws Exception {
void testOpenEntityManagerInViewInterceptorAsyncTimeoutScenario() throws Exception {
// Initial request thread
@@ -223,7 +223,7 @@ public class OpenEntityManagerInViewTests {
}
@Test
public void testOpenEntityManagerInViewInterceptorAsyncErrorScenario() throws Exception {
void testOpenEntityManagerInViewInterceptorAsyncErrorScenario() throws Exception {
// Initial request thread
@@ -263,7 +263,7 @@ public class OpenEntityManagerInViewTests {
}
@Test
public void testOpenEntityManagerInViewFilter() throws Exception {
void testOpenEntityManagerInViewFilter() throws Exception {
given(manager.isOpen()).willReturn(true);
final EntityManagerFactory factory2 = mock();
@@ -317,7 +317,7 @@ public class OpenEntityManagerInViewTests {
}
@Test
public void testOpenEntityManagerInViewFilterAsyncScenario() throws Exception {
void testOpenEntityManagerInViewFilterAsyncScenario() throws Exception {
given(manager.isOpen()).willReturn(true);
final EntityManagerFactory factory2 = mock();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller
* @author Sam Brannen
*/
public class PersistenceInjectionIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
class PersistenceInjectionIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
@Autowired
private DefaultPublicPersistenceContextSetter defaultSetterInjected;
@@ -40,12 +40,12 @@ public class PersistenceInjectionIntegrationTests extends AbstractEntityManagerF
@Test
public void testDefaultPersistenceContextSetterInjection() {
void testDefaultPersistenceContextSetterInjection() {
assertThat(defaultSetterInjected.getEntityManager()).isNotNull();
}
@Test
public void testSetterInjectionOfNamedPersistenceContext() {
void testSetterInjectionOfNamedPersistenceContext() {
assertThat(namedSetterInjected.getEntityManagerFactory()).isNotNull();
}

View File

@@ -62,11 +62,10 @@ import static org.mockito.Mockito.withSettings;
* @author Juergen Hoeller
* @author Phillip Webb
*/
@SuppressWarnings("resource")
public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanTests {
class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanTests {
@Test
public void testPrivatePersistenceContextField() throws Exception {
void testPrivatePersistenceContextField() throws Exception {
mockEmf = mock(EntityManagerFactory.class, withSettings().serializable());
GenericApplicationContext gac = new GenericApplicationContext();
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
@@ -90,7 +89,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPrivateVendorSpecificPersistenceContextField() {
void testPrivateVendorSpecificPersistenceContextField() {
GenericApplicationContext gac = new GenericApplicationContext();
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
gac.registerBeanDefinition("annotationProcessor",
@@ -105,7 +104,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPublicExtendedPersistenceContextSetter() {
void testPublicExtendedPersistenceContextSetter() {
EntityManager mockEm = mock();
given(mockEmf.createEntityManager()).willReturn(mockEm);
@@ -123,7 +122,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPublicSpecificExtendedPersistenceContextSetter() {
void testPublicSpecificExtendedPersistenceContextSetter() {
EntityManagerFactory mockEmf2 = mock();
EntityManager mockEm2 = mock();
given(mockEmf2.createEntityManager()).willReturn(mockEm2);
@@ -146,7 +145,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testInjectionIntoExistingObjects() {
void testInjectionIntoExistingObjects() {
EntityManager mockEm = mock();
given(mockEmf.createEntityManager()).willReturn(mockEm);
@@ -166,7 +165,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPublicExtendedPersistenceContextSetterWithSerialization() throws Exception {
void testPublicExtendedPersistenceContextSetterWithSerialization() throws Exception {
DummyInvocationHandler ih = new DummyInvocationHandler();
Object mockEm = Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] {EntityManager.class}, ih);
given(mockEmf.createEntityManager()).willReturn((EntityManager) mockEm);
@@ -219,7 +218,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPublicExtendedPersistenceContextSetterWithOverriding() {
void testPublicExtendedPersistenceContextSetterWithOverriding() {
EntityManager mockEm2 = mock();
GenericApplicationContext gac = new GenericApplicationContext();
@@ -237,7 +236,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPrivatePersistenceUnitField() {
void testPrivatePersistenceUnitField() {
GenericApplicationContext gac = new GenericApplicationContext();
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
gac.registerBeanDefinition("annotationProcessor",
@@ -252,7 +251,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPublicPersistenceUnitSetter() {
void testPublicPersistenceUnitSetter() {
GenericApplicationContext gac = new GenericApplicationContext();
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
gac.registerBeanDefinition("annotationProcessor",
@@ -267,7 +266,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPublicPersistenceUnitSetterWithOverriding() {
void testPublicPersistenceUnitSetterWithOverriding() {
EntityManagerFactory mockEmf2 = mock();
GenericApplicationContext gac = new GenericApplicationContext();
@@ -285,7 +284,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPublicPersistenceUnitSetterWithUnitIdentifiedThroughBeanName() {
void testPublicPersistenceUnitSetterWithUnitIdentifiedThroughBeanName() {
EntityManagerFactory mockEmf2 = mock();
GenericApplicationContext gac = new GenericApplicationContext();
@@ -310,7 +309,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPublicPersistenceUnitSetterWithMultipleUnitsIdentifiedThroughUnitName() {
void testPublicPersistenceUnitSetterWithMultipleUnitsIdentifiedThroughUnitName() {
EntityManagerFactoryWithInfo mockEmf2 = mock();
given(mockEmf2.getPersistenceUnitName()).willReturn("Person");
@@ -335,7 +334,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPersistenceUnitsFromJndi() {
void testPersistenceUnitsFromJndi() {
EntityManager mockEm = mock();
given(mockEmf.createEntityManager()).willReturn(mockEm);
@@ -377,7 +376,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPersistenceUnitsFromJndiWithDefaultUnit() {
void testPersistenceUnitsFromJndiWithDefaultUnit() {
EntityManagerFactoryWithInfo mockEmf2 = mock();
Map<String, String> persistenceUnits = new HashMap<>();
@@ -407,7 +406,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testSinglePersistenceUnitFromJndi() {
void testSinglePersistenceUnitFromJndi() {
Map<String, String> persistenceUnits = new HashMap<>();
persistenceUnits.put("Person", "pu1");
ExpectedLookupTemplate jt = new ExpectedLookupTemplate();
@@ -432,7 +431,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPersistenceContextsFromJndi() {
void testPersistenceContextsFromJndi() {
EntityManager mockEm = mock();
EntityManager mockEm2 = mock();
EntityManager mockEm3 = mock();
@@ -472,7 +471,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPersistenceContextsFromJndiWithDefaultUnit() {
void testPersistenceContextsFromJndiWithDefaultUnit() {
EntityManager mockEm = mock();
EntityManager mockEm2 = mock();
EntityManager mockEm3 = mock();
@@ -513,7 +512,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testSinglePersistenceContextFromJndi() {
void testSinglePersistenceContextFromJndi() {
EntityManager mockEm = mock();
EntityManager mockEm2 = mock();
@@ -545,28 +544,28 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testFieldOfWrongTypeAnnotatedWithPersistenceUnit() {
void testFieldOfWrongTypeAnnotatedWithPersistenceUnit() {
PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor();
assertThatIllegalStateException().isThrownBy(() ->
pabpp.postProcessProperties(null, new FieldOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"));
}
@Test
public void testSetterOfWrongTypeAnnotatedWithPersistenceUnit() {
void testSetterOfWrongTypeAnnotatedWithPersistenceUnit() {
PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor();
assertThatIllegalStateException().isThrownBy(() ->
pabpp.postProcessProperties(null, new SetterOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"));
}
@Test
public void testSetterWithNoArgs() {
void testSetterWithNoArgs() {
PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor();
assertThatIllegalStateException().isThrownBy(() ->
pabpp.postProcessProperties(null, new SetterWithNoArgs(), "bean"));
}
@Test
public void testNoPropertiesPassedIn() {
void testNoPropertiesPassedIn() {
EntityManager mockEm = mock();
given(mockEmf.createEntityManager()).willReturn(mockEm);
@@ -577,7 +576,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPropertiesPassedIn() {
void testPropertiesPassedIn() {
Properties props = new Properties();
props.put("foo", "bar");
EntityManager mockEm = mock();
@@ -591,7 +590,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPropertiesForTransactionalEntityManager() {
void testPropertiesForTransactionalEntityManager() {
Properties props = new Properties();
props.put("foo", "bar");
EntityManager em = mock();
@@ -615,7 +614,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
* generate new EMs or not.
*/
@Test
public void testPropertiesForSharedEntityManager1() {
void testPropertiesForSharedEntityManager1() {
Properties props = new Properties();
props.put("foo", "bar");
EntityManager em = mock();
@@ -648,7 +647,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
public void testPropertiesForSharedEntityManager2() {
void testPropertiesForSharedEntityManager2() {
Properties props = new Properties();
props.put("foo", "bar");
EntityManager em = mock();
@@ -712,7 +711,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
private EntityManager em;
@Override
public Object getObject() throws Exception {
public Object getObject() {
return null;
}
@@ -868,7 +867,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
public static boolean closed;
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public Object invoke(Object proxy, Method method, Object[] args) {
if ("isOpen".equals(method.getName())) {
return true;
}

View File

@@ -35,10 +35,10 @@ import static org.mockito.Mockito.verify;
* @author Juergen Hoeller
* @author Phillip Webb
*/
public class SharedEntityManagerFactoryTests {
class SharedEntityManagerFactoryTests {
@Test
public void testValidUsage() {
void testValidUsage() {
Object o = new Object();
EntityManager mockEm = mock();