Skip to content

Instantly share code, notes, and snippets.

@fbcbl
fbcbl / kotlin_testing_pt3_example2.kt
Created October 24, 2017 14:09
kotlin_testing_pt3_example2
fun drink() {
if (canDrink) {
System.out.println("Drinking .. ")
} else {
throw UnderageDrinkingException()
}
}
@fbcbl
fbcbl / kotlin_testing_pt3_test_2.kt
Created October 24, 2017 13:40
kotlin_testing_pt3_test_2
@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
@fbcbl
fbcbl / kotlin_testing_pt3_infix.kt
Created October 24, 2017 13:04
kotlin_testing_pt3_infix
infix fun Any.`should equal`(theOther: Any) = assertEquals(theOther, this)
@fbcbl
fbcbl / kotlin_testing_pt3_test_1.kt
Created October 24, 2017 12:54
kotlin_testing_pt3_test_1
@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)
}
@fbcbl
fbcbl / kotlin_testing_pt3_example.kt
Last active October 24, 2017 14:23
kotlin_testing_pt3_example
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()
@fbcbl
fbcbl / kotlin_testing_pt3_example.kt
Created October 10, 2017 13:28
kotlin_testing_pt3_example
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()
@fbcbl
fbcbl / kotlin_testing_pt2_example_1_test_3.kt
Last active October 9, 2017 10:57
kotlin_testing_pt2_example_1_test_3
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 }
}
@fbcbl
fbcbl / kotlin_testing_pt2_example_1_test_2.kt
Last active October 9, 2017 10:54
kotlin_testing_pt2_example_1_test_2
class TemperaturePresenterTest {
@Mock lateinit var locationProvider: LocationProvider
@Mock lateinit var temperatureProvider: TemperatureProvider
@Mock lateinit var view: View
lateinit var tested: TemperaturePresenter
@Before
fun setUp() {
class TemperaturePresenterTest {
@Mock lateinit var locationProvider: LocationProvider
@Mock lateinit var temperatureProvider: TemperatureProvider
@Mock lateinit var view: View
lateinit var tested: TemperaturePresenter
@Before
@fbcbl
fbcbl / kotlin_testing_pt2_example_2_java_test.kt
Last active October 9, 2017 12:28
kotlin_testing_pt2_example_2_java_test
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 {