File tree 3 files changed +12
-10
lines changed
main/java/io/cucumber/guice
test/java/io/cucumber/guice
3 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
19
### Fixed
20
20
- [ Pico] Improve performance ([ #2724 ] ( https://github.com/cucumber/cucumber-jvm/issues/2724 ) Julien Kronegg)
21
21
- [ JUnit 4] Fix swallowed exception ([ #2714 ] ( https://github.com/cucumber/cucumber-jvm/issues/2714 ) M.P. Korstanje)
22
+ - [ Guice] Fix NPE in Guice when configured incorrectly ([ #2716 ] ( https://github.com/cucumber/cucumber-jvm/issues/2716 ) M.P. Korstanje)
22
23
23
24
## [ 7.11.2] - 2023-03-23
24
25
### Fixed
Original file line number Diff line number Diff line change @@ -24,10 +24,11 @@ public final class GuiceFactory implements ObjectFactory {
24
24
25
25
private final Collection <Class <?>> stepClasses = new HashSet <>();
26
26
private final Class <?> injectorSourceFromProperty ;
27
- private Class <?> withInjectorSource = null ;
27
+ private Class <?> withInjectorSource ;
28
+ private ScenarioScope scenarioScope ;
28
29
29
30
public GuiceFactory () {
30
- injectorSourceFromProperty = loadInjectorSourceFromProperties (CucumberProperties .create ());
31
+ this . injectorSourceFromProperty = loadInjectorSourceFromProperties (CucumberProperties .create ());
31
32
}
32
33
33
34
@ Override
@@ -72,11 +73,15 @@ public void start() {
72
73
injector = new InjectorSourceFactory (withInjectorSource ).create ()
73
74
.getInjector ();
74
75
}
75
- injector .getInstance (ScenarioScope .class ).enterScope ();
76
+ scenarioScope = injector .getInstance (ScenarioScope .class );
77
+ scenarioScope .enterScope ();
76
78
}
77
79
78
80
public void stop () {
79
- injector .getInstance (ScenarioScope .class ).exitScope ();
81
+ if (scenarioScope != null ) {
82
+ scenarioScope .exitScope ();
83
+ scenarioScope = null ;
84
+ }
80
85
}
81
86
82
87
public <T > T getInstance (Class <T > clazz ) {
Original file line number Diff line number Diff line change 26
26
import static org .hamcrest .CoreMatchers .containsString ;
27
27
import static org .hamcrest .CoreMatchers .is ;
28
28
import static org .hamcrest .CoreMatchers .notNullValue ;
29
- import static org .hamcrest .CoreMatchers .startsWith ;
30
29
import static org .hamcrest .MatcherAssert .assertThat ;
31
- import static org .hamcrest .text .IsEqualCompressingWhiteSpace .equalToCompressingWhiteSpace ;
32
30
import static org .junit .jupiter .api .Assertions .assertThrows ;
33
31
import static org .junit .jupiter .api .Assertions .assertTrue ;
34
32
@@ -52,9 +50,8 @@ protected void configure() {
52
50
void tearDown () {
53
51
// If factory is left in start state it can cause cascading failures due
54
52
// to scope being left open
55
- try {
53
+ if ( factory != null ) {
56
54
factory .stop ();
57
- } catch (Exception ignored ) {
58
55
}
59
56
}
60
57
@@ -80,8 +77,7 @@ void factoryCanBeInstantiatedWithArgConstructor() {
80
77
void factoryStartFailsIfScenarioScopeIsNotBound () {
81
78
initFactory (Guice .createInjector ());
82
79
83
- Executable testMethod = () -> factory .start ();
84
- ConfigurationException actualThrown = assertThrows (ConfigurationException .class , testMethod );
80
+ ConfigurationException actualThrown = assertThrows (ConfigurationException .class , () -> factory .start ());
85
81
assertThat ("Unexpected exception message" , actualThrown .getMessage (),
86
82
containsString ("1) [Guice/MissingImplementation]: No implementation for ScenarioScope was bound." ));
87
83
}
You can’t perform that action at this time.
0 commit comments