Clean TODOs and commented code which works.

This commit is contained in:
Ilya Ryzhenkov
2014-03-05 20:33:13 +04:00
committed by Andrey Breslav
parent 266f6ad81a
commit fb7034a472
6 changed files with 21 additions and 23 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ public fun <T> assertNotNull(actual: T?, message: String = ""): T {
return actual!! return actual!!
} }
//TODO merge with next via default //TODO merge with next via default (currently inline functions do not support default values)
/** Asserts that the expression is not null, with an optional message and a function block to process the not-null value */ /** Asserts that the expression is not null, with an optional message and a function block to process the not-null value */
public inline fun <T, R> assertNotNull(actual: T?, block: (T) -> R) { public inline fun <T, R> assertNotNull(actual: T?, block: (T) -> R) {
assertNotNull(actual, "", block) assertNotNull(actual, "", block)
+2 -3
View File
@@ -29,12 +29,11 @@ class ExceptionTest {
fun assertPrintStackTraceStream(t: Throwable) { fun assertPrintStackTraceStream(t: Throwable) {
val byteBuffer = ByteArrayOutputStream() val byteBuffer = ByteArrayOutputStream()
/*
// TODO compiler error
PrintStream(byteBuffer).use { PrintStream(byteBuffer).use {
t.printStackTrace(it) t.printStackTrace(it)
} }
*/
val stream = PrintStream(byteBuffer) val stream = PrintStream(byteBuffer)
stream.use { stream.use {
t.printStackTrace(stream) t.printStackTrace(stream)
+11 -12
View File
@@ -33,7 +33,7 @@ class PreconditionsTest() {
test fun failingRequireWithLazyMessage() { test fun failingRequireWithLazyMessage() {
val error = failsWith(javaClass<IllegalArgumentException>()) { val error = failsWith(javaClass<IllegalArgumentException>()) {
require(false) {"Hello"} require(false) { "Hello" }
} }
assertEquals("Hello", error.getMessage()) assertEquals("Hello", error.getMessage())
} }
@@ -66,7 +66,7 @@ class PreconditionsTest() {
test fun failingCheckWithLazyMessage() { test fun failingCheckWithLazyMessage() {
val error = failsWith(javaClass<IllegalStateException>()) { val error = failsWith(javaClass<IllegalStateException>()) {
check(false) {"Hello"} check(false) { "Hello" }
} }
assertEquals("Hello", error.getMessage()) assertEquals("Hello", error.getMessage())
} }
@@ -105,16 +105,15 @@ class PreconditionsTest() {
assertFalse(called) assertFalse(called)
} }
test fun failingAssert() {
val assertDefaultMessage = "Assertion failed"
test fun failingAssert() {
val error = fails { val error = fails {
assert(false) assert(false)
} }
if(error is AssertionError) { if (error is AssertionError) {
assertEquals(assertDefaultMessage, error.getMessage()) assertEquals("Assertion failed", error.getMessage())
} else { } else {
fail("Invalid exception type: "+error) fail("Invalid exception type: " + error)
} }
} }
@@ -126,21 +125,21 @@ class PreconditionsTest() {
val error = fails { val error = fails {
assert(false, "Hello") assert(false, "Hello")
} }
if(error is AssertionError) { if (error is AssertionError) {
assertEquals("Hello", error.getMessage()) assertEquals("Hello", error.getMessage())
} else { } else {
fail("Invalid exception type: "+error) fail("Invalid exception type: " + error)
} }
} }
test fun failingAssertWithLazyMessage() { test fun failingAssertWithLazyMessage() {
val error = fails { val error = fails {
assert(false) {"Hello"} assert(false) { "Hello" }
} }
if(error is AssertionError) { if (error is AssertionError) {
assertEquals("Hello", error.getMessage()) assertEquals("Hello", error.getMessage())
} else { } else {
fail("Invalid exception type: "+error) fail("Invalid exception type: " + error)
} }
} }
} }
@@ -30,7 +30,7 @@ fun productSnippet(product: Product) = "<li>${product.name}. Price : ${product.p
class StringExpressionExampleTest : TestCase() { class StringExpressionExampleTest : TestCase() {
val customer = Customer("James", arrayList(Product("Beer", 1.99), Product("Wine", 5.99))) val customer = Customer("James", arrayListOf(Product("Beer", 1.99), Product("Wine", 5.99)))
fun testExpressions(): Unit { fun testExpressions(): Unit {
println(customerTemplate(customer)) println(customerTemplate(customer))
@@ -9,7 +9,7 @@ import junit.framework.TestCase
class Kt1617Test: TestCase() { class Kt1617Test: TestCase() {
fun testMapFunction() { fun testMapFunction() {
val coll: Collection<String> = arrayList("foo", "bar") val coll: Collection<String> = arrayListOf("foo", "bar")
val files = coll.map{ File(it) } val files = coll.map{ File(it) }
@@ -1,16 +1,16 @@
package regressions package regressions
import junit.framework.TestCase import junit.framework.TestCase
import kotlin.test.expect
class Kt1619Test: TestCase() { class Kt1619Test: TestCase() {
fun doSomething(list: List<String?>): Boolean { fun doSomething(list: List<String?>): Int {
return list.size() > 0 return list.size()
} }
fun testCollectionNotNullCanBeUsedForNullables() { fun testCollectionNotNullCanBeUsedForNullables() {
val list: List<String> = arrayList("foo", "bar") val list: List<String> = arrayListOf("foo", "bar")
// TODO uncomment this line to reproduce KT-1619 expect(2) { doSomething(list) }
// doSomething(list)
} }
} }