use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class InjectionManagerTest method testIsRegistrable.
@Test
public void testIsRegistrable() {
InjectionManager injectionManager = new HK2InjectionManager();
assertTrue(injectionManager.isRegistrable(Binder.class));
assertTrue(injectionManager.isRegistrable(AbstractBinder.class));
assertFalse(injectionManager.isRegistrable(org.glassfish.jersey.internal.inject.AbstractBinder.class));
assertFalse(injectionManager.isRegistrable(String.class));
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class InjectionManagerTest method testRegisterBinder.
@Test
public void testRegisterBinder() {
AbstractBinder binder = new AbstractBinder() {
@Override
protected void configure() {
bindAsContract(EnglishGreeting.class);
}
};
InjectionManager injectionManager = new HK2InjectionManager();
injectionManager.initialize();
injectionManager.register(binder);
assertNotNull(injectionManager.getInstance(EnglishGreeting.class));
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ExceptionMapperFactoryTest method testFindMappingExtendedExceptions.
/**
* Test spec:
* <p/>
* setup:<br/>
* - have two extended exception mappers, order matters<br/>
* - both using the same generic type (RuntimeException)<br/>
* - first mapper return isMappable true only to IllegalArgumentException<br/>
* - second mapper return isMappable true only to IllegalStateException<br/>
* <br/>
* when:<br/>
* - {@link ExceptionMapperFactory#findMapping(Throwable)} with IllegalArgumentException instance<br/>
* <br/>
* then:<br/>
* - exception mapper factory returns IllegalArgumentExceptionMapper<br/>
* <p/>
* why:<br/>
* - IllegalArgumentException has the same distance (1) for both exception mappers generic type (RuntimeException),
* but IllegalArgumentException's isMappable return true, so it is the winner
*
* @throws Exception unexpected - if anything goes wrong, the test fails
*/
@Test
public void testFindMappingExtendedExceptions() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager(new ExtendedExceptionMappers());
final ExceptionMapperFactory mapperFactory = new ExceptionMapperFactory(injectionManager);
final ExceptionMapper mapper = mapperFactory.findMapping(new IllegalArgumentException());
Assert.assertTrue("IllegalArgumentExceptionMapper should be returned", mapper instanceof IllegalArgumentExceptionMapper);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ExceptionMapperFactoryTest method testFindMapping.
/**
* Test spec:
* <p/>
* setup:<br/>
* - have 3 exception mappers, order matters<br/>
* - first is *not* extended mapper typed to RuntimeException
* - second and third are extended mappers type to RuntimeException
* <br/>
* when:<br/>
* - {@link ExceptionMapperFactory#findMapping(Throwable)} invoked with RuntimeException instance<br/>
* then: <br/>
* - exception mapper factory returns RuntimeExceptionMapper<br/>
* <p/>
* why:<br/>
* - RuntimeException mapper has distance 0 for RuntimeException, it is not extended mapper, so it will be chosen
* immediately, cause there is no better option possible
*
* @throws Exception unexpected - if anything goes wrong, the test fails
*/
@Test
public void testFindMapping() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager(new AllMappers());
final ExceptionMapperFactory mapperFactory = new ExceptionMapperFactory(injectionManager);
final ExceptionMapper<RuntimeException> mapper = mapperFactory.findMapping(new RuntimeException());
Assert.assertTrue("RuntimeExceptionMapper should be returned", mapper instanceof RuntimeExceptionMapper);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ExceptionMapperFactoryTest method testFindExtendedExceptions.
/**
* Test spec: <br/>
* <p/>
* setup:<br/>
* - have 2 extended mappers, order matters<br/>
* - first mapper return isMappable true only to IllegalArgumentException<br/>
* - second mapper return isMappable true only to IllegalStateException<br/>
* <br/>
* when:<br/>
* - {@link ExceptionMapperFactory#find(Class)} invoked with IllegalArgumentException.class<br/>
* then:<br/>
* - exception mapper factory returns IllegalArgumentExceptionMapper<br/>
* <p/>
* why:<br/>
* - both exception mappers have distance 1 to IllegalArgumentException, we don't have instance of the
* IllegalArgumentException, so the isMappable check is not used and both are accepted, the later accepted is
* the winner
*
* @throws Exception unexpected - if anything goes wrong, the test fails
*/
@Test
public void testFindExtendedExceptions() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager(new ExtendedExceptionMappers());
final ExceptionMapperFactory mapperFactory = new ExceptionMapperFactory(injectionManager);
final ExceptionMapper mapper = mapperFactory.find(IllegalArgumentException.class);
Assert.assertTrue("IllegalStateExceptionMapper should be returned", mapper instanceof IllegalStateExceptionMapper);
}
Aggregations