mockit.Delegate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmockit Show documentation
Show all versions of jmockit Show documentation
JMockit is a Java toolkit for developer (unit/integration) testing.
It contains mocking APIs and other tools, supporting both JUnit and TestNG.
The mocking APIs allow all kinds of Java code, without testability restrictions, to be tested
in isolation from selected dependencies.
/*
* Copyright (c) 2006-2011 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit;
/**
* An empty interface to be used with the {@link Expectations#result} field or the {@link Invocations#with(Delegate)}
* method, allowing test code to define invocation results (return values or thrown exceptions) or argument matching
* rules based on test-specific logic.
*
* When used with the {@code result} field, the following rules apply to the implementation class:
*
* - A method matching the signature of the recorded method/constructor call must be defined.
* That is, they should have the same name and parameters. In the case of delegating a constructor, a delegate
* method should still be used, with name "$init".
* - Alternatively, for the common case where the delegate implementation class defines a single method, the
* name is allowed to be different from the recorded method.
* The parameters should still match, though. Besides giving more flexibility, this ability also prevents the test from
* breaking in case the recorded method is renamed.
* If the delegate class defines two or more methods (including {@code private} ones, if any), then exactly one
* of them must match both the name and the parameters of the recorded method.
* - The result of a delegate method execution can be any return value compatible with the recorded method's return
* type, or a thrown error/exception.
*
* When used with the {@code with} method, the implementing class must have a single non-{@code private} method which
* returns a {@code boolean}, being {@code true} for a succesfully matched argument or {@code false} otherwise.
*
* At replay time, when the mocked method/constructor is called the corresponding "delegate" method will be called.
* The arguments passed to the delegate method will be the same as those received by the recorded invocation during
* replay.
* Even {@code static} methods in the mocked type can have delegates, which in turn can be static or not.
* The same is true for {@code private}, {@code final}, and {@code native} methods.
*
* In the Tutorial
*
* Sample tests:
* DocumentManager_JMockit_Test
*
* @param the type of the argument to be matched, when used with the {@code with(Delegate<T>)} method
*/
public interface Delegate
{
}