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:
Sam Brannen
2016-09-01 13:38:42 +02:00
parent 1cf503f939
commit d9eaa5f3ac

View File

@@ -210,14 +210,7 @@ public class SpringClassRule implements TestRule {
*/
static TestContextManager getTestContextManager(Class<?> testClass) {
Assert.notNull(testClass, "testClass must not be null");
synchronized (testContextManagerCache) {
TestContextManager testContextManager = testContextManagerCache.get(testClass);
if (testContextManager == null) {
testContextManager = new TestContextManager(testClass);
testContextManagerCache.put(testClass, testContextManager);
}
return testContextManager;
}
return testContextManagerCache.computeIfAbsent(testClass, TestContextManager::new);
}