Use Map.computeIfAbsent() in SpringClassRule

Replace manual synchronization block in SpringClassRule with Java 8's
Map.computeIfAbsent().

Issue: SPR-12421
master
Sam Brannen 8 years ago
parent 1cf503f939
commit d9eaa5f3ac
  1. 9
      spring-test/src/main/java/org/springframework/test/context/junit4/rules/SpringClassRule.java

@ -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);
}

Loading…
Cancel
Save