From 0e287c1a90513971aea03941a5fbfca48b089f20 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 18 Apr 2015 19:16:59 +0200 Subject: [PATCH] Introduce resetContextCache() in ContextCacheTestUtils --- .../test/context/ClassLevelDirtiesContextTestNGTests.java | 5 +++-- .../test/context/ClassLevelDirtiesContextTests.java | 5 +++-- .../test/context/ContextCacheTestUtils.java | 7 +++++++ .../test/context/SpringRunnerContextCacheTests.java | 3 +-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTestNGTests.java b/spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTestNGTests.java index 9009e73229a..528ef704503 100644 --- a/spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTestNGTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTestNGTests.java @@ -79,8 +79,9 @@ public class ClassLevelDirtiesContextTestNGTests { @BeforeClass public static void verifyInitialCacheState() { - ContextCache contextCache = TestContextManager.contextCache; - contextCache.reset(); + resetContextCache(); + // Reset static counters in case tests are run multiple times in a test suite -- + // for example, via JUnit's @Suite. cacheHits.set(0); cacheMisses.set(0); assertContextCacheStatistics("BeforeClass", 0, cacheHits.get(), cacheMisses.get()); diff --git a/spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTests.java b/spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTests.java index 1c51ad8072e..6a73bfa4e0c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTests.java @@ -74,8 +74,9 @@ public class ClassLevelDirtiesContextTests { @BeforeClass public static void verifyInitialCacheState() { - ContextCache contextCache = TestContextManager.contextCache; - contextCache.reset(); + resetContextCache(); + // Reset static counters in case tests are run multiple times in a test suite -- + // for example, via JUnit's @Suite. cacheHits.set(0); cacheMisses.set(0); assertContextCacheStatistics("BeforeClass", 0, cacheHits.get(), cacheMisses.get()); diff --git a/spring-test/src/test/java/org/springframework/test/context/ContextCacheTestUtils.java b/spring-test/src/test/java/org/springframework/test/context/ContextCacheTestUtils.java index dd5efcee1a4..3ffe61fe687 100644 --- a/spring-test/src/test/java/org/springframework/test/context/ContextCacheTestUtils.java +++ b/spring-test/src/test/java/org/springframework/test/context/ContextCacheTestUtils.java @@ -27,6 +27,13 @@ import static org.junit.Assert.*; */ public class ContextCacheTestUtils { + /** + * Reset the state of the context cache. + */ + public static final void resetContextCache() { + TestContextManager.contextCache.reset(); + } + /** * Assert the statistics of the context cache in {@link TestContextManager}. * diff --git a/spring-test/src/test/java/org/springframework/test/context/SpringRunnerContextCacheTests.java b/spring-test/src/test/java/org/springframework/test/context/SpringRunnerContextCacheTests.java index 3e09f2731e9..030bfa9e882 100644 --- a/spring-test/src/test/java/org/springframework/test/context/SpringRunnerContextCacheTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/SpringRunnerContextCacheTests.java @@ -58,8 +58,7 @@ public class SpringRunnerContextCacheTests { @BeforeClass public static void verifyInitialCacheState() { dirtiedApplicationContext = null; - ContextCache contextCache = TestContextManager.contextCache; - contextCache.reset(); + resetContextCache(); assertContextCacheStatistics("BeforeClass", 0, 0, 0); }