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
| package testing.fabiocarballo.com.myapplication | |
| import com.nhaarman.mockito_kotlin.mock | |
| import com.nhaarman.mockito_kotlin.verify | |
| import com.nhaarman.mockito_kotlin.whenever | |
| import org.junit.Test | |
| class TemperaturePresenterTest { | |
| val locationProvider: LocationProvider = mock() |
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
| package testing.fabiocarballo.com.myapplication | |
| import com.nhaarman.mockito_kotlin.mock | |
| import com.nhaarman.mockito_kotlin.verify | |
| import com.nhaarman.mockito_kotlin.whenever | |
| import org.junit.Test | |
| class TemperaturePresenterTest { | |
| val locationProvider: LocationProvider = mock() |
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
| class Coordinate(latitude: Double, longitude: Double) | |
| interface LocationProvider { | |
| fun getLastKnownLocation(): Coordinate | |
| fun getExactLocation(): Coordinate | |
| } | |
| interface TemperatureProvider { | |
| fun getCelsiusTemperatureAt(coordinate: Coordinate): Float |
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
| fun <String> on(methodCall: LocationProvider.() -> String): OngoingStubbing<String> { | |
| return try { | |
| Mockito.`when`(mock.methodCall()) | |
| } catch(e: NullPointerException) { | |
| throw Exception(....) | |
| } | |
| } |
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
| class GreeterTest { | |
| var user: User = mock() | |
| val tested = Greeter(user) | |
| @Test | |
| fun englishGreetIsCorrect() { | |
| Mockito.`when`(user.fullName()).thenReturn("Fábio Carballo") |
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
| @RunWith(KotlinTestRunner::class) | |
| class GreeterTest { | |
| ... | |
| } |
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
| open class User( | |
| private val firstName: String, | |
| private val lastName: String) { | |
| open fun fullName(): String = "$firstName $lastName" | |
| } |
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 org.junit.Before | |
| import org.junit.Test | |
| import org.junit.Assert.* | |
| import org.mockito.Mock | |
| import org.mockito.Mockito | |
| import org.mockito.MockitoAnnotations | |
| class GreeterTest { |
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
| // Class that is going to be the focus of our test | |
| class Greeter( | |
| private val user: User) { | |
| fun getEnglishGreeting() = "Hello, ${user.fullName()}!" | |
| } | |
| // Class used as a dependency | |
| class User( | |
| private val firstName: 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
| class AppExceptionHandler(val systemHandler: Thread.UncaughtExceptionHandler, | |
| val crashlyticsHandler: Thread.UncaughtExceptionHandler, | |
| application: Application) : Thread.UncaughtExceptionHandler { | |
| private var lastStartedActivity: Activity? = null | |
| private var startCount = 0 | |
| init { | |
| application.registerActivityLifecycleCallbacks( |