The trait to mix in for using Smockito facilities in a specification. It includes the mock and spy methods for creating mocks, and the various syntax extensions on them, such as on, calls and times. Those extensions expect method references via context functions with a Mock context parameter, retrievable via the it method.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
Value members
Concrete methods
Retrieves the mock in scope. This is the recommended way to refer to a mock available in context, as is the case when using methods of Mock.
Retrieves the mock in scope. This is the recommended way to refer to a mock available in context, as is the case when using methods of Mock.
Type parameters
- T
-
the mocked type.
Value parameters
- mock
-
the mock in scope.
Attributes
- Returns
-
the mock in scope.
Creates a Mock instance of T.
Creates a Spy instance of T.
Creates a Spy instance of T.
A Spy[T] is the Smockito compile time representation of a type spied by Mockito, erased at runtime. Keep in mind that Mockito spies are copies of real instances, so any method side effects won't affect the original object.
A Spy[T] is also a Mock[T], so you may use all methods available on Mock.
If you only need to forward a few methods to a real instance, consider using the forward method on a Mock instead for clarity and performance.
Type parameters
- T
-
the type to spy.
Attributes
- Returns
-
the spy instance.
Extensions
Inherited extensions
Whether the last invocation of method a happened after the last invocation of method b, provided both methods were called at least once. Same as calledBefore(b, a).
Whether the last invocation of method a happened after the last invocation of method b, provided both methods were called at least once. Same as calledBefore(b, a).
Value parameters
- a
-
the method that is expected to be called after
b. - b
-
the method that is expected to be called first.
Attributes
- Returns
-
Whether
awas called afterb. - Inherited from:
- MockSyntax (hidden)
Whether the last invocation of method a happened before the last invocation of method b, provided both methods were called at least once. Same as calledAfter(b, a).
Whether the last invocation of method a happened before the last invocation of method b, provided both methods were called at least once. Same as calledAfter(b, a).
Value parameters
- a
-
the method that is expected to be called first.
- b
-
the method that is expected to be called after
a.
Attributes
- Returns
-
Whether
awas called beforeb. - Inherited from:
- MockSyntax (hidden)
Yields the captured arguments received by a stubbed method, in chronological order. If you only need to reason about the number of interactions, times is more efficient.
Yields the captured arguments received by a stubbed method, in chronological order. If you only need to reason about the number of interactions, times is more efficient.
Value parameters
- method
-
the mocked method.
Attributes
- Returns
-
the received arguments.
- Inherited from:
- MockSyntax (hidden)
Sets up a stub for a method that calls the respective method of a real instance.
Sets up a stub for a method that calls the respective method of a real instance.
At a high level, this desugars to:
mock.on(it.someMethod)(realInstance.someMethod)
If you need to forward multiple methods, consider using a Spy instead.
Value parameters
- method
-
the mocked method.
- realInstance
-
the real instance.
Attributes
- Returns
-
the mocked type.
- Inherited from:
- MockSyntax (hidden)
Sets up a stub for a method, based on the received tupled arguments. This will override any previous stubs for the same method.
Sets up a stub for a method, based on the received tupled arguments. This will override any previous stubs for the same method.
Value parameters
- method
-
the method to mock.
- stub
-
the stub implementation, based on the received arguments.
Attributes
- Returns
-
the mocked type.
- Inherited from:
- MockSyntax (hidden)
Sets up a stub for a method that behaves differently based on the call number. For the version operating only on the expected set of inputs, see on.
Sets up a stub for a method that behaves differently based on the call number. For the version operating only on the expected set of inputs, see on.
Value parameters
- method
-
the method to mock.
- stub
-
the stub implementation, based on the call number of the respective method, starting at 1.
Attributes
- Returns
-
the mocked type.
- Inherited from:
- MockSyntax (hidden)
Sets up a stub that delegates to the real implementation of this method. Useful when you want to preserve an adapter method’s behavior while stubbing a method lower in the hierarchy later with on. Otherwise, use with care.
Sets up a stub that delegates to the real implementation of this method. Useful when you want to preserve an adapter method’s behavior while stubbing a method lower in the hierarchy later with on. Otherwise, use with care.
Notice that, if the real implementation interacts with a class value that is not available in the mocking context, the stub will throw with a java.lang.NullPointerException. Similarly, if this method is abstract on the mocked type, this will throw at set up time.
Value parameters
- method
-
the method whose real implementation shall be called.
Attributes
- Returns
-
the mocked type.
- Inherited from:
- MockSyntax (hidden)
Yields the number of times a stub was called. If you need the exact arguments, see calls.
Yields the number of times a stub was called. If you need the exact arguments, see calls.
Value parameters
- method
-
the mocked method.
Attributes
- Returns
-
the number of calls to the stub.
- Inherited from:
- MockSyntax (hidden)