Clover coverage report - Maven Clover report
Coverage timestamp: Sun Mar 18 2007 17:42:32 CET
file stats: LOC: 90   Methods: 6
NCLOC: 58   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InvocationExpectationVisitor.java 100% 100% 100% 100%
coverage
 1    package com.agical.rmock.core.expectation;
 2   
 3    import java.util.LinkedList;
 4   
 5    import com.agical.rmock.core.Action;
 6    import com.agical.rmock.core.Expectation;
 7    import com.agical.rmock.core.ExpectationVisitor;
 8    import com.agical.rmock.core.Section;
 9    import com.agical.rmock.core.match.Expression;
 10    import com.agical.rmock.core.match.Multiplicity;
 11   
 12    /**
 13    * Finds a matching expectation and returns its action.
 14    * If no match is found, null is returned.
 15    *
 16    * <em>(c) Agical AB 2005</em>
 17    * @author joakim.ohlrogge
 18    *
 19   
 20    */
 21    public class InvocationExpectationVisitor implements ExpectationVisitor{
 22   
 23    private final String id;
 24    private final String method;
 25    private final Object[] arguments;
 26    private Action action;
 27    private final LinkedList sectionStack = new LinkedList();
 28    private Section lastEnteredSection = null;
 29   
 30    /**
 31    * @param id the id of the calling object
 32    * @param method the name of the method to be called
 33    * @param arguments the arguments of the
 34    */
 35  943 public InvocationExpectationVisitor(String id, String method, Object[] arguments) {
 36  943 this.id = id;
 37  943 this.method = method;
 38  943 this.arguments = arguments;
 39    }
 40   
 41    /**
 42    * @see ExpectationVisitor#visit(Expectation, boolean)
 43    */
 44  2584 public boolean visit(Expectation expectation, boolean available) {
 45  2584 if( !available ) {
 46  281 return true;
 47    }
 48  2303 Multiplicity multiplicityConstraint = expectation.getMultiplicity();
 49  2303 if( multiplicityConstraint.canMatch() &&
 50    expectation.getId().equals( id ) &&
 51    expectation.getMethod().equals( method ) &&
 52    matchArguments( expectation.getArguments() ) ) {
 53  936 action = expectation.getAction();
 54  936 multiplicityConstraint.match();
 55  936 return false;
 56    }
 57  1367 return true;
 58    }
 59   
 60  939 private boolean matchArguments(Expression[] expectedArguments ) {
 61  939 if( expectedArguments.length != arguments.length ) {
 62  2 return false;
 63    }
 64  937 for (int i = 0; i < expectedArguments.length; i++) {
 65  702 Expression constraint = expectedArguments[i];
 66  702 if ( !constraint.passes( arguments[i] ) ) {
 67  1 return false;
 68    }
 69    }
 70  936 return true;
 71    }
 72   
 73    /**
 74    *
 75    * @return the action of the matched expectation, null if no expectation was matched
 76    */
 77  943 public Action getMatchedAction() {
 78  943 return action;
 79    }
 80   
 81  2187 public void enteredSection(Section section) {
 82  2187 sectionStack.addLast(section);
 83  2187 lastEnteredSection = section;
 84    }
 85   
 86  100 public void exitedSection() {
 87  100 sectionStack.removeLast();
 88    }
 89   
 90    }