1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package test.utils
import kotlin.test.*
class TODOTest {
private class PartiallyImplementedClass {
public val prop: String get() = TODO()
@Suppress("UNREACHABLE_CODE", "CAST_NEVER_SUCCEEDS")
fun method1() = TODO() as String
public fun method2(): Int = TODO()
public fun method3(switch: Boolean, value: String): String {
if (!switch)
TODO("what if false")
else {
if (value.length < 3)
throw TODO("write message")
}
return value
}
public fun method4() {
TODO()
}
}
private fun assertNotImplemented(block: () -> Unit) {
assertFailsWith<NotImplementedError>(block = block)
}
private fun assertNotImplementedWithMessage(message: String, block: () -> Unit) {
val e = assertFailsWith<NotImplementedError>(block = block)
assertTrue(message in e.message!!)
}
@Test
fun usage() {
val inst = PartiallyImplementedClass()
assertNotImplemented { inst.prop }
assertNotImplemented { inst.method1() }
assertNotImplemented { inst.method2() }
assertNotImplemented { inst.method4() }
assertNotImplementedWithMessage("what if false") { inst.method3(false, "test") }
assertNotImplementedWithMessage("write message") { inst.method3(true, "t") }
assertEquals("test", inst.method3(true, "test"))
}
}
|