mockit.Injectable 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-2012 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit;
import java.lang.annotation.*;
/**
* Indicates an instance field of the test class or a parameter of the test method whose value will be an
* isolated mocked instance, intended to be passed or injected into the code under test.
* Such instances can be said to be proper mock objects, in contrast to the mocked instances of a
* regular mocked type.
* The intent is that these mock objects will be passed/injected into the tested object/unit, so that other instances
* of the same type remain unaffected.
*
* The use of this annotation implies that the declared type of the mock field/parameter is a mocked type, just like it
* would be if annotated with {@linkplain Mocked @Mocked}.
* The {@code @Mocked} annotation can be applied at the same time, if needed.
* The default mocking behavior, however, is different in several ways.
*
* For the duration of each test where the mock field/parameter is in scope, only one injectable instance is
* mocked; other instances of the same mocked type are not affected.
* For an injectable mocked class, static methods and constructors are not mocked;
* only instance methods are.
*
* When used in combination with {@linkplain Tested @Tested}, the values of injectable fields and parameters will be
* used for automatic injection into the tested object.
* Additionally, this annotation can be applied to non-mocked fields of primitive or array type, which will also be used
* for injection.
*
* @see #value
* @see In the
* Tutorial
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
public @interface Injectable
{
/**
* Specifies a literal value when the injectable mock field/parameter is of a primitive type.
* The value provided must be convertible to that primitive type.
*/
String value() default "";
}