Used inside a mock-up
class to indicate a mock (fake) method
whose implementation will
temporarily replace the implementation of a matching "real" method.
The mock method must have the same name and the same parameters as the matching real method, except for an optional
first parameter of type
; 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 (
, etc.) between mock and mocked
have to be the same.
It's perfectly fine to have a non-
mock method for a
mocked method (or vice-versa),
Checked exceptions in the
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 "
Another special mock method, "
", will target the
initializers of the faked class, if present in the mock-up class.
Yet another special mock method is "
", which if defined will
method in the target class hierarchy.