Package com.github.jsr330.spi.config.builder

Examples of com.github.jsr330.spi.config.builder.BindingConditionsTest


   
    @Test
    public void singletonUsingStaticFactoryMethodWithoutParameters() {
        TypeConfig config = defaultBinder.instance(TestImplementation1.class).asSingleton(TestImplementation1.class)
                .using(factoryMethod(TestImplementation1.class)).build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestImplementation1.class, null, null, null);
        assertNotNull(container);
        assertEquals(TestImplementation1.class, container.getType());
        assertTrue(container.isSingleton());
        assertEquals(InstanceMode.FACTORY_METHOD, container.getInstanceMode());
        assertNull(container.getConstructor());
        assertEquals(factoryMethod(TestImplementation1.class), container.getFactoryMethod());
    }
View Full Code Here


   
    @Test
    public void singletonUsingStaticFactoryMethodWithParameters() {
        TypeConfig config = defaultBinder.instance(TestImplementation1.class).asSingleton(TestImplementation1.class)
                .using(factoryMethod(TestImplementation1.class, String.class, String.class)).build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestImplementation1.class, null, null, null);
        assertNotNull(container);
        assertEquals(TestImplementation1.class, container.getType());
        assertTrue(container.isSingleton());
        assertEquals(InstanceMode.FACTORY_METHOD, container.getInstanceMode());
        assertNull(container.getConstructor());
        assertEquals(factoryMethod(TestImplementation1.class, String.class, String.class), container.getFactoryMethod());
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    @Override
    public <V> TypeContainer getTypeContainer(ClassInjector injector, Class<V> type, Map<String, Class<? extends V>[]> inheritanceTree, Annotation qualifier,
            ClassLoader classLoader) {
        TypeContainerConfig<V> config = (TypeContainerConfig<V>) configs.get(type.getName());
        TypeContainer container;
       
        LOGGER.debug("getTypeContainer - type {}, qualifier {}", type, qualifier);
       
        if (config != null && (config.getImplementation() != null || config.getProvider() != null)) {
            LOGGER.debug("getTypeContainer - config exists");
            if (config.getCondition() != null && !config.getCondition().fulfilled(injector, type, inheritanceTree, qualifier, classLoader)) {
                LOGGER.debug("getTypeContainer - condition not fulfilled");
                return null;
            }
           
            container = new TypeContainer(null, null);
           
            if (config.getFactoryMethod() != null) {
                LOGGER.debug("getTypeContainer - using factory method");
                container.setType(config.getImplementation());
                container.gatherInformation();
                container.setSingleton(config.isSingleton());
               
                container.setInstanceMode(InstanceMode.FACTORY_METHOD);
                container.setFactoryMethod(config.getFactoryMethod());
                container.setConstructor(null);
                container.setProvider(null);
            } else if (config.getProvider() != null) {
                LOGGER.debug("getTypeContainer - using provider");
                container.setInstanceMode(InstanceMode.PROVIDER);
                container.setProvider(config.getProvider());
                container.setFactoryMethod(null);
                container.setConstructor(null);
            } else {
                LOGGER.debug("getTypeContainer - using constructor");
                container.setType(config.getImplementation());
                container.gatherInformation();
                container.setSingleton(config.isSingleton());
               
                container.setInstanceMode(InstanceMode.CONSTRUCTOR);
                container.setConstructor(config.getConstructor());
                container.setFactoryMethod(null);
                container.setProvider(null);
            }
           
            return container;
        }
       
View Full Code Here

    }
   
    @Test
    public void simpleBinding() {
        TypeConfig config = defaultBinder.instance(TestInterface.class).as(TestImplementation1.class).build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestInterface.class, null, null, null);
        assertNotNull(container);
        assertEquals(TestImplementation1.class, container.getType());
        assertFalse(container.isSingleton());
        assertEquals(InstanceMode.CONSTRUCTOR, container.getInstanceMode());
    }
View Full Code Here

    }
   
    @Test
    public void simpleBindingAsSingleton() {
        TypeConfig config = defaultBinder.instance(TestInterface.class).asSingleton(TestImplementation1.class).build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestInterface.class, null, null, null);
        assertNotNull(container);
        assertEquals(TestImplementation1.class, container.getType());
        assertTrue(container.isSingleton());
        assertEquals(InstanceMode.CONSTRUCTOR, container.getInstanceMode());
    }
View Full Code Here

    }
   
    @Test
    public void simpleTypeAsSingleton() {
        TypeConfig config = defaultBinder.instance(TestImplementation1.class).asSingleton().build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestImplementation1.class, null, null, null);
        assertNotNull(container);
        assertEquals(TestImplementation1.class, container.getType());
        assertTrue(container.isSingleton());
        assertEquals(InstanceMode.CONSTRUCTOR, container.getInstanceMode());
    }
View Full Code Here

    }
   
    @Test
    public void simpleType() {
        TypeConfig config = defaultBinder.instance(TestImplementation1.class).build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestImplementation1.class, null, null, null);
        assertNotNull(container);
        assertEquals(TestImplementation1.class, container.getType());
        assertFalse(container.isSingleton());
        assertEquals(InstanceMode.CONSTRUCTOR, container.getInstanceMode());
    }
View Full Code Here

    }
   
    @Test
    public void simpleTypeInheritance() {
        TypeConfig config = defaultBinder.instance(TestImplementation1.class).as(TestImplementation2.class).build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestImplementation1.class, null, null, null);
        assertNotNull(container);
        assertEquals(TestImplementation2.class, container.getType());
        assertFalse(container.isSingleton());
        assertEquals(InstanceMode.CONSTRUCTOR, container.getInstanceMode());
    }
View Full Code Here

            public TestInterface get() {
                return new TestImplementation1();
            }
           
        }).build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestInterface.class, null, null, null);
        assertNotNull(container);
        assertNotNull(container.getProvider());
        assertFalse(container.isSingleton());
        assertEquals(InstanceMode.PROVIDER, container.getInstanceMode());
    }
View Full Code Here

            public TestImplementation1 get() {
                return new TestImplementation1();
            }
           
        }).build();
        TypeContainer container;
       
        container = config.getTypeContainer(null, TestImplementation1.class, null, null, null);
        assertNotNull(container);
        assertNotNull(container.getProvider());
        assertFalse(container.isSingleton());
        assertEquals(InstanceMode.PROVIDER, container.getInstanceMode());
    }
View Full Code Here

TOP

Related Classes of com.github.jsr330.spi.config.builder.BindingConditionsTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.