mockit.Mock Maven / Gradle / Ivy
/*
* Copyright (c) 2006 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit;
import java.lang.annotation.*;
/**
* Used inside a {@linkplain MockUp fake} class to indicate a fake method whose implementation will temporarily
* replace the implementation of a matching "real" method.
*
* The fake method must have the same name and the same parameters as the matching real method, except for an optional
* first parameter of type {@link Invocation}; if this extra parameter is present, the remaining ones must match the
* parameters in the real method.
* The fake method must also have the same return type as the matching real method.
*
* Method modifiers (public
, {@code final}, {@code static}, etc.) between fake and faked methods
* don't have to be the same.
* It's perfectly fine to have a non-static
fake method for a {@code static} faked method (or vice-versa),
* for example.
* Checked exceptions in the {@code throws} clause (if any) can also differ between the two matching methods.
*
* A fake method can also target a constructor, in which case the previous considerations still apply,
* except for the name of the fake method which must be "$init
".
*
* Another special fake method, "void $clinit()
", will target the {@code static}
* initializers of the faked class, if present in the fake class.
*
* Yet another special fake method is "Object $advice(Invocation)
", which if defined will
* match every method in the target class hierarchy.
*
* @see Tutorial
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Mock
{
}