TestInterceptor.java :  » Testing » MockEJB » org » mockejb » interceptor » test » Java Open Source

Java Open Source » Testing » MockEJB 
MockEJB » org » mockejb » interceptor » test » TestInterceptor.java
package org.mockejb.interceptor.test;


import org.mockejb.interceptor.Interceptor;
import org.mockejb.interceptor.InvocationContext;


class TestInterceptor implements Interceptor {
    static final String TEST_CONTEXT = "testContext";
    
    private boolean wasInvoked = false;
    private int callIndexBefore = 0;
    private int callIndexAfter = 0;

    private Exception exception;
    private Object context; 
    
    public void intercept( InvocationContext invocationContext)  throws Exception {
            
        wasInvoked= true;
        callIndexBefore = invocationContext.getInterceptorIterator().previousIndex();
            
        context = invocationContext.getOptionalPropertyValue( TEST_CONTEXT );

        System.out.println( "Was invoked: "+ callIndexBefore);        
        
        if ( exception != null )
            throw exception;
                    
        invocationContext.proceed();

        callIndexAfter = invocationContext.getInterceptorIterator().previousIndex();
            
    }
    
    boolean wasInvoked(){
        boolean tmpWasInvoked = wasInvoked;
        wasInvoked=false;
        return tmpWasInvoked;
    }
    
    int getCallIndexBefore(){
        return callIndexBefore;
    }
    
    int getCallIndexAfter(){
        return callIndexAfter;
    }
    
    void setThrowException( Exception exception ){
        this.exception=exception;
    }
    
    Object getContext(){
        return context;
    }
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.