Adapted usage of failsWith().
This commit is contained in:
@@ -38,7 +38,7 @@ class ArraysJVMTest {
|
|||||||
expect(0.toByte()) { byteArray(3, 2, 1) reduce { a, b -> (a - b).toByte() } }
|
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() } }
|
expect(0.toShort()) { shortArray(3, 2, 1) reduce { a, b -> (a - b).toShort() } }
|
||||||
|
|
||||||
failsWith<UnsupportedOperationException> {
|
failsWith (javaClass<UnsupportedOperationException>()) {
|
||||||
intArray().reduce { a, b -> a + b}
|
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.toByte()) { byteArray(1, 2, 3) reduceRight { a, b -> (a - b).toByte() } }
|
||||||
expect(2.toShort()) { shortArray(1, 2, 3) reduceRight { a, b -> (a - b).toShort() } }
|
expect(2.toShort()) { shortArray(1, 2, 3) reduceRight { a, b -> (a - b).toShort() } }
|
||||||
|
|
||||||
failsWith<UnsupportedOperationException> {
|
failsWith (javaClass<UnsupportedOperationException>()) {
|
||||||
intArray().reduceRight { a, b -> a + b}
|
intArray().reduceRight { a, b -> a + b}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.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() } }
|
// Fails in JS: expect(0.toShort()) { shortArray(3, 2, 1) reduce { a, b -> (a - b).toShort() } }
|
||||||
|
|
||||||
failsWith<UnsupportedOperationException> {
|
failsWith(javaClass<UnsupportedOperationException>()) {
|
||||||
intArray().reduce { a, b -> a + b}
|
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.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() } }
|
// Fails in JS: expect(2.toShort()) { shortArray(1, 2, 3) reduceRight { a, b -> (a - b).toShort() } }
|
||||||
|
|
||||||
failsWith<UnsupportedOperationException> {
|
failsWith(javaClass<UnsupportedOperationException>()) {
|
||||||
intArray().reduceRight { a, b -> a + b}
|
intArray().reduceRight { a, b -> a + b}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ class CollectionTest {
|
|||||||
list.reduce { a, b -> a + b }
|
list.reduce { a, b -> a + b }
|
||||||
}
|
}
|
||||||
|
|
||||||
failsWith<UnsupportedOperationException> {
|
failsWith(javaClass<UnsupportedOperationException>()) {
|
||||||
arrayList<Int>().reduce { a, b -> a + b}
|
arrayList<Int>().reduce { a, b -> a + b}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,7 +200,7 @@ class CollectionTest {
|
|||||||
list.reduceRight { a, b -> a + b }
|
list.reduceRight { a, b -> a + b }
|
||||||
}
|
}
|
||||||
|
|
||||||
failsWith<UnsupportedOperationException> {
|
failsWith(javaClass<UnsupportedOperationException>()) {
|
||||||
arrayList<Int>().reduceRight { a, b -> a + b}
|
arrayList<Int>().reduceRight { a, b -> a + b}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ class CollectionTest {
|
|||||||
assertEquals(arrayList("foo", "bar"), notNull)
|
assertEquals(arrayList("foo", "bar"), notNull)
|
||||||
|
|
||||||
val hasNulls = arrayList("foo", null, "bar")
|
val hasNulls = arrayList("foo", null, "bar")
|
||||||
failsWith<IllegalArgumentException> {
|
failsWith(javaClass<IllegalArgumentException>()) {
|
||||||
// should throw an exception as we have a null
|
// should throw an exception as we have a null
|
||||||
hasNulls.requireNoNulls()
|
hasNulls.requireNoNulls()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class PreconditionsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test fun failingRequire() {
|
test fun failingRequire() {
|
||||||
val error = failsWith<IllegalArgumentException> {
|
val error = failsWith(javaClass<IllegalArgumentException>()) {
|
||||||
require(false)
|
require(false)
|
||||||
}
|
}
|
||||||
assertNotNull(error.getMessage())
|
assertNotNull(error.getMessage())
|
||||||
@@ -25,14 +25,14 @@ class PreconditionsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test fun failingRequireWithMessage() {
|
test fun failingRequireWithMessage() {
|
||||||
val error = failsWith<IllegalArgumentException> {
|
val error = failsWith(javaClass<IllegalArgumentException>()) {
|
||||||
require(false, "Hello")
|
require(false, "Hello")
|
||||||
}
|
}
|
||||||
assertEquals("Hello", error.getMessage())
|
assertEquals("Hello", error.getMessage())
|
||||||
}
|
}
|
||||||
|
|
||||||
test fun failingRequireWithLazyMessage() {
|
test fun failingRequireWithLazyMessage() {
|
||||||
val error = failsWith<IllegalArgumentException> {
|
val error = failsWith(javaClass<IllegalArgumentException>()) {
|
||||||
require(false) {"Hello"}
|
require(false) {"Hello"}
|
||||||
}
|
}
|
||||||
assertEquals("Hello", error.getMessage())
|
assertEquals("Hello", error.getMessage())
|
||||||
@@ -47,7 +47,7 @@ class PreconditionsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test fun failingCheck() {
|
test fun failingCheck() {
|
||||||
val error = failsWith<IllegalStateException> {
|
val error = failsWith(javaClass<IllegalStateException>()) {
|
||||||
check(false)
|
check(false)
|
||||||
}
|
}
|
||||||
assertNotNull(error.getMessage())
|
assertNotNull(error.getMessage())
|
||||||
@@ -58,14 +58,14 @@ class PreconditionsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test fun failingCheckWithMessage() {
|
test fun failingCheckWithMessage() {
|
||||||
val error = failsWith<IllegalStateException> {
|
val error = failsWith(javaClass<IllegalStateException>()) {
|
||||||
check(false, "Hello")
|
check(false, "Hello")
|
||||||
}
|
}
|
||||||
assertEquals("Hello", error.getMessage())
|
assertEquals("Hello", error.getMessage())
|
||||||
}
|
}
|
||||||
|
|
||||||
test fun failingCheckWithLazyMessage() {
|
test fun failingCheckWithLazyMessage() {
|
||||||
val error = failsWith<IllegalStateException> {
|
val error = failsWith(javaClass<IllegalStateException>()) {
|
||||||
check(false) {"Hello"}
|
check(false) {"Hello"}
|
||||||
}
|
}
|
||||||
assertEquals("Hello", error.getMessage())
|
assertEquals("Hello", error.getMessage())
|
||||||
@@ -78,7 +78,7 @@ class PreconditionsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test fun requireNotNullFails() {
|
test fun requireNotNullFails() {
|
||||||
failsWith<IllegalArgumentException> {
|
failsWith(javaClass<IllegalArgumentException>()) {
|
||||||
val s2: String? = null
|
val s2: String? = null
|
||||||
requireNotNull(s2)
|
requireNotNull(s2)
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ class PreconditionsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test fun checkNotNullFails() {
|
test fun checkNotNullFails() {
|
||||||
failsWith<IllegalStateException> {
|
failsWith(javaClass<IllegalStateException>()) {
|
||||||
val s2: String? = null
|
val s2: String? = null
|
||||||
checkNotNull(s2)
|
checkNotNull(s2)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class StringJVMTest {
|
|||||||
// get the smallest character(by char value)
|
// get the smallest character(by char value)
|
||||||
assertEquals('a', "bacfd".reduce { v, c -> if (v > c) c else v })
|
assertEquals('a', "bacfd".reduce { v, c -> if (v > c) c else v })
|
||||||
|
|
||||||
failsWith<UnsupportedOperationException> {
|
failsWith(javaClass<UnsupportedOperationException>()) {
|
||||||
"".reduce { a, b -> '\n' }
|
"".reduce { a, b -> '\n' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ class StringJVMTest {
|
|||||||
// get the smallest character(by char value)
|
// get the smallest character(by char value)
|
||||||
assertEquals('a', "bacfd".reduceRight { c, v -> if (v > c) c else v })
|
assertEquals('a', "bacfd".reduceRight { c, v -> if (v > c) c else v })
|
||||||
|
|
||||||
failsWith<UnsupportedOperationException> {
|
failsWith(javaClass<UnsupportedOperationException>()) {
|
||||||
"".reduceRight { a, b -> '\n' }
|
"".reduceRight { a, b -> '\n' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package iterators
|
|||||||
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import org.junit.Test as test
|
import org.junit.Test as test
|
||||||
import kotlin.test.failsWith
|
import kotlin.test.fails
|
||||||
|
|
||||||
fun fibonacci(): Iterator<Int> {
|
fun fibonacci(): Iterator<Int> {
|
||||||
// fibonacci terms
|
// fibonacci terms
|
||||||
@@ -66,7 +66,7 @@ class IteratorsTest {
|
|||||||
|
|
||||||
val iterWithNulls = arrayList("foo", null, "bar").iterator()
|
val iterWithNulls = arrayList("foo", null, "bar").iterator()
|
||||||
val notNull2 = iterWithNulls.requireNoNulls()
|
val notNull2 = iterWithNulls.requireNoNulls()
|
||||||
failsWith<IllegalArgumentException> {
|
fails {
|
||||||
// should throw an exception as we have a null
|
// should throw an exception as we have a null
|
||||||
notNull2.toList()
|
notNull2.toList()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,44 +145,44 @@ public class RangeTest {
|
|||||||
|
|
||||||
test fun illegalSequenceCreation() {
|
test fun illegalSequenceCreation() {
|
||||||
// create sequence explicitly with increment = 0
|
// create sequence explicitly with increment = 0
|
||||||
failsWith<IllegalArgumentException> { IntSequence(0, 5, 0) }
|
failsWith(javaClass<IllegalArgumentException>()) { IntSequence(0, 5, 0) }
|
||||||
failsWith<IllegalArgumentException> { ByteSequence(0, 5, 0) }
|
failsWith(javaClass<IllegalArgumentException>()) { ByteSequence(0, 5, 0) }
|
||||||
failsWith<IllegalArgumentException> { ShortSequence(0, 5, 0) }
|
failsWith(javaClass<IllegalArgumentException>()) { ShortSequence(0, 5, 0) }
|
||||||
failsWith<IllegalArgumentException> { LongSequence(0, 5, 0) }
|
failsWith(javaClass<IllegalArgumentException>()) { LongSequence(0, 5, 0) }
|
||||||
failsWith<IllegalArgumentException> { CharacterSequence('a', 'z', 0) }
|
failsWith(javaClass<IllegalArgumentException>()) { CharacterSequence('a', 'z', 0) }
|
||||||
failsWith<IllegalArgumentException> { DoubleSequence(0.0, 5.0, 0.0) }
|
failsWith(javaClass<IllegalArgumentException>()) { DoubleSequence(0.0, 5.0, 0.0) }
|
||||||
failsWith<IllegalArgumentException> { FloatSequence(0.0.toFloat(), 5.0.toFloat(), 0.0.toFloat()) }
|
failsWith(javaClass<IllegalArgumentException>()) { FloatSequence(0.0.toFloat(), 5.0.toFloat(), 0.0.toFloat()) }
|
||||||
|
|
||||||
failsWith<IllegalArgumentException> { 0..5 step 0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0..5 step 0 }
|
||||||
failsWith<IllegalArgumentException> { 0.toByte()..5.toByte() step 0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toByte()..5.toByte() step 0 }
|
||||||
failsWith<IllegalArgumentException> { 0.toShort()..5.toShort() step 0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toShort()..5.toShort() step 0 }
|
||||||
failsWith<IllegalArgumentException> { 0.toLong()..5.toLong() step 0.toLong() }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toLong()..5.toLong() step 0.toLong() }
|
||||||
failsWith<IllegalArgumentException> { 'a'..'z' step 0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 'a'..'z' step 0 }
|
||||||
failsWith<IllegalArgumentException> { 0.0..5.0 step 0.0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.0..5.0 step 0.0 }
|
||||||
failsWith<IllegalArgumentException> { 0.0.toFloat()..5.0.toFloat() step 0.0.toFloat() }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.0.toFloat()..5.0.toFloat() step 0.0.toFloat() }
|
||||||
|
|
||||||
failsWith<IllegalArgumentException> { 0 downTo -5 step 0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0 downTo -5 step 0 }
|
||||||
failsWith<IllegalArgumentException> { 0.toByte() downTo -5.toByte() step 0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toByte() downTo -5.toByte() step 0 }
|
||||||
failsWith<IllegalArgumentException> { 0.toShort() downTo -5.toShort() step 0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toShort() downTo -5.toShort() step 0 }
|
||||||
failsWith<IllegalArgumentException> { 0.toLong() downTo -5.toLong() step 0.toLong() }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toLong() downTo -5.toLong() step 0.toLong() }
|
||||||
failsWith<IllegalArgumentException> { 'z' downTo 'a' step 0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 'z' downTo 'a' step 0 }
|
||||||
failsWith<IllegalArgumentException> { 0.0 downTo -5.0 step 0.0 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.0 downTo -5.0 step 0.0 }
|
||||||
failsWith<IllegalArgumentException> { 0.0.toFloat() downTo -5.0.toFloat() step 0.0.toFloat() }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.0.toFloat() downTo -5.0.toFloat() step 0.0.toFloat() }
|
||||||
|
|
||||||
failsWith<IllegalArgumentException> { 0..5 step -2 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0..5 step -2 }
|
||||||
failsWith<IllegalArgumentException> { 0.toByte()..5.toByte() step -2 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toByte()..5.toByte() step -2 }
|
||||||
failsWith<IllegalArgumentException> { 0.toShort()..5.toShort() step -2 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toShort()..5.toShort() step -2 }
|
||||||
failsWith<IllegalArgumentException> { 0.toLong()..5.toLong() step -2.toLong() }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toLong()..5.toLong() step -2.toLong() }
|
||||||
failsWith<IllegalArgumentException> { 'a'..'z' step -2 }
|
failsWith(javaClass<IllegalArgumentException>()) { 'a'..'z' step -2 }
|
||||||
failsWith<IllegalArgumentException> { 0.0..5.0 step -0.5 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.0..5.0 step -0.5 }
|
||||||
failsWith<IllegalArgumentException> { 0.0.toFloat()..5.0.toFloat() step -0.5.toFloat() }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.0.toFloat()..5.0.toFloat() step -0.5.toFloat() }
|
||||||
|
|
||||||
failsWith<IllegalArgumentException> { 0 downTo -5 step -2 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0 downTo -5 step -2 }
|
||||||
failsWith<IllegalArgumentException> { 0.toByte() downTo -5.toByte() step -2 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toByte() downTo -5.toByte() step -2 }
|
||||||
failsWith<IllegalArgumentException> { 0.toShort() downTo -5.toShort() step -2 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toShort() downTo -5.toShort() step -2 }
|
||||||
failsWith<IllegalArgumentException> { 0.toLong() downTo -5.toLong() step -2.toLong() }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.toLong() downTo -5.toLong() step -2.toLong() }
|
||||||
failsWith<IllegalArgumentException> { 'z' downTo 'a' step -2 }
|
failsWith(javaClass<IllegalArgumentException>()) { 'z' downTo 'a' step -2 }
|
||||||
failsWith<IllegalArgumentException> { 0.0 downTo -5.0 step -0.5 }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.0 downTo -5.0 step -0.5 }
|
||||||
failsWith<IllegalArgumentException> { 0.0.toFloat() downTo -5.0.toFloat() step -0.5.toFloat() }
|
failsWith(javaClass<IllegalArgumentException>()) { 0.0.toFloat() downTo -5.0.toFloat() step -0.5.toFloat() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user