KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tirsen > nanning > MockConstructionInterceptor


1 package com.tirsen.nanning;
2
3 import com.tirsen.nanning.definition.SingletonInterceptor;
4 import junit.framework.Assert;
5
6 public class MockConstructionInterceptor implements ConstructionInterceptor, SingletonInterceptor {
7     private ConstructionInvocation constructionInvocation;
8     private Object JavaDoc newTarget;
9
10     public Object JavaDoc construct(ConstructionInvocation invocation) {
11         this.constructionInvocation = invocation;
12         if (newTarget != null) {
13             invocation.setTarget(newTarget);
14         }
15         return invocation.getProxy();
16     }
17
18     public boolean interceptsConstructor(Class JavaDoc klass) {
19         return true;
20     }
21
22     public ConstructionInvocation getInvocation() {
23         return constructionInvocation;
24     }
25
26     public void changeTarget(Object JavaDoc newTarget) {
27         this.newTarget = newTarget;
28     }
29
30     public void verify() {
31         Assert.assertNotNull("construction-interceptor never called", constructionInvocation);
32     }
33 }
34
Popular Tags