KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > aop > defaults > AspectsComponentAdapterTestCase


1 /*****************************************************************************
2  * Copyright (c) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Idea by Rachel Davies, Original code by various *
9  *****************************************************************************/

10 package org.nanocontainer.aop.defaults;
11
12 import org.jmock.Mock;
13 import org.jmock.MockObjectTestCase;
14 import org.nanocontainer.aop.AspectsApplicator;
15 import org.picocontainer.ComponentAdapter;
16 import org.picocontainer.PicoContainer;
17 import org.picocontainer.defaults.DefaultPicoContainer;
18
19 /**
20  * @author Stephen Molitor
21  */

22 public class AspectsComponentAdapterTestCase extends MockObjectTestCase {
23
24     private Mock mockApplicator = mock(AspectsApplicator.class);
25     private Mock mockComponentAdapterDelegate = mock(ComponentAdapter.class);
26     private PicoContainer container = new DefaultPicoContainer();
27
28     public void testGetComponentInstance() {
29         mockComponentAdapterDelegate.expects(once()).method("getComponentInstance").with(same(container)).will(returnValue("component"));
30         mockComponentAdapterDelegate.expects(once()).method("getComponentKey").will(returnValue("componentKey"));
31
32         mockApplicator.expects(once()).method("applyAspects").with(same("componentKey"), same("component"),
33                 same(container)).will(returnValue("wrappedComponent"));
34
35         ComponentAdapter adapter = new AspectsComponentAdapter((AspectsApplicator) mockApplicator.proxy(),
36                 (ComponentAdapter) mockComponentAdapterDelegate.proxy());
37         Object JavaDoc component = adapter.getComponentInstance(container);
38         assertEquals("wrappedComponent", component);
39     }
40
41 }
Popular Tags