|
![]() |
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@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
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 |
---|
public abstract Class<?> realClass
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.
public abstract Instantiation instantiation
public abstract boolean inverse
public abstract String[] stubs
[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>".
|
![]() |
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |