KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > aop > dynaop > ContainerSuppliedInterceptorFactoryTestCase


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.dynaop;
11
12 import dynaop.Interceptor;
13 import dynaop.InterceptorFactory;
14 import org.aopalliance.intercept.MethodInterceptor;
15 import org.jmock.Mock;
16 import org.jmock.MockObjectTestCase;
17 import org.picocontainer.MutablePicoContainer;
18 import org.picocontainer.defaults.DefaultPicoContainer;
19
20 /**
21  * @author Stephen Molitor
22  */

23 public class ContainerSuppliedInterceptorFactoryTestCase extends MockObjectTestCase {
24
25     private MutablePicoContainer pico = new DefaultPicoContainer();
26
27     public void testCreate() throws Throwable JavaDoc {
28         Mock methodInterceptorMock = mock(MethodInterceptor.class);
29
30         pico.registerComponentInstance("interceptorComponentKey", methodInterceptorMock.proxy());
31
32         InterceptorFactory interceptorFactory = new ContainerSuppliedInterceptorFactory(pico, "interceptorComponentKey");
33         Interceptor interceptor = interceptorFactory.create(null);
34         assertNotNull(interceptor);
35
36         // verify that the dynaop interceptor delegates to the MethodInterceptor
37
// in the container:
38
methodInterceptorMock.expects(once()).method("invoke");
39         interceptor.intercept(null);
40     }
41
42     public void testInterceptorNotFoundInContainer() {
43         MutablePicoContainer container = new DefaultPicoContainer();
44         InterceptorFactory interceptorFactory = new ContainerSuppliedInterceptorFactory(container,
45                 "interceptorComponentKey");
46         try {
47             interceptorFactory.create(null);
48             fail("NullPointerException should have been raised");
49         } catch (NullPointerException JavaDoc e) {
50         }
51     }
52
53     public void testPropertiesNotNull() {
54         InterceptorFactory interceptorFactory = new ContainerSuppliedInterceptorFactory(pico, "interceptorComponentKey");
55         assertNotNull(interceptorFactory.getProperties());
56     }
57
58 }
Popular Tags