Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package scalatest

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    Definition Classes
    org
  • package easymock
    Definition Classes
    scalatest
  • EasyMockSugar

object EasyMockSugar extends EasyMockSugar

Companion object that facilitates the importing of EasyMockSugar members as an alternative to mixing it in. One use case is to import EasyMockSugar members so you can use them in the Scala interpreter.

Source
EasyMockSugar.scala
Linear Supertypes
EasyMockSugar, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. EasyMockSugar
  2. EasyMockSugar
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. case class MockObjects (mocks: AnyRef*) extends Product with Serializable

    Holder class for a collection of mocks that can be passed implicitly to one form of the overloaded whenExecuting method.

    Holder class for a collection of mocks that can be passed implicitly to one form of the overloaded whenExecuting method.

    mocks

    one or more mock objects that you intend to pass to whenExecuting

    Definition Classes
    EasyMockSugar
    Exceptions thrown

    IllegalArgumentException if no mocks are passed

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. implicit def call[T](value: T): IExpectationSetters[T]

    Implicit conversion that invokes the expect method on the EasyMock companion object (i.e., the static expect method in Java class org.easymock.EasyMock).

    Implicit conversion that invokes the expect method on the EasyMock companion object (i.e., the static expect method in Java class org.easymock.EasyMock).

    In a ScalaTest Suite, the expect method defined in Assertions, and inherited by Suite, interferes with the expect method if imported from EasyMock. You can invoke it by qualifying it, i.e., EasyMock.expect, or by changing its name on import, like this:

    import org.easymock.EasyMock.{expect => easyMockExpect, _}
    

    But if you mix in this trait, you can just invoke call instead.

    You can use this method, for example, to chain expectations like this:

    expecting {
      call(mock.getName).andReturn("Ben Franklin")
    }
    

    Note: the name of this methods is call, not expectCall because "expect" appears in the surrounding expecting clause provided by this trait.

    Moreover, because this method is marked implicit, you will usually be able to simply leave it off. So long as the result of the method call you are expecting doesn't have a method that satisfies the subsequent invocation (such as andReturn in this example), the Scala compiler will invoke call for you implicitly. Here's how that looks:

    expecting {
      mock.getName.andReturn("Ben Franklin")
    }
    

    value

    - the result of invoking a method on mock prior to invoking replay.

    Definition Classes
    EasyMockSugar
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def expecting(unused: Any): Unit

    Provides a visual clue to readers of the code that a set of statements are expectations being set on mocks.

    Provides a visual clue to readers of the code that a set of statements are expectations being set on mocks.

    Using the EasyMock API directly, you set expectations on a mock object with syntax like:

    mockCollaborator.documentAdded("Document")
    mockCollaborator.documentChanged("Document")
    expectLastCall().times(3)
    

    This expecting method can make it more obvious which portion of your test code is devoted to setting expectations on mock objects. For example:

    expecting {
      mockCollaborator.documentAdded("Document")
      mockCollaborator.documentChanged("Document")
      lastCall.times(3)
    }
    

    Using an expecting clause is optional, because it does nothing besides visually indicate which statements are setting expectations on mocks. Note: this trait also provides the lastCall method, which just calls expectLastCall. This allows you to avoid writing "expect" twice. Also, the reason expecting doesn't take a by-name parameter, execute that, then call replay is because you would then need to pass your mock object or objects into expecting. Since you already need to pass the mocks into whenExecuting so that verify can be invoked on them, it yields more concise client code to have whenExecuting invoke replay on the mocks first rather than having expecting invoke replay last.

    Definition Classes
    EasyMockSugar
  10. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. def lastCall[T]: IExpectationSetters[T]

    Invokes the expectLastCall method on the EasyMock companion object (i.e., the static expect method in Java class org.easymock.EasyMock).

    Invokes the expectLastCall method on the EasyMock companion object (i.e., the static expect method in Java class org.easymock.EasyMock).

    This method is provided simply to allow you to avoid repeating "expect" inside an expecting clause. Here's an example that uses the expectLastCall directly to express the expectation that the getName method will be invoked three times on a mock, each time returning "Ben Franklin":

    expecting {
      mock.getName.andReturn("Ben Franklin")
      expectLastCall.times(3)
    }
    

    Using this method, you can compress this to:

    expecting {
      mock.getName.andReturn("Ben Franklin")
      lastCall.times(3)
    }
    

    Definition Classes
    EasyMockSugar
  15. def mock[T <: AnyRef](implicit classTag: ClassTag[T]): T

    Invokes the createMock method on the EasyMock companion object (i.e., the static createMock method in Java class org.easymock.classextension.EasyMock).

    Invokes the createMock method on the EasyMock companion object (i.e., the static createMock method in Java class org.easymock.classextension.EasyMock).

    Using the EasyMock API directly, you create a mock with:

    val mockCollaborator = createMock(classOf[Collaborator])
    

    Using this method, you can shorten that to:

    val mockCollaborator = mock[Collaborator]
    

    Definition Classes
    EasyMockSugar
  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. def niceMock[T <: AnyRef](implicit classTag: ClassTag[T]): T

    Invokes the createNiceMock method on the EasyMock companion object (i.e., the static createNiceMock method in Java class org.easymock.classextension.EasyMock).

    Invokes the createNiceMock method on the EasyMock companion object (i.e., the static createNiceMock method in Java class org.easymock.classextension.EasyMock).

    Using the EasyMock API directly, you create a nice mock with:

    val mockCollaborator = createNiceMock(classOf[Collaborator])
    

    Using this trait, you can shorten that to:

    val mockCollaborator = niceMock[Collaborator]
    

    Definition Classes
    EasyMockSugar
  18. final def notify(): Unit
    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  20. def strictMock[T <: AnyRef](implicit classTag: ClassTag[T]): T

    Invokes the createStrictMock method on the EasyMock companion object (i.e., the static createStrictMock method in Java class org.easymock.classextension.EasyMock).

    Invokes the createStrictMock method on the EasyMock companion object (i.e., the static createStrictMock method in Java class org.easymock.classextension.EasyMock).

    Using the EasyMock API directly, you create a strict mock with:

    val mockCollaborator = createStrictMock(classOf[Collaborator])
    

    Using this trait, you can shorten that to:

    val mockCollaborator = strictMock[Collaborator]
    

    Definition Classes
    EasyMockSugar
  21. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  22. def toString(): String
    Definition Classes
    AnyRef → Any
  23. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. def whenExecuting(fun: ⇒ Unit)(implicit mocks: MockObjects): Unit

    Invokes replay on the mock object or objects passed via an implicit parameter, executes the passed function, then invokes verify on the passed mock object or objects.

    Invokes replay on the mock object or objects passed via an implicit parameter, executes the passed function, then invokes verify on the passed mock object or objects.

    Once you've set expectations on some mock objects, you must invoke replay on the mocks to indicate you are done setting expectations, and will start using the mocks. After using the mocks, you must invoke verify to check to make sure the mocks were used in accordance with the expectations you set on it. Here's how that looks when you use the EasyMock API directly:

    replay(mock)
    classUnderTest.addDocument("Document", new Array[Byte](0))
    classUnderTest.addDocument("Document", new Array[Byte](0))
    classUnderTest.addDocument("Document", new Array[Byte](0))
    classUnderTest.addDocument("Document", new Array[Byte](0))
    verify(mock)
    

    This method enables you to use the following, more declarative syntax instead:

    implicit val mocks = MockObjects(mockCollaborator)
    
    whenExecuting {
      classUnderTest.addDocument("Document", new Array[Byte](0))
      classUnderTest.addDocument("Document", new Array[Byte](0))
      classUnderTest.addDocument("Document", new Array[Byte](0))
      classUnderTest.addDocument("Document", new Array[Byte](0))
    }
    

    If you are working with multiple mock objects at once, you simply pass them all to MockObjects, like this:

    implicit val mocks = MockObjects(mock1, mock2, mock3)
    

    The whenExecuting method will first invoke EasyMock.reply once for each mock you supplied, execute the passed function, then invoke EasyMock.verify once for each mock you supplied. If an exception is thrown by the passed function, whenExecuting will complete abruptly with that same exception without executing verify on any of the mocks.

    Definition Classes
    EasyMockSugar
  27. def whenExecuting(mocks: AnyRef*)(fun: ⇒ Unit): Unit

    Invokes replay on the passed mock object or objects, executes the passed function, then invokes verify on the passed mock object or objects.

    Invokes replay on the passed mock object or objects, executes the passed function, then invokes verify on the passed mock object or objects.

    Once you've set expectations on some mock objects, you must invoke replay on the mocks to indicate you are done setting expectations, and will start using the mocks. After using the mocks, you must invoke verify to check to make sure the mocks were used in accordance with the expectations you set on it. Here's how that looks when you use the EasyMock API directly:

    replay(mock)
    classUnderTest.addDocument("Document", new Array[Byte](0))
    classUnderTest.addDocument("Document", new Array[Byte](0))
    classUnderTest.addDocument("Document", new Array[Byte](0))
    classUnderTest.addDocument("Document", new Array[Byte](0))
    verify(mock)
    

    This method enables you to use the following, more declarative syntax instead:

    whenExecuting(mockCollaborator) {
      classUnderTest.addDocument("Document", new Array[Byte](0))
      classUnderTest.addDocument("Document", new Array[Byte](0))
      classUnderTest.addDocument("Document", new Array[Byte](0))
      classUnderTest.addDocument("Document", new Array[Byte](0))
    }
    

    If you are working with multiple mock objects at once, you simply pass them all to whenExecuting, like this:

    whenExecuting(mock1, mock2, mock3) {
      // ...
    }
    

    The whenExecuting method will first invoke EasyMock.reply once for each mock you supplied, execute the passed function, then invoke EasyMock.verify once for each mock you supplied. If an exception is thrown by the passed function, whenExecuting will complete abruptly with that same exception without executing verify on any of the mocks.

    mocks

    one or more mock objects to invoke replay before using and verify after using.

    Definition Classes
    EasyMockSugar
    Exceptions thrown

    IllegalArgumentException if no mocks are passed

Inherited from EasyMockSugar

Inherited from AnyRef

Inherited from Any

Ungrouped