Search in sources :

Example 1 with Provider

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());
}
Also used : Injectee(org.glassfish.hk2.api.Injectee) IterableProvider(org.glassfish.hk2.api.IterableProvider) Provider(jakarta.inject.Provider) Test(org.junit.Test)

Aggregations

Provider (jakarta.inject.Provider)1 Injectee (org.glassfish.hk2.api.Injectee)1 IterableProvider (org.glassfish.hk2.api.IterableProvider)1 Test (org.junit.Test)1