I was able to resolve this issue. I had to make sure that there was an exclusion for junit in the dropwizard-test dependency.
Then I had to update my test class to import the JUnit5 classes and make sure that the test class was annotated with @ExtendWith (DropwizardExtensionsSupport.class) This information seems like it should be updated in the documentation, explicitly here: https://www.dropwizard.io/en/stable/manual/testing.html#testing-resources I will submit a PR to update this. Regards, William On Wednesday, December 25, 2019 at 9:45:39 PM UTC-5, William Herbert wrote: > > I am attempting to upgrade to 2.0.0 but am having difficulty making > ResourceExtension work for me. > > I'm following the example that is in dropwizard-example and have this: > > private static final ResourceExtension RESOURCE = ResourceExtension.builder() > .addResource(new GamingResource(dao)) > .build(); > > > What happens when that field is called in a test method (either way): > > RESOURCE.client()target("/vg/all").request().get(List.class); > > RESOURCE.target("/vg/all").request().get(List.class); > > > I receive a null pointer exception when the ResourceExtension attempts to > call client() or target(). > > > I know there are working unit tests for this class in the dropwizard-example > project, so I am wondering if the cause of my problem is a dependency or pom > issue. Below is the pom.xml file I have. I have attempted a number of > variations based on the pom.xml in dropwizard-example. > > > All suggestions would be appreciated. > > > <?xml version="1.0" encoding="UTF-8"?> > <project xmlns="http://maven.apache.org/POM/4.0.0" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 > http://maven.apache.org/xsd/maven-4.0.0.xsd"> > > <modelVersion>4.0.0</modelVersion> > <groupId>org.bilbert</groupId> > <artifactId>driftwood</artifactId> > <version>6.0.0</version> > <packaging>jar</packaging> > > <properties> > <dropwizard.version>2.0.0</dropwizard.version> > <spring.version>5.2.1.RELEASE</spring.version> > <jersey.version>2.29.1</jersey.version> > <junit5.version>5.5.2</junit5.version> > > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> > <maven.compiler.source>1.8</maven.compiler.source> > <maven.compiler.target>1.8</maven.compiler.target> > </properties> > > <dependencies> > <dependency> > <groupId>io.dropwizard</groupId> > <artifactId>dropwizard-core</artifactId> > <version>${dropwizard.version}</version> > </dependency> > > <dependency> > <groupId>io.dropwizard</groupId> > <artifactId>dropwizard-jdbi3</artifactId> > <version>${dropwizard.version}</version> > </dependency> > > <dependency> > <groupId>io.dropwizard</groupId> > <artifactId>dropwizard-client</artifactId> > <version>${dropwizard.version}</version> > </dependency> > > <dependency> > <groupId>io.dropwizard</groupId> > <artifactId>dropwizard-auth</artifactId> > <version>${dropwizard.version}</version> > </dependency> > > <dependency> > <groupId>io.dropwizard</groupId> > <artifactId>dropwizard-testing</artifactId> > <version>${dropwizard.version}</version> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>org.glassfish.jersey.test-framework.providers</groupId> > <artifactId>jersey-test-framework-provider-grizzly2</artifactId> > <version>${jersey.version}</version> > <exclusions> > <exclusion> > <groupId>javax.servlet</groupId> > <artifactId>javax.servlet-api</artifactId> > </exclusion> > <exclusion> > <groupId>junit</groupId> > <artifactId>junit</artifactId> > </exclusion> > </exclusions> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>mysql</groupId> > <artifactId>mysql-connector-java</artifactId> > <version>5.1.31</version> > </dependency> > > <dependency> > <groupId>com.javadocmd</groupId> > <artifactId>simplelatlng</artifactId> > <version>1.3.0</version> > </dependency> > > <dependency> > <groupId>com.h2database</groupId> > <artifactId>h2</artifactId> > <version>1.4.196</version> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>org.springframework</groupId> > <artifactId>spring-jdbc</artifactId> > <version>${spring.version}</version> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>org.springframework</groupId> > <artifactId>spring-test</artifactId> > <version>${spring.version}</version> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>org.springframework</groupId> > <artifactId>spring-context</artifactId> > <version>${spring.version}</version> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>org.apache.commons</groupId> > <artifactId>commons-lang3</artifactId> > <version>3.3.2</version> > </dependency> > > <dependency> > <groupId>org.mockito</groupId> > <artifactId>mockito-core</artifactId> > <version>3.2.0</version> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>org.jdbi</groupId> > <artifactId>jdbi3-spring4</artifactId> > <version>3.5.1</version> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>org.junit.jupiter</groupId> > <artifactId>junit-jupiter</artifactId> > <version>${junit5.version}</version> > <scope>test</scope> > </dependency> > > </dependencies> > > <build> > <plugins> > > <plugin> > <artifactId>maven-surefire-plugin</artifactId> > <version>2.22.2</version> > </plugin> > <plugin> > <artifactId>maven-failsafe-plugin</artifactId> > <version>2.22.2</version> > </plugin> > > > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-shade-plugin</artifactId> > <version>2.3</version> > <configuration> > <createDependencyReducedPom>true</createDependencyReducedPom> > <filters> > <filter> > <artifact>*:*</artifact> > <excludes> > <exclude>META-INF/*.SF</exclude> > <exclude>META-INF/*.DSA</exclude> > <exclude>META-INF/*.RSA</exclude> > </excludes> > </filter> > </filters> > </configuration> > <executions> > <execution> > <phase>package</phase> > <goals> > <goal>shade</goal> > </goals> > <configuration> > <transformers> > <transformer > > implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" > /> > <transformer > > implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> > > <mainClass>org.driftwood.application.DriftwoodService</mainClass> > </transformer> > </transformers> > </configuration> > </execution> > </executions> > </plugin> > > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-jar-plugin</artifactId> > <version>2.4</version> > <configuration> > <archive> > <manifest> > > <addDefaultImplementationEntries>true</addDefaultImplementationEntries> > </manifest> > </archive> > </configuration> > </plugin> > > <plugin> > <groupId>org.jacoco</groupId> > <artifactId>jacoco-maven-plugin</artifactId> > <version>0.7.5.201505241946</version> > > <configuration> > <destFile>target/coverage-reports/jacoco-unit.exec</destFile> > <dataFile>target/coverage-reports/jacoco-unit.exec</dataFile> > <excludes> > <exclude>org/driftwood/serializer/**/*</exclude> > </excludes> > </configuration> > <executions> > <execution> > <id>jacoco-initialize</id> > <goals> > <goal>prepare-agent</goal> > </goals> > </execution> > <execution> > <id>jacoco-site</id> > <phase>package</phase> > <goals> > <goal>report</goal> > </goals> > </execution> > </executions> > </plugin> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-compiler-plugin</artifactId> > <version>3.7.0</version> > <configuration> > <source>1.8</source> > <target>1.8</target> > </configuration> > > </plugin> > </plugins> > </build> > </project> > > -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dropwizard-user/720099d3-6f60-44e6-934b-0afab7826316%40googlegroups.com.
