From c63ea36637ce956029fb15b1482c0683ecb8a587 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Wed, 30 Aug 2023 15:58:46 +0200 Subject: Migrate to JUnit 5 and unify used test API (#3138) --- core/content-matcher-test-utils/build.gradle.kts | 2 +- .../kotlin/matchers/content/ContentMatchersDsl.kt | 28 ++++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'core/content-matcher-test-utils') diff --git a/core/content-matcher-test-utils/build.gradle.kts b/core/content-matcher-test-utils/build.gradle.kts index 75602c64..f469c03d 100644 --- a/core/content-matcher-test-utils/build.gradle.kts +++ b/core/content-matcher-test-utils/build.gradle.kts @@ -6,5 +6,5 @@ dependencies { implementation(projects.core.testApi) implementation(kotlin("reflect")) - implementation(libs.assertk) + implementation(kotlin("test")) } diff --git a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt index 6e05c11a..962841ba 100644 --- a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt +++ b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt @@ -1,12 +1,11 @@ package matchers.content -import assertk.assertThat -import assertk.assertions.contains -import assertk.assertions.isEqualTo import org.jetbrains.dokka.model.withDescendants import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.test.tools.matchers.content.* import kotlin.reflect.KClass +import kotlin.test.assertEquals +import kotlin.test.asserter // entry point: fun ContentNode.assertNode(block: ContentMatcherBuilder.() -> Unit) { @@ -48,7 +47,7 @@ private val ContentComposite.extractedText fun ContentMatcherBuilder.hasExactText(expected: String) { assertions += { - assertThat(this::extractedText).isEqualTo(expected) + assertEquals(expected, this.extractedText) } } @@ -74,7 +73,7 @@ fun ContentMatcherBuilder<*>.tabbedGroup( block: ContentMatcherBuilder.() -> Unit ) = composite { block() - check { assertThat(this::style).transform { style -> style.contains(ContentStyle.TabbedContent) }.isEqualTo(true) } + check { assertContains(this.style, ContentStyle.TabbedContent) } } fun ContentMatcherBuilder<*>.tab( @@ -82,21 +81,20 @@ fun ContentMatcherBuilder<*>.tab( ) = composite { block() check { - assertThat(this::extra).transform { extra -> extra[TabbedContentTypeExtra]?.value } - .isEqualTo(tabbedContentType) + assertEquals(tabbedContentType, this.extra[TabbedContentTypeExtra]?.value) } } fun ContentMatcherBuilder<*>.header(expectedLevel: Int? = null, block: ContentMatcherBuilder.() -> Unit) = composite { block() - check { if (expectedLevel != null) assertThat(this::level).isEqualTo(expectedLevel) } + check { if (expectedLevel != null) assertEquals(expectedLevel, this.level) } } fun ContentMatcherBuilder<*>.p(block: ContentMatcherBuilder.() -> Unit) = composite { block() - check { assertThat(this::style).contains(TextStyle.Paragraph) } + check { assertContains(this.style, TextStyle.Paragraph) } } fun ContentMatcherBuilder<*>.link(block: ContentMatcherBuilder.() -> Unit) = composite(block) @@ -114,7 +112,7 @@ fun ContentMatcherBuilder<*>.codeInline(block: ContentMatcherBuilder.caption(block: ContentMatcherBuilder.() -> Unit) = composite { block() - check { assertThat(this::style).contains(ContentStyle.Caption) } + check { assertContains(this.style, ContentStyle.Caption) } } fun ContentMatcherBuilder<*>.br() = node() @@ -139,3 +137,13 @@ fun ContentMatcherBuilder.divergent(block: ContentMatc fun ContentMatcherBuilder.after(block: ContentMatcherBuilder.() -> Unit) = composite(block) + +/* + * TODO replace with kotlin.test.assertContains after migrating to Kotlin language version 1.5+ + */ +private fun assertContains(iterable: Iterable, element: T) { + asserter.assertTrue( + { "Expected the collection to contain the element.\nCollection <$iterable>, element <$element>." }, + iterable.contains(element) + ) +} -- cgit