    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                                                          *
    009     *****************************************************************************/
    010    package org.picocontainer.monitors;
    011
    012    import java.io.PrintStream;
    013    import java.lang.reflect.Constructor;
    014    import java.lang.reflect.Method;
    015
    016    import org.junit.Before;
    017    import org.junit.Test;
    018    import org.picocontainer.ComponentMonitor;
    019
    020    /**
    021     * @author Aslak Helles&oslash;y
    022     * @author Mauro Talevi
    023     */
    024    public class ConsoleComponentMonitorTestCase {
    025        private ComponentMonitor componentMonitor;
    026        private Constructor constructor;
    027        private Method method;
    028
    029        @Before
    030        public void setUp() throws Exception {
    031            PrintStream out = System.out;
    032            constructor = getClass().getConstructor((Class[])null);
    033            method = getClass().getDeclaredMethod("setUp", (Class[])null);
    034            componentMonitor = new ConsoleComponentMonitor(out);
    035        }
    036
    037        @Test public void testShouldTraceInstantiating() {
    038            componentMonitor.instantiating(null, null, constructor);
    039        }
    040
    041        @Test public void testShouldTraceInstantiatedWithInjected() {
    042            componentMonitor.instantiated(null, null, constructor, new Object(), new Object[0], 543);
    043        }
    044
    045        @Test public void testShouldTraceInstantiationFailed() {
    046            componentMonitor.instantiationFailed(null, null, constructor, new RuntimeException("doh"));
    047        }
    048
    049        @Test public void testShouldTraceInvoking() {
    050            componentMonitor.invoking(null, null, method, this);
    051        }
    052
    053        @Test public void testShouldTraceInvoked() {
    054            componentMonitor.invoked(null, null, method, this, 543);
    055        }
    056
    057        @Test public void testShouldTraceInvocatiationFailed() {
    058            componentMonitor.invocationFailed(method, this, new RuntimeException("doh"));
    059        }
    060
    061    }