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