org.specs2.mock.mockito

MockitoStubs

trait MockitoStubs extends MocksCreation with MockitoStubsLowerImplicits

This trait provides functionalities to declare stub values on method calls.

Usage:

mockedList.get(0) returns "one"
mockedList.get(0) returns ("one", "two")
mockedList.get(0) throws new Exception("unexpected")
mockedList.get(0) answers ( i => "value " + i.toString )
mockedList.get(any) responds { case i: Int => (i + 1).toString }

It is also possible to chain stubs like this:

mockedList.get(0) returns "one" thenReturns "two"
mockedList.get(0) returns "one" thenThrows new Exception("unexpected now")
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. MockitoStubs
  2. MockitoStubsLowerImplicits
  3. MocksCreation
  4. ClassesOf
  5. TheMockitoMocker
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. class AStubber[T] extends AnyRef

    provide stub chain methods.

  2. class AnOngoingStubbing[T] extends AnyRef

    provide stub chain methods.

  3. class MockAnswer[T] extends Answer[T]

    This class is an implementation of the Answer interface allowing to pass functions as an answer.

  4. class MockAnswer2[T] extends Answer[T]

    in this case we suppose that the second expected parameter is the mock instance

  5. case class MockProperty[T](p: Property[T] = control.Property.apply[T]()) extends Product with Serializable

    Definition Classes
    MocksCreation
  6. class Stubbed[T] extends AnyRef

    This class provide stub methods like returns, throws and answers.

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. implicit def aStubber(stub: ⇒ Stubber): AStubber[Nothing]

    returns

    an object allowing the chaining of returned values on doNothing calls.

  7. implicit def anOngoingStubbing[T](stub: ⇒ OngoingStubbing[T]): AnOngoingStubbing[T]

    returns

    an object allowing the chaining of stub values.

  8. implicit def anyToMockProperty[T](t: ⇒ T): MockProperty[T]

    this implicit helps with defining optional values for mockito settings

    this implicit helps with defining optional values for mockito settings

    Definition Classes
    MocksCreation
  9. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  10. def classesOf[T1, T2, T3, T4, T5](implicit arg0: ClassTag[T1], arg1: ClassTag[T2], arg2: ClassTag[T3], arg3: ClassTag[T4], arg4: ClassTag[T5]): Seq[Class[_ >: _$1 with _$1 with _$1 with _$1 with _$1]] forSome {type _$1, type _$1, type _$1, type _$1, type _$1}

    Definition Classes
    ClassesOf
  11. def classesOf[T1, T2, T3, T4](implicit arg0: ClassTag[T1], arg1: ClassTag[T2], arg2: ClassTag[T3], arg3: ClassTag[T4]): Seq[Class[_ >: _$1 with _$1 with _$1 with _$1]] forSome {type _$1, type _$1, type _$1, type _$1}

    Definition Classes
    ClassesOf
  12. def classesOf[T1, T2, T3](implicit arg0: ClassTag[T1], arg1: ClassTag[T2], arg2: ClassTag[T3]): Seq[Class[_ >: _$1 with _$1 with _$1]] forSome {type _$1, type _$1, type _$1}

    Definition Classes
    ClassesOf
  13. def classesOf[T1, T2](implicit arg0: ClassTag[T1], arg1: ClassTag[T2]): Seq[Class[_ >: _$1 with _$1]] forSome {type _$1, type _$1}

    Definition Classes
    ClassesOf
  14. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  15. def doAnswer[T](f: (Any) ⇒ T): Stubber

    delegate to MockitoMocker doAnswer with a MockAnswer object using the function f.

  16. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  18. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  19. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  20. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  21. def ignoreStubs(mocks: AnyRef*): IgnoreStubs

    ignore stubbed methods when verifying that a mock has no more interactions

    ignore stubbed methods when verifying that a mock has no more interactions

    Definition Classes
    MocksCreation
  22. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  23. def mock[T](settings: MockSettings)(implicit arg0: ClassTag[T]): T

    create a mock object with some specific settings: val m = mock[java.

    create a mock object with some specific settings: val m = mock[java.util.List[String]](settings)

    Definition Classes
    MocksCreation
  24. def mock[T](implicit arg0: ClassTag[T]): T

    create a mock object: val m = mock[java.

    create a mock object: val m = mock[java.util.List[String]]

    Definition Classes
    MocksCreation
  25. def mockAs[T](name: String)(implicit arg0: ClassTag[T]): T

    create a mock object with a name: val m = mockAs[java.

    create a mock object with a name: val m = mockAs[java.util.List[String]]("name")

    Definition Classes
    MocksCreation
  26. implicit def mocked[T](t: ⇒ T)(implicit arg0: ClassTag[T]): Mocked[T]

    implicit allowing to define the mock settings with a nice syntax:

    implicit allowing to define the mock settings with a nice syntax:

    • named mock: val m = mock[java.util.List[String]].as("name")
    • smart mock: val m = mock[java.util.List[String]].smart
    • other settings: val m = mock[java.util.List[String]]. settings(name = "list", defaultReturn = 10, extraInterfaces = classesOf[Cloneable, Serializable])
    Definition Classes
    MocksCreation
  27. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  28. final def notify(): Unit

    Definition Classes
    AnyRef
  29. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  30. implicit def ongoingStubbing[M](stubbing: ⇒ OngoingStubbing[_]): M

    Definition Classes
    MockitoStubsLowerImplicits
  31. def smartMock[T](implicit arg0: ClassTag[T]): T

    create a mock object with smart return values: val m = smartMock[java.

    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.

    Definition Classes
    MocksCreation
  32. def spy[T](m: T): T

    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
    Definition Classes
    MocksCreation
  33. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  34. implicit def theStubbed[T](c: ⇒ T): Stubbed[T]

    returns

    an object supporting the stub methods.

  35. def toString(): String

    Definition Classes
    AnyRef → Any
  36. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from MocksCreation

Inherited from ClassesOf

Inherited from TheMockitoMocker

Inherited from AnyRef

Inherited from Any

Ungrouped