Skip to content

Commit

Permalink
[Spring] Do not replace already registered scope
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Apr 8, 2022
1 parent d898b31 commit 2d67224
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.cucumber.core.backend.CucumberBackendException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.Scope;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.ConfigurableApplicationContext;
Expand Down Expand Up @@ -60,7 +61,13 @@ private void notifyTestContextManagerAboutBeforeTestMethod() {

final void registerGlueCodeScope(ConfigurableApplicationContext context) {
while (context != null) {
context.getBeanFactory().registerScope(SCOPE_CUCUMBER_GLUE, new CucumberScenarioScope());
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
// Scenario scope may have already been registered by another
// thread.
Scope registeredScope = beanFactory.getRegisteredScope(SCOPE_CUCUMBER_GLUE);
if (registeredScope == null) {
beanFactory.registerScope(SCOPE_CUCUMBER_GLUE, new CucumberScenarioScope());
}
context = (ConfigurableApplicationContext) context.getParent();
}
}
Expand Down

0 comments on commit 2d67224

Please sign in to comment.