01: /*****************************************************************************
02: * Copyright (c) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Idea by Rachel Davies, Original code by various *
09: *****************************************************************************/package org.nanocontainer.aop.defaults;
10:
11: import org.jmock.Mock;
12: import org.jmock.MockObjectTestCase;
13: import org.nanocontainer.aop.AspectsApplicator;
14: import org.picocontainer.ComponentAdapter;
15: import org.picocontainer.PicoContainer;
16: import org.picocontainer.defaults.DefaultPicoContainer;
17:
18: /**
19: * @author Stephen Molitor
20: */
21: public class AspectsComponentAdapterTestCase extends MockObjectTestCase {
22:
23: private Mock mockApplicator = mock(AspectsApplicator.class);
24: private Mock mockComponentAdapterDelegate = mock(ComponentAdapter.class);
25: private PicoContainer container = new DefaultPicoContainer();
26:
27: public void testGetComponentInstance() {
28: mockComponentAdapterDelegate.expects(once()).method(
29: "getComponentInstance").with(same(container)).will(
30: returnValue("component"));
31: mockComponentAdapterDelegate.expects(once()).method(
32: "getComponentKey").will(returnValue("componentKey"));
33:
34: mockApplicator.expects(once()).method("applyAspects").with(
35: same("componentKey"), same("component"),
36: same(container)).will(returnValue("wrappedComponent"));
37:
38: ComponentAdapter adapter = new AspectsComponentAdapter(
39: (AspectsApplicator) mockApplicator.proxy(),
40: (ComponentAdapter) mockComponentAdapterDelegate.proxy());
41: Object component = adapter.getComponentInstance(container);
42: assertEquals("wrappedComponent", component);
43: }
44:
45: }
|