Migrate to Mockito.mock(T...) where feasible
This commit is contained in:
@@ -40,8 +40,8 @@ public abstract class AbstractEntityManagerFactoryBeanTests {
|
||||
protected static EntityManagerFactory mockEmf;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
mockEmf = mock(EntityManagerFactory.class);
|
||||
public void setUp() {
|
||||
mockEmf = mock();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
||||
@@ -49,8 +49,8 @@ public class DefaultJpaDialectTests {
|
||||
@Test
|
||||
public void testDefaultBeginTransaction() throws Exception {
|
||||
TransactionDefinition definition = new DefaultTransactionDefinition();
|
||||
EntityManager entityManager = mock(EntityManager.class);
|
||||
EntityTransaction entityTx = mock(EntityTransaction.class);
|
||||
EntityManager entityManager = mock();
|
||||
EntityTransaction entityTx = mock();
|
||||
|
||||
given(entityManager.getTransaction()).willReturn(entityTx);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class EntityManagerFactoryUtilsTests {
|
||||
// test null assertion
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
EntityManagerFactoryUtils.doGetTransactionalEntityManager(null, null));
|
||||
EntityManagerFactory factory = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory factory = mock();
|
||||
|
||||
// no tx active
|
||||
assertThat(EntityManagerFactoryUtils.doGetTransactionalEntityManager(factory, null)).isNull();
|
||||
@@ -66,8 +66,8 @@ public class EntityManagerFactoryUtilsTests {
|
||||
@Test
|
||||
public void testDoGetEntityManagerWithTx() throws Exception {
|
||||
try {
|
||||
EntityManagerFactory factory = mock(EntityManagerFactory.class);
|
||||
EntityManager manager = mock(EntityManager.class);
|
||||
EntityManagerFactory factory = mock();
|
||||
EntityManager manager = mock();
|
||||
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
given(factory.createEntityManager()).willReturn(manager);
|
||||
|
||||
@@ -53,26 +53,19 @@ import static org.mockito.Mockito.verify;
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public class JpaTransactionManagerTests {
|
||||
|
||||
private EntityManagerFactory factory;
|
||||
private EntityManagerFactory factory = mock();
|
||||
|
||||
private EntityManager manager;
|
||||
private EntityManager manager = mock();
|
||||
|
||||
private EntityTransaction tx;
|
||||
private EntityTransaction tx = mock();
|
||||
|
||||
private JpaTransactionManager tm;
|
||||
private JpaTransactionManager tm = new JpaTransactionManager(factory);
|
||||
|
||||
private TransactionTemplate tt;
|
||||
private TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
factory = mock(EntityManagerFactory.class);
|
||||
manager = mock(EntityManager.class);
|
||||
tx = mock(EntityTransaction.class);
|
||||
|
||||
tm = new JpaTransactionManager(factory);
|
||||
tt = new TransactionTemplate(tm);
|
||||
|
||||
given(factory.createEntityManager()).willReturn(manager);
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
@@ -448,8 +441,8 @@ public class JpaTransactionManagerTests {
|
||||
public void testTransactionWithRequiresNewInAfterCompletion() {
|
||||
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
|
||||
EntityManager manager2 = mock(EntityManager.class);
|
||||
EntityTransaction tx2 = mock(EntityTransaction.class);
|
||||
EntityManager manager2 = mock();
|
||||
EntityTransaction tx2 = mock();
|
||||
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
given(factory.createEntityManager()).willReturn(manager, manager2);
|
||||
|
||||
@@ -101,7 +101,7 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
|
||||
@Test
|
||||
public void testApplicationManagedEntityManagerWithoutTransaction() throws Exception {
|
||||
Object testEntity = new Object();
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
|
||||
given(mockEmf.createEntityManager()).willReturn(mockEm);
|
||||
|
||||
@@ -122,14 +122,14 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
|
||||
public void testApplicationManagedEntityManagerWithTransaction() throws Exception {
|
||||
Object testEntity = new Object();
|
||||
|
||||
EntityTransaction mockTx = mock(EntityTransaction.class);
|
||||
EntityTransaction mockTx = mock();
|
||||
|
||||
// This one's for the tx (shared)
|
||||
EntityManager sharedEm = mock(EntityManager.class);
|
||||
EntityManager sharedEm = mock();
|
||||
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
|
||||
|
||||
// This is the application-specific one
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
given(mockEm.getTransaction()).willReturn(mockTx);
|
||||
|
||||
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
|
||||
@@ -163,15 +163,15 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
|
||||
public void testApplicationManagedEntityManagerWithTransactionAndCommitException() throws Exception {
|
||||
Object testEntity = new Object();
|
||||
|
||||
EntityTransaction mockTx = mock(EntityTransaction.class);
|
||||
EntityTransaction mockTx = mock();
|
||||
willThrow(new OptimisticLockException()).given(mockTx).commit();
|
||||
|
||||
// This one's for the tx (shared)
|
||||
EntityManager sharedEm = mock(EntityManager.class);
|
||||
EntityManager sharedEm = mock();
|
||||
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
|
||||
|
||||
// This is the application-specific one
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
given(mockEm.getTransaction()).willReturn(mockTx);
|
||||
|
||||
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
|
||||
@@ -206,11 +206,11 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
|
||||
Object testEntity = new Object();
|
||||
|
||||
// This one's for the tx (shared)
|
||||
EntityManager sharedEm = mock(EntityManager.class);
|
||||
EntityManager sharedEm = mock();
|
||||
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
|
||||
|
||||
// This is the application-specific one
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
|
||||
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void transactionRequiredExceptionOnJoinTransaction() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
|
||||
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(
|
||||
em::joinTransaction);
|
||||
@@ -63,7 +63,7 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void transactionRequiredExceptionOnFlush() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
|
||||
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(
|
||||
em::flush);
|
||||
@@ -71,7 +71,7 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void transactionRequiredExceptionOnPersist() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
|
||||
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
|
||||
em.persist(new Object()));
|
||||
@@ -79,7 +79,7 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void transactionRequiredExceptionOnMerge() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
|
||||
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
|
||||
em.merge(new Object()));
|
||||
@@ -87,7 +87,7 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void transactionRequiredExceptionOnRemove() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
|
||||
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
|
||||
em.remove(new Object()));
|
||||
@@ -95,7 +95,7 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void transactionRequiredExceptionOnRefresh() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
|
||||
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() ->
|
||||
em.refresh(new Object()));
|
||||
@@ -103,9 +103,9 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void deferredQueryWithUpdate() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManager targetEm = mock(EntityManager.class);
|
||||
Query query = mock(Query.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager targetEm = mock();
|
||||
Query query = mock();
|
||||
given(emf.createEntityManager()).willReturn(targetEm);
|
||||
given(targetEm.createQuery("x")).willReturn(query);
|
||||
given(targetEm.isOpen()).willReturn(true);
|
||||
@@ -119,9 +119,9 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void deferredQueryWithSingleResult() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManager targetEm = mock(EntityManager.class);
|
||||
Query query = mock(Query.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager targetEm = mock();
|
||||
Query query = mock();
|
||||
given(emf.createEntityManager()).willReturn(targetEm);
|
||||
given(targetEm.createQuery("x")).willReturn(query);
|
||||
given(targetEm.isOpen()).willReturn(true);
|
||||
@@ -135,9 +135,9 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void deferredQueryWithResultList() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManager targetEm = mock(EntityManager.class);
|
||||
Query query = mock(Query.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager targetEm = mock();
|
||||
Query query = mock();
|
||||
given(emf.createEntityManager()).willReturn(targetEm);
|
||||
given(targetEm.createQuery("x")).willReturn(query);
|
||||
given(targetEm.isOpen()).willReturn(true);
|
||||
@@ -151,9 +151,9 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void deferredQueryWithResultStream() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManager targetEm = mock(EntityManager.class);
|
||||
Query query = mock(Query.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager targetEm = mock();
|
||||
Query query = mock();
|
||||
given(emf.createEntityManager()).willReturn(targetEm);
|
||||
given(targetEm.createQuery("x")).willReturn(query);
|
||||
given(targetEm.isOpen()).willReturn(true);
|
||||
@@ -167,9 +167,9 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void deferredStoredProcedureQueryWithIndexedParameters() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManager targetEm = mock(EntityManager.class);
|
||||
StoredProcedureQuery query = mock(StoredProcedureQuery.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager targetEm = mock();
|
||||
StoredProcedureQuery query = mock();
|
||||
given(emf.createEntityManager()).willReturn(targetEm);
|
||||
given(targetEm.createStoredProcedureQuery("x")).willReturn(query);
|
||||
willReturn("y").given(query).getOutputParameterValue(0);
|
||||
@@ -198,9 +198,9 @@ public class SharedEntityManagerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void deferredStoredProcedureQueryWithNamedParameters() {
|
||||
EntityManagerFactory emf = mock(EntityManagerFactory.class);
|
||||
EntityManager targetEm = mock(EntityManager.class);
|
||||
StoredProcedureQuery query = mock(StoredProcedureQuery.class);
|
||||
EntityManagerFactory emf = mock();
|
||||
EntityManager targetEm = mock();
|
||||
StoredProcedureQuery query = mock();
|
||||
given(emf.createEntityManager()).willReturn(targetEm);
|
||||
given(targetEm.createStoredProcedureQuery("x")).willReturn(query);
|
||||
willReturn("y").given(query).getOutputParameterValue("a");
|
||||
|
||||
@@ -142,7 +142,7 @@ class PersistenceManagedTypesBeanRegistrationAotProcessorTests {
|
||||
|
||||
@Bean
|
||||
public DataSource mockDataSource() {
|
||||
return mock(DataSource.class);
|
||||
return mock();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -62,30 +62,23 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class OpenEntityManagerInViewTests {
|
||||
|
||||
private EntityManager manager;
|
||||
|
||||
private EntityManagerFactory factory;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
private ServletWebRequest webRequest;
|
||||
|
||||
private final TestTaskExecutor taskExecutor = new TestTaskExecutor();
|
||||
|
||||
private EntityManager manager = mock();
|
||||
|
||||
private EntityManagerFactory factory = mock();
|
||||
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
private MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
private ServletWebRequest webRequest = new ServletWebRequest(this.request);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
factory = mock(EntityManagerFactory.class);
|
||||
manager = mock(EntityManager.class);
|
||||
|
||||
given(factory.createEntityManager()).willReturn(manager);
|
||||
|
||||
this.request = new MockHttpServletRequest();
|
||||
this.request.setAsyncSupported(true);
|
||||
this.response = new MockHttpServletResponse();
|
||||
this.webRequest = new ServletWebRequest(this.request);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -273,8 +266,8 @@ public class OpenEntityManagerInViewTests {
|
||||
public void testOpenEntityManagerInViewFilter() throws Exception {
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
final EntityManagerFactory factory2 = mock(EntityManagerFactory.class);
|
||||
final EntityManager manager2 = mock(EntityManager.class);
|
||||
final EntityManagerFactory factory2 = mock();
|
||||
final EntityManager manager2 = mock();
|
||||
|
||||
given(factory2.createEntityManager()).willReturn(manager2);
|
||||
given(manager2.isOpen()).willReturn(true);
|
||||
@@ -327,8 +320,8 @@ public class OpenEntityManagerInViewTests {
|
||||
public void testOpenEntityManagerInViewFilterAsyncScenario() throws Exception {
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
final EntityManagerFactory factory2 = mock(EntityManagerFactory.class);
|
||||
final EntityManager manager2 = mock(EntityManager.class);
|
||||
final EntityManagerFactory factory2 = mock();
|
||||
final EntityManager manager2 = mock();
|
||||
|
||||
given(factory2.createEntityManager()).willReturn(manager2);
|
||||
given(manager2.isOpen()).willReturn(true);
|
||||
@@ -368,7 +361,7 @@ public class OpenEntityManagerInViewTests {
|
||||
|
||||
FilterChain filterChain3 = new PassThroughFilterChain(filter2, filterChain2);
|
||||
|
||||
AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);
|
||||
AsyncWebRequest asyncWebRequest = mock();
|
||||
given(asyncWebRequest.isAsyncStarted()).willReturn(true);
|
||||
|
||||
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
|
||||
|
||||
@@ -70,7 +70,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests {
|
||||
void processAheadOfTimeWhenPersistenceUnitOnPublicField() {
|
||||
RegisteredBean registeredBean = registerBean(DefaultPersistenceUnitField.class);
|
||||
testCompile(registeredBean, (actual, compiled) -> {
|
||||
EntityManagerFactory entityManagerFactory = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory entityManagerFactory = mock();
|
||||
this.beanFactory.registerSingleton("entityManagerFactory",
|
||||
entityManagerFactory);
|
||||
DefaultPersistenceUnitField instance = new DefaultPersistenceUnitField();
|
||||
@@ -85,7 +85,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests {
|
||||
void processAheadOfTimeWhenPersistenceUnitOnPublicSetter() {
|
||||
RegisteredBean registeredBean = registerBean(DefaultPersistenceUnitMethod.class);
|
||||
testCompile(registeredBean, (actual, compiled) -> {
|
||||
EntityManagerFactory entityManagerFactory = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory entityManagerFactory = mock();
|
||||
this.beanFactory.registerSingleton("entityManagerFactory",
|
||||
entityManagerFactory);
|
||||
DefaultPersistenceUnitMethod instance = new DefaultPersistenceUnitMethod();
|
||||
@@ -101,7 +101,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests {
|
||||
RegisteredBean registeredBean = registerBean(
|
||||
CustomUnitNamePublicPersistenceUnitMethod.class);
|
||||
testCompile(registeredBean, (actual, compiled) -> {
|
||||
EntityManagerFactory entityManagerFactory = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory entityManagerFactory = mock();
|
||||
this.beanFactory.registerSingleton("custom", entityManagerFactory);
|
||||
CustomUnitNamePublicPersistenceUnitMethod instance = new CustomUnitNamePublicPersistenceUnitMethod();
|
||||
actual.accept(registeredBean, instance);
|
||||
@@ -118,7 +118,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests {
|
||||
RegisteredBean registeredBean = registerBean(
|
||||
DefaultPersistenceContextField.class);
|
||||
testCompile(registeredBean, (actual, compiled) -> {
|
||||
EntityManagerFactory entityManagerFactory = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory entityManagerFactory = mock();
|
||||
this.beanFactory.registerSingleton("entityManagerFactory",
|
||||
entityManagerFactory);
|
||||
DefaultPersistenceContextField instance = new DefaultPersistenceContextField();
|
||||
@@ -139,7 +139,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests {
|
||||
RegisteredBean registeredBean = registerBean(
|
||||
CustomPropertiesPersistenceContextMethod.class);
|
||||
testCompile(registeredBean, (actual, compiled) -> {
|
||||
EntityManagerFactory entityManagerFactory = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory entityManagerFactory = mock();
|
||||
this.beanFactory.registerSingleton("entityManagerFactory",
|
||||
entityManagerFactory);
|
||||
CustomPropertiesPersistenceContextMethod instance = new CustomPropertiesPersistenceContextMethod();
|
||||
@@ -172,7 +172,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests {
|
||||
PersistenceAnnotationBeanPostProcessor postProcessor = new PersistenceAnnotationBeanPostProcessor();
|
||||
BeanRegistrationAotContribution contribution = postProcessor
|
||||
.processAheadOfTime(registeredBean);
|
||||
BeanRegistrationCode beanRegistrationCode = mock(BeanRegistrationCode.class);
|
||||
BeanRegistrationCode beanRegistrationCode = mock();
|
||||
contribution.applyTo(generationContext, beanRegistrationCode);
|
||||
generationContext.writeGeneratedContent();
|
||||
TestCompiler.forSystem().with(generationContext)
|
||||
|
||||
@@ -42,33 +42,25 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.1.2
|
||||
*/
|
||||
public class PersistenceContextTransactionTests {
|
||||
class PersistenceContextTransactionTests {
|
||||
|
||||
private EntityManagerFactory factory;
|
||||
private EntityManagerFactory factory = mock();
|
||||
|
||||
private EntityManager manager;
|
||||
private EntityManager manager = mock();
|
||||
|
||||
private EntityTransaction tx;
|
||||
private EntityTransaction tx = mock();
|
||||
|
||||
private TransactionTemplate tt;
|
||||
private TransactionTemplate tt = new TransactionTemplate(new JpaTransactionManager(factory));
|
||||
|
||||
private EntityManagerHoldingBean bean;
|
||||
private EntityManagerHoldingBean bean = new EntityManagerHoldingBean();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
factory = mock(EntityManagerFactory.class);
|
||||
manager = mock(EntityManager.class);
|
||||
tx = mock(EntityTransaction.class);
|
||||
|
||||
JpaTransactionManager tm = new JpaTransactionManager(factory);
|
||||
tt = new TransactionTemplate(tm);
|
||||
|
||||
void setup() {
|
||||
given(factory.createEntityManager()).willReturn(manager);
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
bean = new EntityManagerHoldingBean();
|
||||
@SuppressWarnings("serial")
|
||||
PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() {
|
||||
@Override
|
||||
@@ -83,7 +75,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void clear() {
|
||||
void clear() {
|
||||
assertThat(TransactionSynchronizationManager.getResourceMap().isEmpty()).isTrue();
|
||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();
|
||||
assertThat(TransactionSynchronizationManager.isCurrentTransactionReadOnly()).isFalse();
|
||||
@@ -92,7 +84,7 @@ public class PersistenceContextTransactionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithSharedEntityManager() {
|
||||
void testTransactionCommitWithSharedEntityManager() {
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
|
||||
tt.execute(status -> {
|
||||
@@ -106,7 +98,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithSharedEntityManagerAndPropagationSupports() {
|
||||
void testTransactionCommitWithSharedEntityManagerAndPropagationSupports() {
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
|
||||
@@ -121,7 +113,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithExtendedEntityManager() {
|
||||
void testTransactionCommitWithExtendedEntityManager() {
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
|
||||
tt.execute(status -> {
|
||||
@@ -135,7 +127,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithExtendedEntityManagerAndPropagationSupports() {
|
||||
void testTransactionCommitWithExtendedEntityManagerAndPropagationSupports() {
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
|
||||
@@ -149,7 +141,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithSharedEntityManagerUnsynchronized() {
|
||||
void testTransactionCommitWithSharedEntityManagerUnsynchronized() {
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
|
||||
tt.execute(status -> {
|
||||
@@ -163,7 +155,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithSharedEntityManagerUnsynchronizedAndPropagationSupports() {
|
||||
void testTransactionCommitWithSharedEntityManagerUnsynchronizedAndPropagationSupports() {
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
|
||||
@@ -178,7 +170,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithExtendedEntityManagerUnsynchronized() {
|
||||
void testTransactionCommitWithExtendedEntityManagerUnsynchronized() {
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
|
||||
tt.execute(status -> {
|
||||
@@ -192,7 +184,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedAndPropagationSupports() {
|
||||
void testTransactionCommitWithExtendedEntityManagerUnsynchronizedAndPropagationSupports() {
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
|
||||
@@ -206,7 +198,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithSharedEntityManagerUnsynchronizedJoined() {
|
||||
void testTransactionCommitWithSharedEntityManagerUnsynchronizedJoined() {
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
|
||||
tt.execute(status -> {
|
||||
@@ -221,7 +213,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoined() {
|
||||
void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoined() {
|
||||
given(manager.getTransaction()).willReturn(tx);
|
||||
|
||||
tt.execute(status -> {
|
||||
@@ -236,7 +228,7 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoinedAndPropagationSupports() {
|
||||
void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoinedAndPropagationSupports() {
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
|
||||
@@ -251,19 +243,19 @@ public class PersistenceContextTransactionTests {
|
||||
}
|
||||
|
||||
|
||||
public static class EntityManagerHoldingBean {
|
||||
static class EntityManagerHoldingBean {
|
||||
|
||||
@PersistenceContext
|
||||
public EntityManager sharedEntityManager;
|
||||
EntityManager sharedEntityManager;
|
||||
|
||||
@PersistenceContext(type = PersistenceContextType.EXTENDED)
|
||||
public EntityManager extendedEntityManager;
|
||||
EntityManager extendedEntityManager;
|
||||
|
||||
@PersistenceContext(synchronization = SynchronizationType.UNSYNCHRONIZED)
|
||||
public EntityManager sharedEntityManagerUnsynchronized;
|
||||
EntityManager sharedEntityManagerUnsynchronized;
|
||||
|
||||
@PersistenceContext(type = PersistenceContextType.EXTENDED, synchronization = SynchronizationType.UNSYNCHRONIZED)
|
||||
public EntityManager extendedEntityManagerUnsynchronized;
|
||||
EntityManager extendedEntityManagerUnsynchronized;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPublicExtendedPersistenceContextSetter() {
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
given(mockEmf.createEntityManager()).willReturn(mockEm);
|
||||
|
||||
GenericApplicationContext gac = new GenericApplicationContext();
|
||||
@@ -123,8 +123,8 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPublicSpecificExtendedPersistenceContextSetter() {
|
||||
EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);
|
||||
EntityManager mockEm2 = mock(EntityManager.class);
|
||||
EntityManagerFactory mockEmf2 = mock();
|
||||
EntityManager mockEm2 = mock();
|
||||
given(mockEmf2.createEntityManager()).willReturn(mockEm2);
|
||||
|
||||
GenericApplicationContext gac = new GenericApplicationContext();
|
||||
@@ -146,7 +146,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testInjectionIntoExistingObjects() {
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
given(mockEmf.createEntityManager()).willReturn(mockEm);
|
||||
|
||||
GenericApplicationContext gac = new GenericApplicationContext();
|
||||
@@ -197,7 +197,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
public void testPublicExtendedPersistenceContextSetterWithEntityManagerInfoAndSerialization() throws Exception {
|
||||
EntityManager mockEm = mock(EntityManager.class, withSettings().serializable());
|
||||
given(mockEm.isOpen()).willReturn(true);
|
||||
EntityManagerFactoryWithInfo mockEmf = mock(EntityManagerFactoryWithInfo.class);
|
||||
EntityManagerFactoryWithInfo mockEmf = mock();
|
||||
given(mockEmf.getJpaDialect()).willReturn(new DefaultJpaDialect());
|
||||
given(mockEmf.getEntityManagerInterface()).willReturn((Class) EntityManager.class);
|
||||
given(mockEmf.getBeanClassLoader()).willReturn(getClass().getClassLoader());
|
||||
@@ -219,7 +219,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPublicExtendedPersistenceContextSetterWithOverriding() {
|
||||
EntityManager mockEm2 = mock(EntityManager.class);
|
||||
EntityManager mockEm2 = mock();
|
||||
|
||||
GenericApplicationContext gac = new GenericApplicationContext();
|
||||
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
|
||||
@@ -267,7 +267,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPublicPersistenceUnitSetterWithOverriding() {
|
||||
EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory mockEmf2 = mock();
|
||||
|
||||
GenericApplicationContext gac = new GenericApplicationContext();
|
||||
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
|
||||
@@ -285,7 +285,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPublicPersistenceUnitSetterWithUnitIdentifiedThroughBeanName() {
|
||||
EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory mockEmf2 = mock();
|
||||
|
||||
GenericApplicationContext gac = new GenericApplicationContext();
|
||||
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
|
||||
@@ -310,7 +310,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPublicPersistenceUnitSetterWithMultipleUnitsIdentifiedThroughUnitName() {
|
||||
EntityManagerFactoryWithInfo mockEmf2 = mock(EntityManagerFactoryWithInfo.class);
|
||||
EntityManagerFactoryWithInfo mockEmf2 = mock();
|
||||
given(mockEmf2.getPersistenceUnitName()).willReturn("Person");
|
||||
|
||||
GenericApplicationContext gac = new GenericApplicationContext();
|
||||
@@ -335,10 +335,10 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPersistenceUnitsFromJndi() {
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
given(mockEmf.createEntityManager()).willReturn(mockEm);
|
||||
|
||||
EntityManagerFactoryWithInfo mockEmf2 = mock(EntityManagerFactoryWithInfo.class);
|
||||
EntityManagerFactoryWithInfo mockEmf2 = mock();
|
||||
|
||||
Map<String, String> persistenceUnits = new HashMap<>();
|
||||
persistenceUnits.put("", "pu1");
|
||||
@@ -377,7 +377,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPersistenceUnitsFromJndiWithDefaultUnit() {
|
||||
EntityManagerFactoryWithInfo mockEmf2 = mock(EntityManagerFactoryWithInfo.class);
|
||||
EntityManagerFactoryWithInfo mockEmf2 = mock();
|
||||
|
||||
Map<String, String> persistenceUnits = new HashMap<>();
|
||||
persistenceUnits.put("System", "pu1");
|
||||
@@ -432,9 +432,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPersistenceContextsFromJndi() {
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm2 = mock(EntityManager.class);
|
||||
EntityManager mockEm3 = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
EntityManager mockEm2 = mock();
|
||||
EntityManager mockEm3 = mock();
|
||||
|
||||
Map<String, String> persistenceContexts = new HashMap<>();
|
||||
persistenceContexts.put("", "pc1");
|
||||
@@ -472,9 +472,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testPersistenceContextsFromJndiWithDefaultUnit() {
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm2 = mock(EntityManager.class);
|
||||
EntityManager mockEm3 = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
EntityManager mockEm2 = mock();
|
||||
EntityManager mockEm3 = mock();
|
||||
|
||||
Map<String, String> persistenceContexts = new HashMap<>();
|
||||
persistenceContexts.put("System", "pc1");
|
||||
@@ -513,8 +513,8 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testSinglePersistenceContextFromJndi() {
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm2 = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
EntityManager mockEm2 = mock();
|
||||
|
||||
Map<String, String> persistenceContexts = new HashMap<>();
|
||||
persistenceContexts.put("System", "pc1");
|
||||
@@ -566,7 +566,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
|
||||
@Test
|
||||
public void testNoPropertiesPassedIn() {
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
given(mockEmf.createEntityManager()).willReturn(mockEm);
|
||||
|
||||
PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor();
|
||||
@@ -579,7 +579,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
public void testPropertiesPassedIn() {
|
||||
Properties props = new Properties();
|
||||
props.put("foo", "bar");
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
given(mockEmf.createEntityManager(props)).willReturn(mockEm);
|
||||
|
||||
PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor();
|
||||
@@ -593,7 +593,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
public void testPropertiesForTransactionalEntityManager() {
|
||||
Properties props = new Properties();
|
||||
props.put("foo", "bar");
|
||||
EntityManager em = mock(EntityManager.class);
|
||||
EntityManager em = mock();
|
||||
given(mockEmf.createEntityManager(props)).willReturn(em);
|
||||
given(em.getDelegate()).willReturn(new Object());
|
||||
given(em.isOpen()).willReturn(true);
|
||||
@@ -617,7 +617,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
public void testPropertiesForSharedEntityManager1() {
|
||||
Properties props = new Properties();
|
||||
props.put("foo", "bar");
|
||||
EntityManager em = mock(EntityManager.class);
|
||||
EntityManager em = mock();
|
||||
// only one call made - the first EM definition wins (in this case the one w/ the properties)
|
||||
given(mockEmf.createEntityManager(props)).willReturn(em);
|
||||
given(em.getDelegate()).willReturn(new Object());
|
||||
@@ -650,7 +650,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||
public void testPropertiesForSharedEntityManager2() {
|
||||
Properties props = new Properties();
|
||||
props.put("foo", "bar");
|
||||
EntityManager em = mock(EntityManager.class);
|
||||
EntityManager em = mock();
|
||||
// only one call made - the first EM definition wins (in this case the one w/o the properties)
|
||||
given(mockEmf.createEntityManager()).willReturn(em);
|
||||
given(em.getDelegate()).willReturn(new Object(), 2);
|
||||
|
||||
@@ -41,10 +41,10 @@ public class SharedEntityManagerFactoryTests {
|
||||
public void testValidUsage() {
|
||||
Object o = new Object();
|
||||
|
||||
EntityManager mockEm = mock(EntityManager.class);
|
||||
EntityManager mockEm = mock();
|
||||
given(mockEm.isOpen()).willReturn(true);
|
||||
|
||||
EntityManagerFactory mockEmf = mock(EntityManagerFactory.class);
|
||||
EntityManagerFactory mockEmf = mock();
|
||||
given(mockEmf.createEntityManager()).willReturn(mockEm);
|
||||
|
||||
SharedEntityManagerBean proxyFactoryBean = new SharedEntityManagerBean();
|
||||
|
||||
Reference in New Issue
Block a user