Migrate rest of test suite from JUnit 4 to JUnit Jupiter

This commit migrates the rest of Spring's test suite to JUnit Jupiter,
except spring-test which will be migrated in a separate commit.

See gh-23451
This commit is contained in:
Sam Brannen
2019-08-13 12:57:37 +02:00
parent 3df85c783f
commit 3f3e41923f
1487 changed files with 5428 additions and 4782 deletions

View File

@@ -23,7 +23,7 @@ import javax.persistence.FlushModeType;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.orm.jpa.domain.DriversLicense;
import org.springframework.orm.jpa.domain.Person;

View File

@@ -20,8 +20,8 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import javax.persistence.spi.PersistenceUnitInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -40,12 +40,12 @@ public abstract class AbstractEntityManagerFactoryBeanTests {
protected static EntityManagerFactory mockEmf;
@Before
@BeforeEach
public void setUp() throws Exception {
mockEmf = mock(EntityManagerFactory.class);
}
@After
@AfterEach
public void tearDown() throws Exception {
assertThat(TransactionSynchronizationManager.getResourceMap().isEmpty()).isTrue();
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();

View File

@@ -21,9 +21,9 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
import javax.sql.DataSource;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
@@ -87,7 +87,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
}
@Before
@BeforeEach
public void setup() {
if (applicationContext == null) {
applicationContext = new ClassPathXmlApplicationContext(getConfigLocations());
@@ -103,7 +103,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
return ECLIPSELINK_CONFIG_LOCATIONS;
}
@After
@AfterEach
public void cleanup() {
if (this.transactionStatus != null && !this.transactionStatus.isCompleted()) {
endTransaction();
@@ -115,7 +115,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isFalse();
}
@AfterClass
@AfterAll
public static void closeContext() {
if (applicationContext != null) {
applicationContext.close();

View File

@@ -22,7 +22,7 @@ import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TransactionRequiredException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.orm.jpa.domain.Person;

View File

@@ -23,7 +23,7 @@ import javax.persistence.PersistenceException;
import javax.persistence.Query;
import javax.persistence.TransactionRequiredException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;

View File

@@ -20,7 +20,7 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.OptimisticLockException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;

View File

@@ -16,7 +16,7 @@
package org.springframework.orm.jpa;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.verify;

View File

@@ -26,7 +26,7 @@ import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
import javax.persistence.TransactionRequiredException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;

View File

@@ -23,9 +23,9 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.RollbackException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.transaction.InvalidIsolationLevelException;
import org.springframework.transaction.TransactionDefinition;
@@ -64,7 +64,7 @@ public class JpaTransactionManagerTests {
private TransactionTemplate tt;
@Before
@BeforeEach
public void setup() {
factory = mock(EntityManagerFactory.class);
manager = mock(EntityManager.class);
@@ -78,7 +78,7 @@ public class JpaTransactionManagerTests {
given(manager.isOpen()).willReturn(true);
}
@After
@AfterEach
public void verifyTransactionSynchronizationManagerState() {
assertThat(TransactionSynchronizationManager.getResourceMap().isEmpty()).isTrue();
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();

View File

@@ -28,7 +28,7 @@ import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.persistence.spi.ProviderUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.dao.DataAccessException;

View File

@@ -23,8 +23,8 @@ import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.ProviderUtil;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
@@ -42,7 +42,7 @@ public class LocalEntityManagerFactoryBeanTests extends AbstractEntityManagerFac
private static Map actualProps;
@After
@AfterEach
public void verifyClosed() throws Exception {
verify(mockEmf).close();
}

View File

@@ -23,9 +23,9 @@ import javax.persistence.Query;
import javax.persistence.StoredProcedureQuery;
import javax.persistence.TransactionRequiredException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -43,7 +43,7 @@ import static org.mockito.Mockito.withSettings;
* @author Oliver Gierke
* @author Juergen Hoeller
*/
@RunWith(MockitoJUnitRunner.StrictStubs.class)
@ExtendWith(MockitoExtension.class)
public class SharedEntityManagerCreatorTests {
@Test

View File

@@ -17,7 +17,7 @@
package org.springframework.orm.jpa.eclipselink;
import org.eclipse.persistence.jpa.JpaEntityManager;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests;
import org.springframework.orm.jpa.EntityManagerFactoryInfo;

View File

@@ -21,7 +21,7 @@ import javax.persistence.EntityManager;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.target.SingletonTargetSource;

View File

@@ -19,7 +19,7 @@ package org.springframework.orm.jpa.hibernate;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests;

View File

@@ -21,7 +21,7 @@ import java.util.List;
import org.hibernate.FlushMode;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

View File

@@ -24,7 +24,7 @@ import org.hibernate.resource.beans.container.spi.ContainedBean;
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.service.ServiceRegistry;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -16,7 +16,7 @@
package org.springframework.orm.jpa.persistenceunit;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.index.CandidateComponentsTestClassLoader;
import org.springframework.core.io.ClassPathResource;

View File

@@ -24,8 +24,8 @@ import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -253,7 +253,7 @@ public class PersistenceXmlParsingTests {
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
@Ignore // not doing schema parsing anymore for JPA 2.0 compatibility
@Disabled // not doing schema parsing anymore for JPA 2.0 compatibility
@Test
public void testInvalidPersistence() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(
@@ -263,7 +263,7 @@ public class PersistenceXmlParsingTests {
reader.readPersistenceUnitInfos(resource));
}
@Ignore // not doing schema parsing anymore for JPA 2.0 compatibility
@Disabled // not doing schema parsing anymore for JPA 2.0 compatibility
@Test
public void testNoSchemaPersistence() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(

View File

@@ -28,9 +28,9 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.mock.web.test.MockAsyncContext;
@@ -75,7 +75,7 @@ public class OpenEntityManagerInViewTests {
private ServletWebRequest webRequest;
@Before
@BeforeEach
public void setUp() throws Exception {
factory = mock(EntityManagerFactory.class);
manager = mock(EntityManager.class);
@@ -88,7 +88,7 @@ public class OpenEntityManagerInViewTests {
this.webRequest = new ServletWebRequest(this.request);
}
@After
@AfterEach
public void tearDown() throws Exception {
assertThat(TransactionSynchronizationManager.getResourceMap().isEmpty()).isTrue();
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();

View File

@@ -23,9 +23,9 @@ import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.SynchronizationType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.JpaTransactionManager;
@@ -56,7 +56,7 @@ public class PersistenceContextTransactionTests {
private EntityManagerHoldingBean bean;
@Before
@BeforeEach
public void setup() {
factory = mock(EntityManagerFactory.class);
manager = mock(EntityManager.class);
@@ -83,7 +83,7 @@ public class PersistenceContextTransactionTests {
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();
}
@After
@AfterEach
public void clear() {
assertThat(TransactionSynchronizationManager.getResourceMap().isEmpty()).isTrue();
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();

View File

@@ -16,7 +16,7 @@
package org.springframework.orm.jpa.support;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.AbstractEntityManagerFactoryIntegrationTests;

View File

@@ -30,8 +30,8 @@ import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceProperty;
import javax.persistence.PersistenceUnit;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -336,7 +336,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
@Ignore
@Disabled
public void testPersistenceUnitsFromJndi() {
EntityManager mockEm = mock(EntityManager.class);
given(mockEmf.createEntityManager()).willReturn(mockEm);

View File

@@ -19,7 +19,7 @@ package org.springframework.orm.jpa.support;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.orm.jpa.EntityManagerHolder;
import org.springframework.orm.jpa.EntityManagerProxy;