@Inherited @Retention(value=RUNTIME) @Target(value=METHOD) public @interface Mock
Invocation
; if this extra parameter is present, the remaining ones must match the
parameters in the real method.
The mock method must also have the same return type as the matching real method.
Method modifiers (public
, final
, static
, etc.) between mock and mocked
methods don't have to be the same.
It's perfectly fine to have a non-static
mock method for a static
mocked method (or vice-versa),
for example.
Checked exceptions in the throws
clause (if any) can also differ between the two matching methods.
A mock method can also target a constructor, in which case the previous considerations still apply,
except for the name of the mock method which must be "$init
".
Another special mock method, "void $clinit()
", will target the static
initializers of the mocked class, if present in the mock-up class.
Yet another special mock method is "Object $advice(Invocation)
", which if defined will
match every method in the mocked class hierarchy.
A mock method can specify constraints on the number of invocations it should receive while in effect
(ie, from the time a real method/constructor is mocked to the time it is restored to its original definition).invocations
,
minInvocations
,
maxInvocations
,
TutorialModifier and Type | Optional Element and Description |
---|---|
int |
invocations
Number of expected invocations of the mock method.
|
int |
maxInvocations
Maximum number of expected invocations of the mock method, if positive.
|
int |
minInvocations
Minimum number of expected invocations of the mock method, starting from 0 (zero, which is the default).
|
public abstract int invocations
minInvocations
and
maxInvocations
to that same value.public abstract int maxInvocations
invocations
,
minInvocations
,
Tutorialpublic abstract int minInvocations
invocations
,
maxInvocations
,
Tutorial