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
val testScheduler = TestScheduler() | |
val states = listOf(Loading, Loaded, ClickX, ClickY) | |
@Test | |
fun `loading followed 500ms later by loaded is emitted`() { | |
val observable = Observable.fromIterable(listOf(0, 500, 1000, 2000)) | |
.zipWith(states) { index, state -> Pair(index, state) } | |
.delay { | |
Observable.timer(it.first.toLong(), TimeUnit.MILLISECONDS, testScheduler) |
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
import org.easymock.EasyMock.* | |
import org.easymock.EasyMockSupport | |
import org.easymock.Mock | |
import org.junit.Before | |
import org.junit.Test | |
class EasyMock { | |
@Mock | |
lateinit var mock: MutableList<String> |
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
class Mockito { | |
@Mock | |
lateinit var mock: MutableList<String> | |
@Before | |
fun setUp() { | |
MockitoAnnotations.initMocks(this) | |
} |
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
import com.nhaarman.mockitokotlin2.whenever | |
import org.junit.Before | |
import org.junit.Test | |
import org.mockito.Mock | |
import org.mockito.Mockito.verify | |
import org.mockito.MockitoAnnotations | |
class MockitoKotlin { | |
@Mock |
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
fun main() { | |
var string: String = "abc" | |
string = null // compiler error | |
} |
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
fun List<Int>.myMax(): Int? { | |
val iterator = iterator() | |
if (!iterator.hasNext()) return null | |
var max = iterator.next() | |
while (iterator.hasNext()) { | |
val e = iterator.next() | |
if (max < e) max = e | |
} | |
return max | |
} |
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
class ValueBased { | |
@Test | |
fun testLargestValue() { | |
val ints = listOf(4, 8, 7) | |
assertEquals(8, ints.myMax()) | |
} | |
@Test |
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
fun List<Int>.myMax(): Int? { | |
return if (this.size < 2) null else this[1] | |
} |
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
import io.kotlintest.matchers.beGreaterThan | |
import io.kotlintest.matchers.collections.shouldContain | |
import io.kotlintest.properties.assertAll | |
import io.kotlintest.shouldBe | |
import io.kotlintest.shouldNot | |
import io.kotlintest.specs.StringSpec | |
class KotlinTest : StringSpec() { | |
init { |
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
import io.kotlintest.matchers.beGreaterThan | |
import io.kotlintest.matchers.collections.shouldContain | |
import io.kotlintest.properties.assertAll | |
import io.kotlintest.shouldBe | |
import io.kotlintest.shouldNot | |
import io.kotlintest.specs.StringSpec | |
class KotlinTest : StringSpec() { | |
init { |