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 drink() { | |
| if (canDrink) { | |
| System.out.println("Drinking .. ") | |
| } else { | |
| throw UnderageDrinkingException() | |
| } | |
| } |
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
| @Test | |
| fun `friends are correctly added`() { | |
| val rui = User(firstName = "Rui", lastName = "Gonçalo", age = 28) | |
| val fabio = User(firstName = "Fábio", lastName = "Carballo", age = 26) | |
| rui.addFriend(fabio) | |
| assertEquals(listOf(fabio), rui.friends) | |
| // OR |
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
| infix fun Any.`should equal`(theOther: Any) = assertEquals(theOther, this) |
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
| @Test | |
| fun `the full name is the concatenation of the first and last name`() { | |
| val user = User(firstName = "Fábio", lastName = "Carballo", age = 26) | |
| assertEquals("Fábio Carballo", user.fullName) | |
| } |
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 User( | |
| private val firstName: String, | |
| private val lastName: String, | |
| private val age: Int) { | |
| val fullName = "$firstName $lastName" | |
| val canDrink = (age >= 18) | |
| val friends: MutableList<User> = mutableListOf() |
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 User( | |
| private val firstName: String, | |
| private val lastName: String, | |
| private val age: Int) { | |
| val fullName = "$firstName $lastName" | |
| val canDrink = (age >= 18) | |
| val friends: MutableList<User> = mutableListOf() |
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 TemperaturePresenterTest { | |
| private val lastLocation = Coordinate(41.5, 8.9) | |
| private val currentLocation = Coordinate(38.7, 9.7) | |
| val locationProvider: LocationProvider = mock { | |
| on { getLastKnownLocation() }.then { lastLocation } | |
| on { getExactLocation() }.then { currentLocation } | |
| } |
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 TemperaturePresenterTest { | |
| @Mock lateinit var locationProvider: LocationProvider | |
| @Mock lateinit var temperatureProvider: TemperatureProvider | |
| @Mock lateinit var view: View | |
| lateinit var tested: TemperaturePresenter | |
| @Before | |
| fun setUp() { |
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 TemperaturePresenterTest { | |
| @Mock lateinit var locationProvider: LocationProvider | |
| @Mock lateinit var temperatureProvider: TemperatureProvider | |
| @Mock lateinit var view: View | |
| lateinit var tested: TemperaturePresenter | |
| @Before |
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 org.junit.Before; | |
| import org.junit.Test; | |
| import org.mockito.InOrder; | |
| import org.mockito.Mock; | |
| import org.mockito.Mockito; | |
| import org.mockito.MockitoAnnotations; | |
| public class TemperaturePresenterJavaTest { |