Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *
   *  * Copyright 2010,  Unitils.org
   *  *
   *  * Licensed under the Apache License, Version 2.0 (the "License");
   *  * you may not use this file except in compliance with the License.
   *  * You may obtain a copy of the License at
   *  *
   *  *     http://www.apache.org/licenses/LICENSE-2.0
  *  *
  *  * Unless required by applicable law or agreed to in writing, software
  *  * distributed under the License is distributed on an "AS IS" BASIS,
  *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  * See the License for the specific language governing permissions and
  *  * limitations under the License.
  *
  */
 package org.unitils.mock.core;
 
 
 import java.util.List;
 
 import static org.unitils.mock.argumentmatcher.ArgumentMatcher.MatchResult.NO_MATCH;

Author(s):
Filip Neven
Tim Ducheyne
Kenny Claes
 
 public class BehaviorDefiningInvocation extends ProxyInvocation {
 
 
     /* The argument matchers to use when matching the invocation */
     protected List<ArgumentMatcherargumentMatchers;
     /* The behavior to execute */
     protected MockBehavior mockBehavior;


    
Creates a behavior defining invocation for the given prosy invocation. The argumentsAtInvocationTime should be copies (deep clones) of the arguments at the time of the invocation. This way the original values can still be used later-on even when changes occur to the original values (pass-by-value vs pass-by-reference).

Parameters:
proxyInvocation The proxy invocation, not null
mockBehavior The behavior to execute, not null
argumentMatchers The argument matchers to use when matching the invocation, not null
 
     public BehaviorDefiningInvocation(ProxyInvocation proxyInvocationMockBehavior mockBehaviorList<ArgumentMatcherargumentMatchers) {
         super(proxyInvocation);
         this. = argumentMatchers;
         this. = mockBehavior;
     }


    

Returns:
The behavior to execute, not null
 
     public MockBehavior getMockBehavior() {
         return ;
     }

    

Parameters:
mockBehavior The behavior to execute, not null
 
     public void setMockBehavior(MockBehavior mockBehavior) {
         this. = mockBehavior;
     }


    
Returns whether or not the given org.unitils.mock.core.proxy.ProxyInvocation matches this object's predefined Method and arguments.

Parameters:
proxyInvocation the org.unitils.mock.core.proxy.ProxyInvocation to match.
Returns:
A matching score for the invocation, -1 if there is no match
 
     public int matches(ProxyInvocation proxyInvocation) {
         if (!getMethod().equals(proxyInvocation.getMethod())) {
             return -1;
         }
         List<?> arguments = proxyInvocation.getArguments();
         List<?> argumentsAtInvocationTime = proxyInvocation.getArgumentsAtInvocationTime();
 
         if (arguments.size() != .size()) {
             return -1;
         }
 
         int matchingScore = 0;
         for (int i = 0; i < arguments.size(); ++i) {
             Object argument = arguments.get(i);
             Object argumentAtInvocationTime = argumentsAtInvocationTime.get(i);
 
             ArgumentMatcher.MatchResult matchResult = .get(i).matches(argumentargumentAtInvocationTime);
             if (matchResult == ) {
                 return -1;
            }
            matchingScore += matchResult.getScore();
        }
        return matchingScore;
    }
New to GrepCode? Check out our FAQ X