Tests: use helper function to assert compile-time and run-time type check

To cleanup warnings about useless cast or type check that is always true.
This commit is contained in:
Ilya Gorbunov
2017-12-25 21:07:20 +03:00
parent ecd42f14b3
commit 053f3b6ac0
7 changed files with 79 additions and 55 deletions
@@ -1,10 +1,7 @@
@file:kotlin.jvm.JvmVersion
package test.collections
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import test.assertStaticAndRuntimeTypeIs
import kotlin.test.*
import kotlin.comparisons.*
import java.util.*
@@ -57,9 +54,7 @@ class CollectionJVMTest {
assertEquals(1, foo.size)
assertEquals(listOf("foo"), foo)
assertTrue {
foo is LinkedList<String>
}
assertStaticAndRuntimeTypeIs<LinkedList<String>>(foo)
}
@Test fun filterNotIntoLinkedListOf() {
@@ -72,9 +67,7 @@ class CollectionJVMTest {
assertEquals(1, foo.size)
assertEquals(listOf("bar"), foo)
assertTrue {
foo is LinkedList<String>
}
assertStaticAndRuntimeTypeIs<LinkedList<String>>(foo)
}
@Test fun filterNotNullIntoLinkedListOf() {
@@ -84,9 +77,7 @@ class CollectionJVMTest {
assertEquals(2, foo.size)
assertEquals(LinkedList(listOf("foo", "bar")), foo)
assertTrue {
foo is LinkedList<String>
}
assertStaticAndRuntimeTypeIs<LinkedList<String>>(foo)
}
@Test fun filterIntoSortedSet() {
@@ -94,9 +85,8 @@ class CollectionJVMTest {
val sorted = data.filterTo(sortedSetOf<String>()) { it.length == 3 }
assertEquals(2, sorted.size)
assertEquals(sortedSetOf("bar", "foo"), sorted)
assertTrue {
sorted is TreeSet<String>
}
assertStaticAndRuntimeTypeIs<TreeSet<String>>(sorted)
}
@Test fun first() {
@@ -16,6 +16,7 @@
package test.collections
import test.assertStaticAndRuntimeTypeIs
import kotlin.test.*
import test.collections.behaviors.*
import test.comparisons.STRING_CASE_INSENSITIVE_ORDER
@@ -53,9 +54,7 @@ class CollectionTest {
assertEquals(2, foo.size)
assertEquals(listOf("foo", "bar"), foo)
assertTrue {
foo is List<String>
}
assertStaticAndRuntimeTypeIs<List<String>>(foo)
}
/*
@@ -93,9 +92,7 @@ class CollectionTest {
assertEquals(1, foo.size)
assertEquals(hashSetOf("foo"), foo)
assertTrue {
foo is HashSet<String>
}
assertStaticAndRuntimeTypeIs<HashSet<String>>(foo)
}
@Test fun filterIsInstanceList() {
@@ -244,7 +244,7 @@ abstract class IterableTests<T : Iterable<String>>(val createFrom: (Array<out St
@Test
fun filter() {
val foo = data.filter { it.startsWith("f") }
expect(true) { foo is List<String> }
assertStaticAndRuntimeTypeIs<List<String>>(foo)
expect(true) { foo.all { it.startsWith("f") } }
expect(1) { foo.size }
assertEquals(listOf("foo"), foo)
@@ -258,7 +258,7 @@ abstract class IterableTests<T : Iterable<String>>(val createFrom: (Array<out St
@Test
fun drop() {
val foo = data.drop(1)
expect(true) { foo is List<String> }
assertStaticAndRuntimeTypeIs<List<String>>(foo)
expect(true) { foo.all { it.startsWith("b") } }
expect(1) { foo.size }
assertEquals(listOf("bar"), foo)
@@ -267,7 +267,7 @@ abstract class IterableTests<T : Iterable<String>>(val createFrom: (Array<out St
@Test
fun dropWhile() {
val foo = data.dropWhile { it[0] == 'f' }
expect(true) { foo is List<String> }
assertStaticAndRuntimeTypeIs<List<String>>(foo)
expect(true) { foo.all { it.startsWith("b") } }
expect(1) { foo.size }
assertEquals(listOf("bar"), foo)
@@ -276,7 +276,7 @@ abstract class IterableTests<T : Iterable<String>>(val createFrom: (Array<out St
@Test
fun filterNot() {
val notFoo = data.filterNot { it.startsWith("f") }
expect(true) { notFoo is List<String> }
assertStaticAndRuntimeTypeIs<List<String>>(notFoo)
expect(true) { notFoo.none { it.startsWith("f") } }
expect(1) { notFoo.size }
assertEquals(listOf("bar"), notFoo)