Created
April 3, 2019 07:51
-
-
Save gumil/f373572f67bce365116a9de9067c14dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 kotlin.test.assertEquals | |
| import kotlin.test.assertTrue | |
| internal class Verifier<T> { | |
| val function: (T) -> Unit = { | |
| invokedValues.add(it) | |
| } | |
| private var invokedValues = mutableListOf<T>() | |
| fun verifyInvokedWithValue(value: T, times: Int = 1) { | |
| assertEquals(invokedValues.filter { it == value }.size, times) | |
| } | |
| fun verifyNoInvocations() { | |
| assertTrue { invokedValues.isEmpty() } | |
| } | |
| fun verifyOrder(verifyBuilder: OrderedBuilder<T>.() -> Unit) { | |
| val orderedBuilder = OrderedBuilder<T>() | |
| verifyBuilder(orderedBuilder) | |
| orderedBuilder.values.forEachIndexed { index, value -> | |
| assertEquals(invokedValues[index], value) | |
| } | |
| } | |
| internal class OrderedBuilder<T> { | |
| private val _values = mutableListOf<T>() | |
| val values: List<T> = _values | |
| fun verify(value: T) { | |
| _values.add(value) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment