org.unitils.mock.argumentmatcher
Class ArgumentMatcherRepository

java.lang.Object
  extended by org.unitils.mock.argumentmatcher.ArgumentMatcherRepository

public class ArgumentMatcherRepository
extends Object

A repository for holding the current set of argument matchers.

Argument matchers are placed inline in method invocations. Java will evaluate them before the method is performed. E.g. method1(notNull()) => not null will be called before method1.

For this we need to store the current argument matchers so that they can be linked to the method invocation that will follow.

Author:
Filip Neven, Tim Ducheyne, Kenny Claes

Constructor Summary
ArgumentMatcherRepository()
           
 
Method Summary
 List<ArgumentMatcher> getArgumentMatchers()
           
static ArgumentMatcherRepository getInstance()
           
 int getMatchInvocationEndLineNr()
           
 int getMatchInvocationIndex()
           
 int getMatchInvocationStartLineNr()
           
 void registerArgumentMatcher(ArgumentMatcher argumentMatcher, int lineNr)
          Registers an argument matcher at the given line nr.
 void registerEndOfMatchingInvocation(int lineNr, String methodName)
          Stops the registering of argument matchers.
 void registerStartOfMatchingInvocation(int lineNr)
          From the moment that this method is called until registerEndOfMatchingInvocation(int, java.lang.String) has been called, argument matchers can be registered.
 void reset()
          Clears the current argument matchers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgumentMatcherRepository

public ArgumentMatcherRepository()
Method Detail

getInstance

public static ArgumentMatcherRepository getInstance()
Returns:
The singleton instance, not null

registerArgumentMatcher

public void registerArgumentMatcher(ArgumentMatcher argumentMatcher,
                                    int lineNr)
Registers an argument matcher at the given line nr.

Parameters:
argumentMatcher - The matcher, not null
lineNr - The line number on which the argument matcher was registered.

getArgumentMatchers

public List<ArgumentMatcher> getArgumentMatchers()
Returns:
The current argument matchers, not null

getMatchInvocationStartLineNr

public int getMatchInvocationStartLineNr()
Returns:
The begin line-nr of the invocation

getMatchInvocationEndLineNr

public int getMatchInvocationEndLineNr()
Returns:
The end line-nr of the invocation (could be different from the begin line-nr if the invocation is written on more than 1 line)

getMatchInvocationIndex

public int getMatchInvocationIndex()
Returns:
The index of the matcher on that line, 1 for the first, 2 for the second etc

registerStartOfMatchingInvocation

public void registerStartOfMatchingInvocation(int lineNr)
From the moment that this method is called until registerEndOfMatchingInvocation(int, java.lang.String) has been called, argument matchers can be registered.

Parameters:
lineNr - The line number at which the matching invocation starts, i.e. the line number at which the performs, assertInvoked, etc. statement occurs.

registerEndOfMatchingInvocation

public void registerEndOfMatchingInvocation(int lineNr,
                                            String methodName)
Stops the registering of argument matchers. The argument matchers can now be retrieved using getArgumentMatchers().

Parameters:
lineNr - The current line nr
methodName - The current method, not null

reset

public void reset()
Clears the current argument matchers. After this method is called, registerStartOfMatchingInvocation(int) must be called again to be able to register argument matchers.



Copyright © 2011. All Rights Reserved.