title: Testing Jersey-Spring Integration with JerseyTest, Maven and TestNG
body: <p>I want to test my Jersey resources with the Jersey Test-Framework.</p>
  
  <p>I followed the descriptions provided here</p>
  
  <ul>
  <li><a href="http://blogs.oracle.com/naresh/entry/jersey_test_framework_makes_it" rel="nofollow">http://blogs.oracle.com/naresh/entry/jersey_test_framework_makes_it</a></li>
  <li><a href="http://zhanghaoeye.javaeye.com/blog/441759" rel="nofollow">http://zhanghaoeye.javaeye.com/blog/441759</a></li>
  </ul>
  
  <p>to create a simple example. My example is hosted as git repository on <a href="http://github.com/rmetzler/Jersey-Test" rel="nofollow">http://github.com/rmetzler/Jersey-Test</a> .</p>
  
  <p><code>$ mvn jetty:run</code> works as expected but I keep getting NullPointerExceptions when running <code>$ mvn clean test</code>.</p>
  
  <pre><code>java.lang.NullPointerException
  at com.sun.jersey.spi.container.ContainerResponse.mapException(ContainerResponse.java:429)
  at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1295)
  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
  at com.sun.jersey.test.framework.impl.container.inmemory.TestResourceClientHandler.handle(TestResourceClientHandler.java:119)
  at com.sun.jersey.api.client.Client.handle(Client.java:616)
  at com.sun.jersey.api.client.WebResource.handle(WebResource.java:559)
  at com.sun.jersey.api.client.WebResource.get(WebResource.java:182)
  at example.jersey.spring.MyResourceTest.testMyResource(MyResourceTest.java:30)
  ...
  </code></pre>
  
  <p>I bet I made a small mistake that I'm unable to find. I would show my source to another developer but unfortunately I work alone at home. So maybe someone of you could help me?</p>
  
  <h2>UPDATE</h2>
  
  <p>I created an Eclipse project by running <code>$ mvn eclipse:eclipse</code> . Now when I run the test as JUnit Test in Eclipse it is green. When running it as TestNG Test it fails. So I guess it has something to do with how the test is executed by TestNG.</p>