-
-
Save OlegYch/3226212 to your computer and use it in GitHub Desktop.
Partial verification of arguments passed to a mocked method in specs2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.specs2.mock.Mockito | |
import org.specs2.mutable.SpecificationWithJUnit | |
import org.specs2.mock.mockito.MockitoFunctions | |
class LearningTest extends SpecificationWithJUnit { | |
trait Logger { | |
def error(a: String, e: Throwable) | |
} | |
class mocks extends Mockito with MockitoFunctions { | |
val mockedLogger = mock[Logger] | |
} | |
"mocking" should { | |
"be able to verify arguments passed to mocks" in { | |
val m = new mocks | |
import m._ | |
val exception = new RuntimeException | |
mockedLogger.error("message", exception) | |
got { | |
one(mockedLogger).error("message1", exception) | |
} | |
} | |
"be able to *partially* verify arguments passed to mocks" in { | |
val m = new mocks | |
import m._ | |
val exception = new IllegalArgumentException | |
mockedLogger.error("message", exception) | |
got { | |
one(mockedLogger).error(any[String], ===(exception)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[INFO] +- junit:junit:jar:4.8.1:test
[INFO] +- org.specs2:specs2_2.9.2:jar:1.9:test
[INFO] | - org.specs2:specs2-scalaz-core_2.9.2:jar:6.0.1:runtime (scope managed from test)
[INFO] +- org.hamcrest:hamcrest-all:jar:1.1:test
[INFO] - org.mockito:mockito-all:jar:1.9.0:test