All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.picocontainer.defaults.issues.Issue0354TestCase Maven / Gradle / Ivy

There is a newer version: 2.15
Show newest version
package org.picocontainer.defaults.issues;

import org.junit.Test;import static org.junit.Assert.assertFalse;import static org.junit.Assert.assertEquals;
import org.picocontainer.Startable;
import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.Characteristics;
import org.picocontainer.injectors.SetterInjection;
import org.picocontainer.behaviors.Cached;

import java.util.List;

public class Issue0354TestCase {

 	@Test
    public void testGenericInjectionWithSetterInjection() {
        DefaultPicoContainer pico = new DefaultPicoContainer(new SetterInjection());
        pico.addComponent(new Cod());
        pico.addComponent(new Shark());
        pico.addComponent(GenericBowl.class);
        //pico.addComponent(ArrayList.class);
        //pico.addComponent(ArrayList.class, ArrayList.class, new CollectionComponentParameter(Fish.class, false));

        GenericBowl bowl = pico.getComponent(GenericBowl.class);
        assertEquals(2, bowl.fishes.size());
    }

	@Test
    public void testGenericInjectionWithConstructorInjection() {
        DefaultPicoContainer pico = new DefaultPicoContainer();
        pico.addComponent(new Cod());
        pico.addComponent(new Shark());
        pico.addComponent(GenericBowl.class);

        GenericBowl bowl = pico.getComponent(GenericBowl.class);
        assertEquals(2, bowl.fishes.size());
    }

    public static interface Fish {
    }

    public static class Cod implements Fish {
    }

    public static class Shark implements Fish {
    }

    public static class GenericBowl {
        List fishes;

        public void setFishes(List fishes) {
            this.fishes = fishes;
        }

        public GenericBowl() {
        }

        public GenericBowl(List fishes) {
            this.fishes = fishes;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy