Issue Details (XML | Word | Printable)

Key: PICO-294
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Mark J. Sinke
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
PicoContainer

ComponentMonitor not set for InstantiatingComponentAdapter

Created: 13/Jun/07 03:22 PM   Updated: 13/Jun/07 03:22 PM
Component/s: PicoContainer (Java)
Affects Version/s: 1.2, 1.3
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Java Source File DefaultPicoContainerTest.java (2 kB)


Testcase included: yes


 Description  « Hide
When using a DefaultPicoContainer with a given LifecycleStrategy (which includes a component monitor), the monitor is not automatically set for instances registered in the container. Cut and paste the code below in a file and run the (Junit 3) test:

/*

  • expose the bug
    */
    package some.package.name;

import java.lang.reflect.Constructor;

import junit.framework.TestCase;

import org.picocontainer.ComponentAdapter;
import org.picocontainer.defaults.ComponentMonitorStrategy;
import org.picocontainer.defaults.DefaultPicoContainer;
import org.picocontainer.defaults.DelegatingComponentMonitor;
import org.picocontainer.defaults.MonitoringComponentAdapter;
import org.picocontainer.monitors.DefaultComponentMonitor;

public class DefaultPicoContainerTest extends TestCase {
public static class Instance { // just a test }

public static class LoggingComponentMonitor extends DefaultComponentMonitor {
private static int calls = 0;
@Override
public void instantiating(Constructor constructor) { calls++; }

static int getCalls() { return calls; }
}

public void testCorrectComponentMonitorRegisterImplementation() { LoggingComponentMonitor monitor = new LoggingComponentMonitor(); DefaultPicoContainer container = new DefaultPicoContainer(monitor); ComponentAdapter adapter = container.registerComponentImplementation(Instance.class); assertSame(monitor, ((ComponentMonitorStrategy)adapter).currentMonitor()); }

public void testCorrectComponentMonitorRegisterInstance() { LoggingComponentMonitor monitor = new LoggingComponentMonitor(); DefaultPicoContainer container = new DefaultPicoContainer(monitor); ComponentAdapter adapter = container.registerComponentInstance(new Instance()); // direct call fails - this is a delegating component monitor // assertSame(monitor, ((ComponentMonitorStrategy)adapter).currentMonitor()); int count = LoggingComponentMonitor.getCalls(); // however the failing test below proves that the LoggingComponentMonitor is not hit ((ComponentMonitorStrategy)adapter).currentMonitor().instantiating(null); assertEquals(count + 1, LoggingComponentMonitor.getCalls()); }
}



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.