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 * @version $Revision: 2024 $
024 */
025 public class ConsoleComponentMonitorTestCase extends TestCase {
026 private ComponentMonitor componentMonitor;
027 private Constructor constructor;
028 private Method method;
029
030 protected 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 public void testShouldTraceInstantiating() {
038 componentMonitor.instantiating(null, null, constructor);
039 }
040
041 public void testShouldTraceInstantiatedWithInjected() {
042 componentMonitor.instantiated(null, null, constructor, new Object(), new Object[0], 543);
043 }
044
045 public void testShouldTraceInstantiationFailed() {
046 componentMonitor.instantiationFailed(null, null, constructor, new RuntimeException("doh"));
047 }
048
049 public void testShouldTraceInvoking() {
050 componentMonitor.invoking(null, null, method, this);
051 }
052
053 public void testShouldTraceInvoked() {
054 componentMonitor.invoked(null, null, method, this, 543);
055 }
056
057 public void testShouldTraceInvocatiationFailed() {
058 componentMonitor.invocationFailed(method, this, new RuntimeException("doh"));
059 }
060
061 }