01: package org.mockejb.interceptor.test;
02:
03: import org.mockejb.interceptor.Interceptor;
04: import org.mockejb.interceptor.InvocationContext;
05:
06: class TestInterceptor implements Interceptor {
07: static final String TEST_CONTEXT = "testContext";
08:
09: private boolean wasInvoked = false;
10: private int callIndexBefore = 0;
11: private int callIndexAfter = 0;
12:
13: private Exception exception;
14: private Object context;
15:
16: public void intercept(InvocationContext invocationContext)
17: throws Exception {
18:
19: wasInvoked = true;
20: callIndexBefore = invocationContext.getInterceptorIterator()
21: .previousIndex();
22:
23: context = invocationContext
24: .getOptionalPropertyValue(TEST_CONTEXT);
25:
26: System.out.println("Was invoked: " + callIndexBefore);
27:
28: if (exception != null)
29: throw exception;
30:
31: invocationContext.proceed();
32:
33: callIndexAfter = invocationContext.getInterceptorIterator()
34: .previousIndex();
35:
36: }
37:
38: boolean wasInvoked() {
39: boolean tmpWasInvoked = wasInvoked;
40: wasInvoked = false;
41: return tmpWasInvoked;
42: }
43:
44: int getCallIndexBefore() {
45: return callIndexBefore;
46: }
47:
48: int getCallIndexAfter() {
49: return callIndexAfter;
50: }
51:
52: void setThrowException(Exception exception) {
53: this .exception = exception;
54: }
55:
56: Object getContext() {
57: return context;
58: }
59:
60: }
|