provide stub chain methods.
provide stub chain methods.
This class is an implementation of the Answer interface allowing to pass functions as an answer.
This class is an implementation of the Answer interface allowing to pass functions as an answer.
It does a bit of work for the client:
// if the method has one parameter and the function also, the parameter is passed mock.get(0) answers ( i => i.toString )
// if the method has one parameter and the function has two, the mock is passed as the second argument mock.get(0) answers { (i, mock) => i.toString + " for mock " + mock.toString }
Similarly a mocked method with no parameters can use a function with one parameter. In that case, the mock will be passed mock.size answers { mock => mock.hashCode }
In any other cases, if f is a function of 1 parameter, the array of the method parameters will be passed and if the function has 2 parameters, the second one will be the mock.
in this case we suppose that the second expected parameter is the mock instance
in this case we the function expects all the arguments from the invocation
This class provide stub methods like returns, throws and answers.
This class provide stub methods like returns, throws and answers. Internally it calls Mockito.when(mock call).thenReturn(returnValue)
an object allowing the chaining of returned values on doNothing calls.
an object allowing the chaining of stub values.
this implicit helps with defining optional values for mockito settings
this implicit helps with defining optional values for mockito settings
delegate to MockitoMocker doAnswer with a MockAnswer object using the function f.
ignore stubbed methods when verifying that a mock has no more interactions
ignore stubbed methods when verifying that a mock has no more interactions
create a mock object with some specific settings: val m = mock[java.util.List[String]](settings)
create a mock object with some specific settings: val m = mock[java.util.List[String]](settings)
create a mock object: val m = mock[java.util.List[String]]
create a mock object: val m = mock[java.util.List[String]]
create a mock object with a name: val m = mockAs[java.util.List[String]]("name")
create a mock object with a name: val m = mockAs[java.util.List[String]]("name")
implicit allowing to define the mock settings with a nice syntax:
implicit allowing to define the mock settings with a nice syntax:
create a mock object with smart return values: val m = smartMock[java.util.List[String]]
create a mock object with smart return values: val m = smartMock[java.util.List[String]]
This is the equivalent of Mockito.mock(List.class, SMART_NULLVALUES) but testing shows that it is not working well with Scala.
create a spy on an object.
create a spy on an object.
A spy is a real object but can still have some of its methods stubbed. However the syntax for stubbing a spy is a bit different than with a mock:
val s = spy(new LinkedList[String]) doReturn("one").when(s).get(0) // instead of s.get(0) returns "one" which would throw an exception
an object supporting the stub methods.
This trait provides functionalities to declare stub values on method calls.
Usage:
It is also possible to chain stubs like this: