Skip to content

Commit

Permalink
Add unit tests for times verification mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Keivan Esbati committed Jan 16, 2020
1 parent 374b46a commit 83691ae
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import org.amshove.kluent.tests.helpclasses.Database
import kotlin.test.Test
import kotlin.test.assertFails

class VerifyCalledOnceShould {
class VerifyUsingTimesShould {

@Test
fun passWhenAMethodWasCalledOnlyOnce() {
fun passWhenAMethodWasCalledSpecifiedTimes() {
val mock = mock(Database::class)
mock.getPerson(1)
mock.getPerson(1)
Verify times 2 on mock that mock.getPerson(1) was called
assertFails { Verify on mock that mock.getPerson(1) was called }
mock.getPerson(5)
Verify on mock that mock.getPerson(1) was called
Verify on mock that mock.getPerson(5) was called
Verify times 2 on mock that mock.getPerson(any()) was called
}

@Test
Expand All @@ -25,10 +26,20 @@ class VerifyCalledOnceShould {
}

@Test
fun failWhenTimesThatAMethodWasCalledDoesNotMatch() {
fun failWhenAMethodWasCalledLessThanSpecified() {
val mock = mock(Database::class)
mock.getPerson(1)
Verify on mock that mock.getPerson(1) was called
assertFails { Verify times 2 on mock that mock.getPerson(any()) was called }
}

@Test
fun failWhenAMethodWasCalledMoreThanSpecified() {
val mock = mock(Database::class)
mock.getPerson(1)
mock.getPerson(5)
Verify on mock that mock.getPerson(1) was called
assertFails { Verify times 2 on mock that mock.getPerson(1) was called }
Verify on mock that mock.getPerson(5) was called
assertFails { Verify times 1 on mock that mock.getPerson(any()) was called }
}
}

0 comments on commit 83691ae

Please sign in to comment.