Use Map.computeIfAbsent() in SpringClassRule
Replace manual synchronization block in SpringClassRule with Java 8's Map.computeIfAbsent(). Issue: SPR-12421
This commit is contained in:
@@ -210,14 +210,7 @@ public class SpringClassRule implements TestRule {
|
|||||||
*/
|
*/
|
||||||
static TestContextManager getTestContextManager(Class<?> testClass) {
|
static TestContextManager getTestContextManager(Class<?> testClass) {
|
||||||
Assert.notNull(testClass, "testClass must not be null");
|
Assert.notNull(testClass, "testClass must not be null");
|
||||||
synchronized (testContextManagerCache) {
|
return testContextManagerCache.computeIfAbsent(testClass, TestContextManager::new);
|
||||||
TestContextManager testContextManager = testContextManagerCache.get(testClass);
|
|
||||||
if (testContextManager == null) {
|
|
||||||
testContextManager = new TestContextManager(testClass);
|
|
||||||
testContextManagerCache.put(testClass, testContextManager);
|
|
||||||
}
|
|
||||||
return testContextManager;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user