Created
June 9, 2017 01:11
-
-
Save GabriellCosta/3efbc35c99f39d03f2e5212fa78df758 to your computer and use it in GitHub Desktop.
Metodo como parametro
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
package util | |
import org.junit.Before | |
import org.junit.Test | |
import org.mockito.Mockito.* | |
import kotlin.reflect.KFunction1 | |
class MethodParameterTest { | |
private lateinit var mock: IPresenter | |
@Before fun setup() { | |
mock = mock(IPresenter::class.java) | |
} | |
@Test fun whenExecute_shouldClick() { | |
val temMock = TemMock(mock) | |
temMock.executa() | |
validaClick(IPresenter::click, verify(mock)) | |
} | |
@Test fun whenExecute_shouldNotDouble() { | |
val temMock = TemMock(mock) | |
temMock.executa() | |
validaClick(IPresenter::double, verify(mock, never())) | |
} | |
private fun validaClick(kFunction1: KFunction1<IPresenter, Unit>, mock: IPresenter) { | |
kFunction1.invoke(mock) | |
} | |
} | |
class TemMock(private val presenter: IPresenter) { | |
fun executa() { | |
presenter.click() | |
} | |
} | |
interface IPresenter { | |
fun click() | |
fun double() | |
} | |
open class Presenter: IPresenter { | |
override fun click() { | |
println("click") | |
} | |
override fun double() { | |
println("double") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment