Search in sources :

Example 16 with IterableProvider

use of org.glassfish.hk2.api.IterableProvider in project glassfish-hk2 by eclipse-ee4j.

the class ProvidesTest method testProvidesNullFromInstanceField.

/**
 * Verifies that {@code null} may be provided from an instance field annotated
 * with {@link Provides}.
 */
@Test
public void testProvidesNullFromInstanceField() {
    ServiceLocator locator = createAndPopulateServiceLocator();
    ServiceLocatorUtilities.addClasses(locator, ProvidesListener.class, ProvidesNull.class);
    IterableProvider<NullFromInstanceField> provider = locator.getService(new TypeLiteral<IterableProvider<NullFromInstanceField>>() {
    }.getType());
    try (ServiceHandle<NullFromInstanceField> handle = provider.getHandle()) {
        assertNull(handle.getService());
    }
}
Also used : ServiceLocatorUtilities.createAndPopulateServiceLocator(org.glassfish.hk2.utilities.ServiceLocatorUtilities.createAndPopulateServiceLocator) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) TypeLiteral(org.glassfish.hk2.api.TypeLiteral) Test(org.junit.Test)

Aggregations

ServiceLocator (org.glassfish.hk2.api.ServiceLocator)16 Test (org.junit.Test)16 TypeLiteral (org.glassfish.hk2.api.TypeLiteral)15 ServiceLocatorUtilities.createAndPopulateServiceLocator (org.glassfish.hk2.utilities.ServiceLocatorUtilities.createAndPopulateServiceLocator)15 HashSet (java.util.HashSet)2 UnqualifiedImpl (org.glassfish.hk2.utilities.UnqualifiedImpl)1