diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java index 77a8ac9265a..724a2ccb1d7 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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,11 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; +import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener; +import org.springframework.test.context.support.DirtiesContextTestExecutionListener; import static org.junit.Assert.*; import static org.springframework.test.context.cache.ContextCacheTestUtils.*; @@ -146,6 +150,14 @@ public class ClassLevelDirtiesContextTests { @RunWith(SpringRunner.class) @ContextConfiguration + // Ensure that we do not include the EventPublishingTestExecutionListener + // since it will access the ApplicationContext for each method in the + // TestExecutionListener API, thus distorting our cache hit/miss results. + @TestExecutionListeners({ + DirtiesContextBeforeModesTestExecutionListener.class, + DependencyInjectionTestExecutionListener.class, + DirtiesContextTestExecutionListener.class + }) static abstract class BaseTestCase { @Configuration diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java index 85f966da9d8..767fb9f60ca 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/DirtiesContextInterfaceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -27,7 +27,11 @@ import org.junit.runners.JUnit4; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; +import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener; +import org.springframework.test.context.support.DirtiesContextTestExecutionListener; import static org.junit.Assert.*; import static org.springframework.test.context.cache.ContextCacheTestUtils.*; @@ -72,6 +76,14 @@ public class DirtiesContextInterfaceTests { @RunWith(SpringRunner.class) + // Ensure that we do not include the EventPublishingTestExecutionListener + // since it will access the ApplicationContext for each method in the + // TestExecutionListener API, thus distorting our cache hit/miss results. + @TestExecutionListeners({ + DirtiesContextBeforeModesTestExecutionListener.class, + DependencyInjectionTestExecutionListener.class, + DirtiesContextTestExecutionListener.class + }) public static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase implements DirtiesContextTestInterface { diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java index b9789cb08cf..801e6ea6cc6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/DataSourceOnlySqlScriptsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -85,8 +85,8 @@ public class DataSourceOnlySqlScriptsTests { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder()// - .setName("empty-sql-scripts-without-tx-mgr-test-db")// - .build(); + .generateUniqueName(true)// + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java index 45f6db008bc..09e6c5c6360 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/EmptyDatabaseConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -41,8 +41,8 @@ public class EmptyDatabaseConfig { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder()// - .setName("empty-sql-scripts-test-db")// - .build(); + .generateUniqueName(true)// + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceSqlScriptsTests.java index 8c399df8081..5fa19734849 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceSqlScriptsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -97,19 +97,19 @@ public class InferredDataSourceSqlScriptsTests { @Bean public DataSource dataSource1() { return new EmbeddedDatabaseBuilder()// - .setName("database1")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } @Bean public DataSource dataSource2() { return new EmbeddedDatabaseBuilder()// - .setName("database2")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java index de563258262..63c5235f4a6 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/InferredDataSourceTransactionalSqlScriptsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -100,19 +100,19 @@ public class InferredDataSourceTransactionalSqlScriptsTests { @Bean public DataSource dataSource1() { return new EmbeddedDatabaseBuilder()// - .setName("database1")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } @Bean public DataSource dataSource2() { return new EmbeddedDatabaseBuilder()// - .setName("database2")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java index bfbd2991799..e5966bddb78 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 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. @@ -96,19 +96,19 @@ public class MultipleDataSourcesAndTransactionManagersSqlScriptsTests { @Bean public DataSource dataSource1() { return new EmbeddedDatabaseBuilder()// - .setName("database1")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } @Bean public DataSource dataSource2() { return new EmbeddedDatabaseBuilder()// - .setName("database2")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java index 4ca820441de..2ddf38ae1b8 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java @@ -97,19 +97,19 @@ public class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTes @Bean public DataSource dataSource1() { return new EmbeddedDatabaseBuilder()// - .setName("database1")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } @Bean public DataSource dataSource2() { return new EmbeddedDatabaseBuilder()// - .setName("database2")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// - .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// + .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// + .build(); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java index dee10825079..0c1cecf8822 100644 --- a/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java +++ b/spring-test/src/test/java/org/springframework/test/context/jdbc/PopulatedSchemaDatabaseConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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,9 +43,9 @@ public class PopulatedSchemaDatabaseConfig { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder()// - .setName("populated-sql-scripts-test-db")// - .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") // - .build(); + .generateUniqueName(true)// + .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") // + .build(); } @Bean