JMockit Home

mockit
Annotation Type MockClass


@Retention(value=RUNTIME)
@Target(value=TYPE)
public @interface MockClass

Indicates a mock class containing one or more mock methods, whose implementations will take the place of the corresponding method/constructor implementations in the mocked class. Each mock method in the mock class must be explicitly indicated as such.

In the Tutorial

See Also:
realClass, stubs, inverse, instantiation

Required Element Summary
 Class<?> realClass
          The real class whose methods/constructors will be redefined according to the corresponding mock methods in the mock class.
 
Optional Element Summary
 Instantiation instantiation
          Specifies when instances of the mock class should be created: every time the mock class is set up, every time an instance mock method is called, or for each mocked instance of the real class.
 boolean inverse
          Indicates whether the stubbing filters are to be inverted or not.
 String[] stubs
          One or more stubbing filters which specify the set of methods and constructors in the real class that are to be stubbed out with empty implementations.
 

Element Detail

realClass

public abstract Class<?> realClass
The real class whose methods/constructors will be redefined according to the corresponding mock methods in the mock class.

Alternatively, the Class object provided can point to an interface. In that case, a proxy implementation class will be created and then used as the target class for mocking. The only way for a test to use such a mocked class will be through the proxy instance returned by Mockit.setUpMock(Object), so it only makes sense to use an interface for this attribute when the mock class is set up through that method.

instantiation

public abstract Instantiation instantiation
Specifies when instances of the mock class should be created: every time the mock class is set up, every time an instance mock method is called, or for each mocked instance of the real class.

If not specified, a mock instance will be created for each mock invocation.

Default:
mockit.Instantiation.PerMockInvocation

inverse

public abstract boolean inverse
Indicates whether the stubbing filters are to be inverted or not. If inverted, only the methods and constructors matching them are not stubbed out.

Default:
false

stubs

public abstract String[] stubs
One or more stubbing filters which specify the set of methods and constructors in the real class that are to be stubbed out with empty implementations.

Each filter must follow the syntax [nameRegex][(paramTypeName...)], where nameRegex is a regular expression for matching method names, and paramTypeName is the name of a primitive or reference parameter type. Actually, any suffix of the type name is enough, like "String" instead of the full class name "java.lang.String". If nameRegex is omitted the filter matches only constructors. If (paramTypeName...) is omitted the filter matches methods with any parameters.

Note that an empty filter (stubs = "") will match no methods or constructors in the real class, or all methods and constructors if used with inverse = true.

To specify the static initializers of the class, inform the filter "<clinit>".

Default:
{}

JMockit Home

© 2006-2012 Rogério Liesenfeld