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

org.picocontainer.defaults.GenericsTestCase Maven / Gradle / Ivy

There is a newer version: 2.15
Show newest version
/*****************************************************************************
 * Copyright (C) PicoContainer Organization. All rights reserved.            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *                                                                           *
 * Original code by                                                          *
 *****************************************************************************/
package org.picocontainer.defaults;

import org.junit.Test;

/**
 * Uncomment all the tests in this class (as well as the obvious places in
 * ConstructorInjectionComponentAdapter) in order to run with generics support
 * Requires JDK 1.5 with generics enabled.
 * 
 * @author Aslak Hellesøy
 */
public class GenericsTestCase {
    @Test public void testDummy() {

    }

    /*
    private MutablePicoContainer pico;
    private Shark shark;
    private Cod cod;
    private Bowl bowl;

    protected void setUp() throws Exception {
        pico = new DefaultPicoContainer();

        shark = new Shark();
        cod = new Cod();

        pico.addAdapter("shark", shark);
        pico.addAdapter(cod);
        pico.addAdapter(Bowl.class);

        bowl = (Bowl) pico.getComponent(Bowl.class);
    }

    public static interface Fish {
    }

    public static class Cod implements Fish{
    }

    public static class Shark implements Fish{
    }

    public static class Bowl {
        private final Collection fishes;
        private final Set cods;
        private final Map stringFishMap;
        private final Map objectSharkMap;

        public Bowl(Collection fishes, Set cods, Map stringFishMap, Map objectSharkMap) {
            this.fishes = fishes;
            this.cods = cods;
            this.stringFishMap = stringFishMap;
            this.objectSharkMap = objectSharkMap;
        }

        public Collection getFishes() {
            return fishes;
        }

        public Set getCods() {
            return cods;
        }

        public Map getStringFishMap() {
            return stringFishMap;
        }

        public Map getObjectSharkMap() {
            return objectSharkMap;
        }
    }

    @Test public void testShouldCreateBowlWithFishCollection() {
        Collection fishes = bowl.getFishes();
        assertEquals(2, fishes.size());
        assertTrue(fishes.contains(shark));
        assertTrue(fishes.contains(cod));

        Set cods = bowl.getCods();
        assertEquals(1, cods.size());
        assertTrue(cods.contains(cod));
    }

    @Test public void testShouldFilterMapByKeyType() {
        Map fishMap = bowl.getStringFishMap();
        assertEquals(1, fishMap.size());
        assertSame(shark, fishMap.get("shark"));
    }

    @Test public void testShouldFilterMapByValueType() {
        Map fishMap = bowl.getObjectSharkMap();
        assertEquals(1, fishMap.size());
        assertSame(shark, fishMap.get("shark"));
    }

    public static class UngenericCollectionBowl {
        public UngenericCollectionBowl(Collection fish) {
        }
    }

    @Test public void testShouldNotInstantiateCollectionForUngenericCollectionParameters() {
        pico.addAdapter(UngenericCollectionBowl.class);
        try {
            pico.getComponent(UngenericCollectionBowl.class);
            fail();
        } catch (UnsatisfiableDependenciesException e) {
            // expected
        }
    }

    public static class UngenericMapBowl {
        public UngenericMapBowl(Map fish) {
        }
    }

    @Test public void testShouldNotInstantiateMapForUngenericMapParameters() {
        pico.addAdapter(UngenericMapBowl.class);
        try {
            pico.getComponent(UngenericMapBowl.class);
            fail();
        } catch (UnsatisfiableDependenciesException e) {
            // expected
        }
    }

    public static class AnotherGenericCollectionBowl {
        private final Collection strings;

        public AnotherGenericCollectionBowl(Collection strings) {
            this.strings = strings;
        }

        public Collection getStrings() {
            return strings;
        }
    }

    @Test public void testShouldInstantiateAmptyCollectionForAnotherGenericCollection() {
        pico.addAdapter(AnotherGenericCollectionBowl.class);
        AnotherGenericCollectionBowl anotherGenericCollectionBowl = (AnotherGenericCollectionBowl) pico.getComponent(AnotherGenericCollectionBowl.class);
        assertEquals(0, anotherGenericCollectionBowl.getStrings().size());
    }
*/
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy