Last active
July 15, 2016 03:01
-
-
Save sys1yagi/52fe984011ad9fbe9cb7ba7fa6aaa298 to your computer and use it in GitHub Desktop.
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
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
dependencies { | |
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | |
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-generate:0.1-alpha' | |
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-async:0.1-alpha' | |
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-rx:0.1-alpha' | |
testCompile 'junit:junit:4.12' | |
testCompile 'org.robolectric:robolectric:3.0' | |
testCompile('com.squareup.assertj:assertj-android:1.1.1') { | |
exclude group: 'com.android.support', module: 'support-annotations' | |
} | |
testCompile('com.github.sys1yagi:kmockito:0.1.1') { | |
exclude group: 'org.mockito', module: 'mockito-core' | |
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib' | |
} | |
testCompile 'org.mockito:mockito-core:2.0.28-beta' | |
} | |
buildscript { | |
ext.kotlin_version = '1.1-M01' | |
repositories { | |
mavenCentral() | |
jcenter() | |
maven { url ='https://dl.bintray.com/kotlin/kotlin-eap-1.1' } | |
} | |
dependencies { | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" | |
} | |
} | |
repositories { | |
mavenCentral() | |
maven { url="https://dl.bintray.com/kotlin/kotlin-eap-1.1" } | |
maven { url="https://dl.bintray.com/kotlin/kotlinx.coroutines" } | |
} |
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 jp.dip.sys1.aozora.util | |
import android.view.View | |
import com.sys1yagi.kmockito.mock | |
import kotlinx.coroutines.asyncRx | |
import org.assertj.core.api.Assertions.assertThat | |
import org.junit.Assert | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
import org.robolectric.RobolectricTestRunner | |
import rx.Observable | |
import rx.observers.TestSubscriber | |
@RunWith(RobolectricTestRunner::class) | |
class Kotlin11Test { | |
// Type Alias | |
typealias OnClickListener = (View) -> Unit | |
inline fun setOnClickListener(listener: OnClickListener) { | |
listener(mock()) | |
} | |
@Test | |
fun TypeAlias() { | |
setOnClickListener { | |
//success | |
return | |
} | |
Assert.fail() | |
} | |
// BoundCallableReferences | |
class Printer { | |
fun print(text: String) { | |
println(text) | |
} | |
} | |
@Test | |
fun BoundCallableReferences() { | |
val printer = Printer() | |
listOf(1, 2, 3, 4, 5) | |
.map { it.toString() } | |
.forEach(printer::print) | |
} | |
// LocalDelegatedProperty | |
@Test | |
fun localDelegatedProperty() { | |
val text by lazy { "Hello local delegate property" } | |
println(text) | |
} | |
// Coroutine | |
// see more https://github.com/Kotlin/kotlinx.coroutines | |
@Test | |
fun coroutine() { | |
// 正直なんでこれで動くのかよくわかんねー | |
val observable = asyncRx<String> { | |
Observable.just("test").awaitSingle() | |
} | |
val testSubscriber = TestSubscriber<String>() | |
observable | |
.subscribe(testSubscriber) | |
testSubscriber.awaitTerminalEvent() | |
testSubscriber.assertNoErrors() | |
assertThat(testSubscriber.onNextEvents[0]).isEqualTo("test") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment