From dd4b50821338d97ba894ad52bf974232ddb5b5d3 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 29 Jan 2013 20:43:36 +0400 Subject: [PATCH] Adapted usage of failsWith(). --- libraries/stdlib/test/ArraysJVMTest.kt | 4 +- libraries/stdlib/test/ArraysTest.kt | 4 +- libraries/stdlib/test/CollectionTest.kt | 6 +- libraries/stdlib/test/PreconditionsTest.kt | 16 ++--- libraries/stdlib/test/StringJVMTest.kt | 4 +- .../stdlib/test/iterators/IteratorsTest.kt | 4 +- libraries/stdlib/test/language/RangeTest.kt | 70 +++++++++---------- 7 files changed, 54 insertions(+), 54 deletions(-) diff --git a/libraries/stdlib/test/ArraysJVMTest.kt b/libraries/stdlib/test/ArraysJVMTest.kt index e20bfd6b428..8049a44bb2f 100644 --- a/libraries/stdlib/test/ArraysJVMTest.kt +++ b/libraries/stdlib/test/ArraysJVMTest.kt @@ -38,7 +38,7 @@ class ArraysJVMTest { expect(0.toByte()) { byteArray(3, 2, 1) reduce { a, b -> (a - b).toByte() } } expect(0.toShort()) { shortArray(3, 2, 1) reduce { a, b -> (a - b).toShort() } } - failsWith { + failsWith (javaClass()) { intArray().reduce { a, b -> a + b} } } @@ -54,7 +54,7 @@ class ArraysJVMTest { expect(2.toByte()) { byteArray(1, 2, 3) reduceRight { a, b -> (a - b).toByte() } } expect(2.toShort()) { shortArray(1, 2, 3) reduceRight { a, b -> (a - b).toShort() } } - failsWith { + failsWith (javaClass()) { intArray().reduceRight { a, b -> a + b} } } diff --git a/libraries/stdlib/test/ArraysTest.kt b/libraries/stdlib/test/ArraysTest.kt index 6e1760077a7..e1aec0d471f 100644 --- a/libraries/stdlib/test/ArraysTest.kt +++ b/libraries/stdlib/test/ArraysTest.kt @@ -48,7 +48,7 @@ class ArraysTest { // Fails in JS: expect(0.toByte()) { byteArray(3, 2, 1) reduce { a, b -> (a - b).toByte() } } // Fails in JS: expect(0.toShort()) { shortArray(3, 2, 1) reduce { a, b -> (a - b).toShort() } } - failsWith { + failsWith(javaClass()) { intArray().reduce { a, b -> a + b} } } @@ -64,7 +64,7 @@ class ArraysTest { // Fails in JS: expect(2.toByte()) { byteArray(1, 2, 3) reduceRight { a, b -> (a - b).toByte() } } // Fails in JS: expect(2.toShort()) { shortArray(1, 2, 3) reduceRight { a, b -> (a - b).toShort() } } - failsWith { + failsWith(javaClass()) { intArray().reduceRight { a, b -> a + b} } } diff --git a/libraries/stdlib/test/CollectionTest.kt b/libraries/stdlib/test/CollectionTest.kt index 19d758ca037..d53ff076aff 100644 --- a/libraries/stdlib/test/CollectionTest.kt +++ b/libraries/stdlib/test/CollectionTest.kt @@ -189,7 +189,7 @@ class CollectionTest { list.reduce { a, b -> a + b } } - failsWith { + failsWith(javaClass()) { arrayList().reduce { a, b -> a + b} } } @@ -200,7 +200,7 @@ class CollectionTest { list.reduceRight { a, b -> a + b } } - failsWith { + failsWith(javaClass()) { arrayList().reduceRight { a, b -> a + b} } } @@ -271,7 +271,7 @@ class CollectionTest { assertEquals(arrayList("foo", "bar"), notNull) val hasNulls = arrayList("foo", null, "bar") - failsWith { + failsWith(javaClass()) { // should throw an exception as we have a null hasNulls.requireNoNulls() } diff --git a/libraries/stdlib/test/PreconditionsTest.kt b/libraries/stdlib/test/PreconditionsTest.kt index 082b0bd1635..784fcc3e4aa 100644 --- a/libraries/stdlib/test/PreconditionsTest.kt +++ b/libraries/stdlib/test/PreconditionsTest.kt @@ -14,7 +14,7 @@ class PreconditionsTest() { } test fun failingRequire() { - val error = failsWith { + val error = failsWith(javaClass()) { require(false) } assertNotNull(error.getMessage()) @@ -25,14 +25,14 @@ class PreconditionsTest() { } test fun failingRequireWithMessage() { - val error = failsWith { + val error = failsWith(javaClass()) { require(false, "Hello") } assertEquals("Hello", error.getMessage()) } test fun failingRequireWithLazyMessage() { - val error = failsWith { + val error = failsWith(javaClass()) { require(false) {"Hello"} } assertEquals("Hello", error.getMessage()) @@ -47,7 +47,7 @@ class PreconditionsTest() { } test fun failingCheck() { - val error = failsWith { + val error = failsWith(javaClass()) { check(false) } assertNotNull(error.getMessage()) @@ -58,14 +58,14 @@ class PreconditionsTest() { } test fun failingCheckWithMessage() { - val error = failsWith { + val error = failsWith(javaClass()) { check(false, "Hello") } assertEquals("Hello", error.getMessage()) } test fun failingCheckWithLazyMessage() { - val error = failsWith { + val error = failsWith(javaClass()) { check(false) {"Hello"} } assertEquals("Hello", error.getMessage()) @@ -78,7 +78,7 @@ class PreconditionsTest() { } test fun requireNotNullFails() { - failsWith { + failsWith(javaClass()) { val s2: String? = null requireNotNull(s2) } @@ -91,7 +91,7 @@ class PreconditionsTest() { } test fun checkNotNullFails() { - failsWith { + failsWith(javaClass()) { val s2: String? = null checkNotNull(s2) } diff --git a/libraries/stdlib/test/StringJVMTest.kt b/libraries/stdlib/test/StringJVMTest.kt index f437104d3cd..c7808ba5bb2 100644 --- a/libraries/stdlib/test/StringJVMTest.kt +++ b/libraries/stdlib/test/StringJVMTest.kt @@ -179,7 +179,7 @@ class StringJVMTest { // get the smallest character(by char value) assertEquals('a', "bacfd".reduce { v, c -> if (v > c) c else v }) - failsWith { + failsWith(javaClass()) { "".reduce { a, b -> '\n' } } } @@ -188,7 +188,7 @@ class StringJVMTest { // get the smallest character(by char value) assertEquals('a', "bacfd".reduceRight { c, v -> if (v > c) c else v }) - failsWith { + failsWith(javaClass()) { "".reduceRight { a, b -> '\n' } } } diff --git a/libraries/stdlib/test/iterators/IteratorsTest.kt b/libraries/stdlib/test/iterators/IteratorsTest.kt index 09764c9bac7..fae3fc23b97 100644 --- a/libraries/stdlib/test/iterators/IteratorsTest.kt +++ b/libraries/stdlib/test/iterators/IteratorsTest.kt @@ -2,7 +2,7 @@ package iterators import kotlin.test.assertEquals import org.junit.Test as test -import kotlin.test.failsWith +import kotlin.test.fails fun fibonacci(): Iterator { // fibonacci terms @@ -66,7 +66,7 @@ class IteratorsTest { val iterWithNulls = arrayList("foo", null, "bar").iterator() val notNull2 = iterWithNulls.requireNoNulls() - failsWith { + fails { // should throw an exception as we have a null notNull2.toList() } diff --git a/libraries/stdlib/test/language/RangeTest.kt b/libraries/stdlib/test/language/RangeTest.kt index 5fe74b03196..6de0520ab77 100644 --- a/libraries/stdlib/test/language/RangeTest.kt +++ b/libraries/stdlib/test/language/RangeTest.kt @@ -145,44 +145,44 @@ public class RangeTest { test fun illegalSequenceCreation() { // create sequence explicitly with increment = 0 - failsWith { IntSequence(0, 5, 0) } - failsWith { ByteSequence(0, 5, 0) } - failsWith { ShortSequence(0, 5, 0) } - failsWith { LongSequence(0, 5, 0) } - failsWith { CharacterSequence('a', 'z', 0) } - failsWith { DoubleSequence(0.0, 5.0, 0.0) } - failsWith { FloatSequence(0.0.toFloat(), 5.0.toFloat(), 0.0.toFloat()) } + failsWith(javaClass()) { IntSequence(0, 5, 0) } + failsWith(javaClass()) { ByteSequence(0, 5, 0) } + failsWith(javaClass()) { ShortSequence(0, 5, 0) } + failsWith(javaClass()) { LongSequence(0, 5, 0) } + failsWith(javaClass()) { CharacterSequence('a', 'z', 0) } + failsWith(javaClass()) { DoubleSequence(0.0, 5.0, 0.0) } + failsWith(javaClass()) { FloatSequence(0.0.toFloat(), 5.0.toFloat(), 0.0.toFloat()) } - failsWith { 0..5 step 0 } - failsWith { 0.toByte()..5.toByte() step 0 } - failsWith { 0.toShort()..5.toShort() step 0 } - failsWith { 0.toLong()..5.toLong() step 0.toLong() } - failsWith { 'a'..'z' step 0 } - failsWith { 0.0..5.0 step 0.0 } - failsWith { 0.0.toFloat()..5.0.toFloat() step 0.0.toFloat() } + failsWith(javaClass()) { 0..5 step 0 } + failsWith(javaClass()) { 0.toByte()..5.toByte() step 0 } + failsWith(javaClass()) { 0.toShort()..5.toShort() step 0 } + failsWith(javaClass()) { 0.toLong()..5.toLong() step 0.toLong() } + failsWith(javaClass()) { 'a'..'z' step 0 } + failsWith(javaClass()) { 0.0..5.0 step 0.0 } + failsWith(javaClass()) { 0.0.toFloat()..5.0.toFloat() step 0.0.toFloat() } - failsWith { 0 downTo -5 step 0 } - failsWith { 0.toByte() downTo -5.toByte() step 0 } - failsWith { 0.toShort() downTo -5.toShort() step 0 } - failsWith { 0.toLong() downTo -5.toLong() step 0.toLong() } - failsWith { 'z' downTo 'a' step 0 } - failsWith { 0.0 downTo -5.0 step 0.0 } - failsWith { 0.0.toFloat() downTo -5.0.toFloat() step 0.0.toFloat() } + failsWith(javaClass()) { 0 downTo -5 step 0 } + failsWith(javaClass()) { 0.toByte() downTo -5.toByte() step 0 } + failsWith(javaClass()) { 0.toShort() downTo -5.toShort() step 0 } + failsWith(javaClass()) { 0.toLong() downTo -5.toLong() step 0.toLong() } + failsWith(javaClass()) { 'z' downTo 'a' step 0 } + failsWith(javaClass()) { 0.0 downTo -5.0 step 0.0 } + failsWith(javaClass()) { 0.0.toFloat() downTo -5.0.toFloat() step 0.0.toFloat() } - failsWith { 0..5 step -2 } - failsWith { 0.toByte()..5.toByte() step -2 } - failsWith { 0.toShort()..5.toShort() step -2 } - failsWith { 0.toLong()..5.toLong() step -2.toLong() } - failsWith { 'a'..'z' step -2 } - failsWith { 0.0..5.0 step -0.5 } - failsWith { 0.0.toFloat()..5.0.toFloat() step -0.5.toFloat() } + failsWith(javaClass()) { 0..5 step -2 } + failsWith(javaClass()) { 0.toByte()..5.toByte() step -2 } + failsWith(javaClass()) { 0.toShort()..5.toShort() step -2 } + failsWith(javaClass()) { 0.toLong()..5.toLong() step -2.toLong() } + failsWith(javaClass()) { 'a'..'z' step -2 } + failsWith(javaClass()) { 0.0..5.0 step -0.5 } + failsWith(javaClass()) { 0.0.toFloat()..5.0.toFloat() step -0.5.toFloat() } - failsWith { 0 downTo -5 step -2 } - failsWith { 0.toByte() downTo -5.toByte() step -2 } - failsWith { 0.toShort() downTo -5.toShort() step -2 } - failsWith { 0.toLong() downTo -5.toLong() step -2.toLong() } - failsWith { 'z' downTo 'a' step -2 } - failsWith { 0.0 downTo -5.0 step -0.5 } - failsWith { 0.0.toFloat() downTo -5.0.toFloat() step -0.5.toFloat() } + failsWith(javaClass()) { 0 downTo -5 step -2 } + failsWith(javaClass()) { 0.toByte() downTo -5.toByte() step -2 } + failsWith(javaClass()) { 0.toShort() downTo -5.toShort() step -2 } + failsWith(javaClass()) { 0.toLong() downTo -5.toLong() step -2.toLong() } + failsWith(javaClass()) { 'z' downTo 'a' step -2 } + failsWith(javaClass()) { 0.0 downTo -5.0 step -0.5 } + failsWith(javaClass()) { 0.0.toFloat() downTo -5.0.toFloat() step -0.5.toFloat() } } } \ No newline at end of file