    001    /*****************************************************************************
    002     * Copyright (C) PicoContainer Organization. All rights reserved.            *
    003     * ------------------------------------------------------------------------- *
    004     * The software in this package is published under the terms of the BSD      *
    005     * style license a copy of which has been included with this distribution in *
    006     * the LICENSE.txt file.                                                     *
    007     *                                                                           *
    008     * Original code by Michael Rettig                                           *
    009     *****************************************************************************/
    010    package org.picocontainer.defaults.issues;
    011
    012    import static org.junit.Assert.assertNotNull;
    013
    014    import org.junit.Test;
    015    import org.picocontainer.DefaultPicoContainer;
    016    import org.picocontainer.visitors.VerifyingVisitor;
    017
    018
    019    public class Issue0229TestCase {
    020
    021        public static class MockRunnable implements Runnable {
    022            public void run() {
    023            }
    024        }
    025
    026        public static class OtherRunnable implements Runnable {
    027            public void run() {
    028            }
    029        }
    030
    031        public static class MockRunner {
    032            private final Runnable[] _runners;
    033
    034            public MockRunner(Runnable[] runnables) {
    035                _runners = runnables;
    036            }
    037
    038            public Runnable[] getRunners(){
    039                return _runners;
    040            }
    041        }
    042
    043        @Test public void testArrayDependenciesAndVerification() {
    044            DefaultPicoContainer container = new DefaultPicoContainer();
    045            container.addComponent(new MockRunnable());
    046            container.addComponent(new OtherRunnable());
    047            container.addComponent(MockRunner.class);
    048
    049            // this will fail to resolve the Runnable array on the MockRunner
    050            VerifyingVisitor visitor = new VerifyingVisitor();
    051            visitor.traverse(container);
    052
    053            container.start();
    054            assertNotNull(container.getComponent(MockRunner.class));
    055        }
    056
    057    }