Skip to content
Advertisement

java.lang.NullPointerException at io.dropwizard.testing.junit5.DropwizardExtensionsSupport.beforeEach

I am trying to test a Dropwizard resource.

My test looks like this:

JavaScript

However, this gives the error message:

JavaScript

which is frankly uninformative. Can someone point out what is wrong here?

P/S Here is the CommonObjects constructor:

JavaScript

which also explains why I am creating the resource extension before each test case.

Advertisement

Answer

In the end, instead of using mocks, I created stubs extending from concrete classes.

For example, for ApplicationConfig, I created ApplicationConfigStub:

JavaScript

And for MyAppConfig, I created MyAppConfigStub:

JavaScript

Then, I used these stubs when initialising the ResourceExtension in the test class:

JavaScript

This would allow for the resource extension to be initialised at declaration even if we are calling methods in other dependencies during the initialisation.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement