Fix tests

See gh-18490
This commit is contained in:
Sam Brannen 2019-04-04 12:55:55 +02:00
parent 86fb7362b1
commit 07e9f802f2
9 changed files with 71 additions and 47 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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;
import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringRunner; 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.junit.Assert.*;
import static org.springframework.test.context.cache.ContextCacheTestUtils.*; import static org.springframework.test.context.cache.ContextCacheTestUtils.*;
@ -146,6 +150,14 @@ public class ClassLevelDirtiesContextTests {
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration @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 { static abstract class BaseTestCase {
@Configuration @Configuration

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringRunner; 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.junit.Assert.*;
import static org.springframework.test.context.cache.ContextCacheTestUtils.*; import static org.springframework.test.context.cache.ContextCacheTestUtils.*;
@ -72,6 +76,14 @@ public class DirtiesContextInterfaceTests {
@RunWith(SpringRunner.class) @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 public static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase
implements DirtiesContextTestInterface { implements DirtiesContextTestInterface {

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -85,7 +85,7 @@ public class DataSourceOnlySqlScriptsTests {
@Bean @Bean
public DataSource dataSource() { public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("empty-sql-scripts-without-tx-mgr-test-db")// .generateUniqueName(true)//
.build(); .build();
} }
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ public class EmptyDatabaseConfig {
@Bean @Bean
public DataSource dataSource() { public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("empty-sql-scripts-test-db")// .generateUniqueName(true)//
.build(); .build();
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -97,7 +97,7 @@ public class InferredDataSourceSqlScriptsTests {
@Bean @Bean
public DataSource dataSource1() { public DataSource dataSource1() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("database1")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build(); .build();
@ -106,7 +106,7 @@ public class InferredDataSourceSqlScriptsTests {
@Bean @Bean
public DataSource dataSource2() { public DataSource dataSource2() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("database2")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build(); .build();

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -100,7 +100,7 @@ public class InferredDataSourceTransactionalSqlScriptsTests {
@Bean @Bean
public DataSource dataSource1() { public DataSource dataSource1() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("database1")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build(); .build();
@ -109,7 +109,7 @@ public class InferredDataSourceTransactionalSqlScriptsTests {
@Bean @Bean
public DataSource dataSource2() { public DataSource dataSource2() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("database2")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build(); .build();

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -96,7 +96,7 @@ public class MultipleDataSourcesAndTransactionManagersSqlScriptsTests {
@Bean @Bean
public DataSource dataSource1() { public DataSource dataSource1() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("database1")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build(); .build();
@ -105,7 +105,7 @@ public class MultipleDataSourcesAndTransactionManagersSqlScriptsTests {
@Bean @Bean
public DataSource dataSource2() { public DataSource dataSource2() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("database2")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build(); .build();

View File

@ -97,7 +97,7 @@ public class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTes
@Bean @Bean
public DataSource dataSource1() { public DataSource dataSource1() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("database1")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build(); .build();
@ -106,7 +106,7 @@ public class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTes
@Bean @Bean
public DataSource dataSource2() { public DataSource dataSource2() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("database2")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")// .addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
.build(); .build();

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ public class PopulatedSchemaDatabaseConfig {
@Bean @Bean
public DataSource dataSource() { public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()// return new EmbeddedDatabaseBuilder()//
.setName("populated-sql-scripts-test-db")// .generateUniqueName(true)//
.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") // .addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
.build(); .build();
} }