Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when using BEFORE_EACH_TEST_METHOD as InjectorCreationMode #372

Open
hmedkouri opened this issue Oct 6, 2017 · 0 comments

Comments

@hmedkouri
Copy link

hmedkouri commented Oct 6, 2017

Hi,

On the latest version 1.17.4 of governator-test-spock, several NullPointerException are thrown when using BEFORE_EACH_TEST_METHOD as InjectorCreationMode in Spock Spec.

Below are the stacktraces:

`
java.lang.NullPointerException
at com.netflix.governator.guice.test.AnnotationBasedTestInjectorManager.prepareTestFixture(AnnotationBasedTestInjectorManager.java:76)

java.lang.NullPointerException
at com.netflix.governator.guice.test.AnnotationBasedTestInjectorManager.cleanUpMethodLevelConfig(AnnotationBasedTestInjectorManager.java:86)

java.lang.NullPointerException
at com.netflix.governator.guice.test.AnnotationBasedTestInjectorManager.cleanUpInjector(AnnotationBasedTestInjectorManager.java:90)
`

To reproduce, one just need create and run the following spock test class:

@ModulesForTesting(injectorCreation = InjectorCreationMode.BEFORE_EACH_TEST_METHOD) class ExampleSpec extends Specification { def "dummy test"() { expect: 1 + 1 == 2 } }

The fix seems to be simple to implement, in GovernatorExtension the line of code below needs to be moved before calling prepareTestFixture.

if (InjectorCreationMode.BEFORE_EACH_TEST_METHOD == annotationBasedTestInjectorManager.getInjectorCreationMode()) { annotationBasedTestInjectorManager.createInjector(); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant