use of jakarta.inject.Provider in project glassfish-hk2 by eclipse-ee4j.
the class ProviderTest method testInjecteeOfAProvider.
/**
* Tests that the descriptor returned from the injectee
* of something that injects Provider can be used
* in a getService call later
*/
@SuppressWarnings("unchecked")
@Test
public void testInjecteeOfAProvider() {
ActiveDescriptor<?> parentDescriptor = locator.getBestDescriptor(BuilderHelper.createContractFilter(ProviderInjectedPerLookup.class.getName()));
Assert.assertNotNull(parentDescriptor);
Injectee injectee = parentDescriptor.getInjectees().get(0);
Assert.assertNotNull(injectee);
ActiveDescriptor<?> childDescriptor = locator.getInjecteeDescriptor(injectee);
Assert.assertNotNull(childDescriptor);
ServiceHandle<?> handle = locator.getServiceHandle(childDescriptor, injectee);
Assert.assertNotNull(handle);
Object result = handle.getService();
Assert.assertTrue(result instanceof Provider);
Provider<PerLookupService> provider0 = (Provider<PerLookupService>) result;
Assert.assertNotNull(provider0.get());
Provider<PerLookupService> provider = (Provider<PerLookupService>) locator.getService(childDescriptor, null, injectee);
Assert.assertNotNull(provider);
Assert.assertNotNull(provider.get());
}
Aggregations