Update: got it working.
While I was trying hard creating an AbstractBinder to satisfy HK2, i registered the binder using the class, i.e. register(MyBinder.class);. Turns out it does not work.
Instead I had to register(new MyBinder()); which did the trick. All fine now.
From: Matyas Bene [mailto:matyas.bene-mY8PkvhUYG9Wk0Htik3Jfirstname.lastname@example.org]
Sent: Thursday, October 23, 2014 3:10 PM
Subject: JerseyTest with a resource containing @Inject
After much trial and error while trying to test one of my JAX-RS resource using the JerseyTest framework (to be precise, I am extending JerseyTestNg.ContainerPerClassTest), I narrowed down my problem to the @Inject annotation. That is, whenever my resource contains at least 1 such field annotated with @Inject, any call to that resource inside the test framework fails with HTTP-500, even though that field is never used. Running the same resource in Glassfish certainly works as expected.
What would be the recommended way of testing such resources? Using jersey 2.9 (as shipped with Glassfish)
I also tried creating a ServletDeploymentContext, but in that, however, I received countless warnings from HK2, that injection points can not be satisfied.
Jersey 2.13 was a tad better. It did not crash with HTTP-500, but printed more meaningful exceptions (HK2 complaining about no object being available for injection) even without using ServletDeploymentContext. However, my test could not be run. Not sure how to tell HK2 that I either: donât need those fields, or where to find the for injection?