Created
June 15, 2017 12:26
-
-
Save maciejwalkowiak/98e844e884e77609404f07b7ed479fd4 to your computer and use it in GitHub Desktop.
mockito-kotlin
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
interface Analytics<in T> { | |
fun send(event : T) | |
} |
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
data class Event(val foo: String) |
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 com.nhaarman.mockito_kotlin.KArgumentCaptor | |
import com.nhaarman.mockito_kotlin.argumentCaptor | |
import org.assertj.core.api.Assertions.assertThat | |
import org.junit.Before | |
import org.junit.Test | |
import org.mockito.Mock | |
import org.mockito.Mockito.verify | |
import org.mockito.MockitoAnnotations | |
class SomeTest { | |
@Mock | |
private lateinit var analytics : Analytics<Event> | |
private val captor : KArgumentCaptor<Event> = argumentCaptor() | |
@Before | |
fun setup() { | |
MockitoAnnotations.initMocks(this) | |
} | |
@Test | |
fun foo() { | |
val event = Event("foo") | |
analytics.send(event) | |
verify(analytics).send(captor.capture()) | |
assertThat(captor.firstValue).isEqualTo(event) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment