aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test/kotlin/test/VerificationTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/test/kotlin/test/VerificationTest.kt')
-rw-r--r--tests/src/test/kotlin/test/VerificationTest.kt115
1 files changed, 115 insertions, 0 deletions
diff --git a/tests/src/test/kotlin/test/VerificationTest.kt b/tests/src/test/kotlin/test/VerificationTest.kt
new file mode 100644
index 0000000..f2f92fd
--- /dev/null
+++ b/tests/src/test/kotlin/test/VerificationTest.kt
@@ -0,0 +1,115 @@
+package test
+
+import com.nhaarman.expect.expect
+import org.junit.Test
+import org.mockito.exceptions.base.MockitoAssertionError
+import org.mockito.kotlin.*
+import org.mockito.kotlin.verify
+
+class VerificationTest : TestBase() {
+
+ @Test
+ fun atLeastXInvocations() {
+ mock<Methods>().apply {
+ string("")
+ string("")
+
+ verify(this, atLeast(2)).string(any())
+ }
+ }
+
+ @Test
+ fun testAtLeastOnce() {
+ mock<Methods>().apply {
+ string("")
+ string("")
+
+ verify(this, atLeastOnce()).string(any())
+ }
+ }
+
+ @Test
+ fun atMostXInvocations() {
+ mock<Methods>().apply {
+ string("")
+ string("")
+
+ verify(this, atMost(2)).string(any())
+ }
+ }
+
+ @Test
+ fun testCalls() {
+ mock<Methods>().apply {
+ string("")
+ string("")
+
+ inOrder(this).verify(this, calls(2)).string(any())
+ }
+ }
+
+ @Test
+ fun testInOrderWithLambda() {
+ /* Given */
+ val a = mock<() -> Unit>()
+ val b = mock<() -> Unit>()
+
+ /* When */
+ b()
+ a()
+
+ /* Then */
+ inOrder(a, b) {
+ verify(b).invoke()
+ verify(a).invoke()
+ }
+ }
+
+ @Test
+ fun testInOrderWithReceiver() {
+ /* Given */
+ val mock = mock<Methods>()
+
+ /* When */
+ mock.string("")
+ mock.int(0)
+
+ /* Then */
+ mock.inOrder {
+ verify().string(any())
+ verify().int(any())
+ verifyNoMoreInteractions()
+ }
+ }
+
+ @Test
+ fun testClearInvocations() {
+ val mock = mock<Methods>().apply {
+ string("")
+ }
+
+ clearInvocations(mock)
+
+ verify(mock, never()).string(any())
+ }
+
+ @Test
+ fun testDescription() {
+ try {
+ mock<Methods>().apply {
+ verify(this, description("Test")).string(any())
+ }
+ throw AssertionError("Verify should throw Exception.")
+ } catch (e: MockitoAssertionError) {
+ expect(e.message).toContain("Test")
+ }
+ }
+
+ @Test
+ fun testAfter() {
+ mock<Methods>().apply {
+ int(3)
+ verify(this, after(10)).int(3)
+ }
+ }
+} \ No newline at end of file