This is a specs2 adapter + DSL for using the popular mocking framework JMock
<dependency>
<groupId>com.wix</groupId>
<artifactId>specs2-jmock_${scala.version}</artifactId>
<version>x.y.z</version>
<scope>test</scope>
</dependency>
libraryDependencies += "com.wix" %% "specs2-jmock" % "x.y.z"
- for latest version check releases
Mixin the JMock
trait to your Specification class, and use the DSL.
import com.wixpress.common.specs2.JMock
class JMockTest extends Specification with JMock {
"My JMock test" should {
"Do something" in {
val mockFoo = mock[FooTrait]
checking {
allowing(mockFoo).bar.willReturn("foo")
oneOf(mockFoo).baz()
}
val result = mockFoo.bar
mockFoo.baz
result must be equalTo "foo"
}
...
}
You can see more examples in the tests.
Use of this source code is governed by a BSD-style license which you can find here.