From 7632910ffd9ffb2f21cc32bb3412030352c8d97f Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 19 Jun 2020 00:11:59 +0300 Subject: [PATCH] Drop deprecated CollectionAssertions.kt Remove incorrect import from callByWithEmptyVarArg test --- .../createAnnotation/callByWithEmptyVarArg.kt | 1 - .../src/main/kotlin/CollectionAssertions.kt | 95 ------------ .../test/kotlin/CollectionAssertionTest.kt | 143 ------------------ 3 files changed, 239 deletions(-) delete mode 100644 libraries/kotlin.test/jvm/src/main/kotlin/CollectionAssertions.kt delete mode 100644 libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt diff --git a/compiler/testData/codegen/box/reflection/createAnnotation/callByWithEmptyVarArg.kt b/compiler/testData/codegen/box/reflection/createAnnotation/callByWithEmptyVarArg.kt index 41a1d856b24..585fdef4d46 100644 --- a/compiler/testData/codegen/box/reflection/createAnnotation/callByWithEmptyVarArg.kt +++ b/compiler/testData/codegen/box/reflection/createAnnotation/callByWithEmptyVarArg.kt @@ -6,7 +6,6 @@ import kotlin.reflect.* import kotlin.reflect.full.* -import kotlin.test.assert annotation class Foo(vararg val strings: String) diff --git a/libraries/kotlin.test/jvm/src/main/kotlin/CollectionAssertions.kt b/libraries/kotlin.test/jvm/src/main/kotlin/CollectionAssertions.kt deleted file mode 100644 index afbdca48d08..00000000000 --- a/libraries/kotlin.test/jvm/src/main/kotlin/CollectionAssertions.kt +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -@file:Suppress("DEPRECATION_ERROR") -package kotlin.test - -import java.util.* - -// TODO: Drop entirely in 1.4 - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -class CollectionAssertionSession>(val collection: C) - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -inline fun > assert(collection: C, block: CollectionAssertionSession.() -> Unit) { - CollectionAssertionSession(collection).block() -} - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -fun > CollectionAssertionSession<*, C>.sizeShouldBe(expectedSize: Int, message: String? = null) { - assertEquals(expectedSize, collection.size, message ?: "collection should have size $expectedSize but it is ${collection.size}") -} - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -fun CollectionAssertionSession.elementAtShouldBe(position: Int, expected: T, message: String? = null) { - assertEquals(expected, collection.elementAt(position), message ?: "element at $position should be $expected") -} - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -fun > CollectionAssertionSession.elementAtShouldComply(position: Int, message: String? = null, predicate: (T) -> Boolean) { - assertTrue(message) { predicate(collection.elementAt(position)) } -} - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -fun CollectionAssertionSession.lastElementShouldBe(expected: T, message: String? = null) { - assertEquals(expected, collection.last(), message ?: "the last element should be $expected") -} - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -fun CollectionAssertionSession.containsAll(vararg elements: T) { - for (e in elements) { - assertTrue(message = "Element $e is missing in the collection") { e in collection } - } -} - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -fun > CollectionAssertionSession.shouldBe(expectedElements: Iterable, message: String? = null) { - val actual = collection.iterator() - val expected = expectedElements.iterator() - - while (actual.hasNext() && expected.hasNext()) { - assertEquals(expected.next(), actual.next(), message) - } - - if (actual.hasNext()) { - fail("Actual collection is longer than expected. Extra elements are: ${actual.remaining()}") - } - if (expected.hasNext()) { - fail("Actual collection is shorter than expected. Missing elements are: ${expected.remaining()}") - } -} - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -fun > CollectionAssertionSession.shouldBeSet(other: Set, message: String? = null) { - for (e in other) { - if (e !in collection) { - fail(message ?: "Element $e in not in the collection $collection") - } - } - for (e in collection) { - if (e !in other) { - fail(message ?: "Element $e is not expected") - } - } -} - -@Deprecated("This is an experimental part of the API. It may be changed or removed in newer releases.", level = DeprecationLevel.ERROR) -fun > CollectionAssertionSession.shouldBeSet(vararg other: T) { - val otherSet = HashSet() - for (e in other) { - otherSet.add(e) - } - - shouldBeSet(otherSet) -} - -private fun Iterator.remaining(): List { - val result = ArrayList() - while (hasNext()) { - result.add(next()) - } - return result -} \ No newline at end of file diff --git a/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt b/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt deleted file mode 100644 index 8f5f1360deb..00000000000 --- a/libraries/kotlin.test/jvm/src/test/kotlin/CollectionAssertionTest.kt +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -@file:Suppress("DEPRECATION_ERROR") - -package kotlin.test.tests - -import org.junit.Assert -import java.util.* -import kotlin.test.* - -class CollectionAssertionTest { - @Test - fun testList() { - assert(listOf(1, 2, 3)) { - sizeShouldBe(3) - elementAtShouldBe(0, 1) - elementAtShouldComply(0) { it > 0 } - lastElementShouldBe(3) - containsAll(1, 2) - - shouldBe(listOf(1, 2, 3)) - } - } - - @Test - fun testSet() { - assert(setOf(1, 2, 3)) { - sizeShouldBe(3) - elementAtShouldBe(0, 1) - elementAtShouldComply(0) { it > 0 } - lastElementShouldBe(3) - containsAll(1, 2) - - shouldBeSet(setOf(1, 2, 3)) - } - } - - @Test(expected = AssertionError::class) - fun testSizeShouldBeFails() { - assert(listOf(1, 2, 3)) { - sizeShouldBe(1) - } - } - - @Test(expected = AssertionError::class) - fun testElementAtShouldBeFail() { - assert(listOf(1, 2, 3)) { - elementAtShouldBe(0, 0) - } - } - - @Test(expected = AssertionError::class) - fun testElementAtShouldComplyFail() { - assert(listOf(1, 2, 3)) { - elementAtShouldComply(0) { it < 0 } - } - } - - @Test(expected = AssertionError::class) - fun testLastElementFail() { - assert(listOf(1, 2, 3)) { - lastElementShouldBe(0) - } - } - - @Test(expected = NoSuchElementException::class) - fun testLastElementOnEmptyFail() { - assert(listOf()) { - lastElementShouldBe(0) - } - } - - @Test(expected = AssertionError::class) - fun testContainsAll() { - assert(listOf(1, 2, 3)) { - containsAll(1, 8) - } - } - - @Test(expected = AssertionError::class) - fun testContainsAllWithSet() { - assert(setOf(1, 2, 3)) { - containsAll(1, 8) - } - } - - @Test - fun testShouldBeLess() { - try { - assert(listOf(1, 2, 3)) { - shouldBe(listOf(1, 2, 3, 4)) - } - Assert.fail("It shouldn't pass here") - } catch (e: AssertionError) { - assertTrue { "[4]" in e.message!! } - assertTrue { "shorter" in e.message!! } - } - } - - @Test - fun testShouldBeLonger() { - try { - assert(listOf(1, 2, 3)) { - shouldBe(listOf(1, 2)) - } - Assert.fail("It shouldn't pass here") - } catch (e: AssertionError) { - assertTrue { "[3]" in e.message!! } - assertTrue { "longer" in e.message!! } - } - } - - @Test(expected = AssertionError::class) - fun testShouldBeSetExtra() { - assert(setOf(1, 2, 3)) { - shouldBeSet(setOf(1, 2)) - } - } - - @Test - fun testShouldBeSetExact() { - assert(setOf(1, 2, 3)) { - shouldBeSet(setOf(1, 2, 3)) - } - } - - @Test - fun testShouldBeSetExactVararg() { - assert(setOf(1, 2, 3)) { - shouldBeSet(1, 2, 3) - } - } - - @Test(expected = AssertionError::class) - fun testShouldBeSetMissing() { - assert(setOf(1, 2, 3)) { - shouldBeSet(setOf(1, 2, 3, 4)) - } - } -}