diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-08-30 15:58:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-30 15:58:46 +0200 |
commit | c63ea36637ce956029fb15b1482c0683ecb8a587 (patch) | |
tree | 2b75a8a976b43530820e73dc60cce4b10d9fc005 /core/content-matcher-test-utils | |
parent | 0e00edc6fcd406fcf38673ef6a2f8f59e8374de2 (diff) | |
download | dokka-c63ea36637ce956029fb15b1482c0683ecb8a587.tar.gz dokka-c63ea36637ce956029fb15b1482c0683ecb8a587.tar.bz2 dokka-c63ea36637ce956029fb15b1482c0683ecb8a587.zip |
Migrate to JUnit 5 and unify used test API (#3138)
Diffstat (limited to 'core/content-matcher-test-utils')
-rw-r--r-- | core/content-matcher-test-utils/build.gradle.kts | 2 | ||||
-rw-r--r-- | core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt | 28 |
2 files changed, 19 insertions, 11 deletions
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<ContentComposite>.() -> Unit) { @@ -48,7 +47,7 @@ private val ContentComposite.extractedText fun <T : ContentComposite> ContentMatcherBuilder<T>.hasExactText(expected: String) { assertions += { - assertThat(this::extractedText).isEqualTo(expected) + assertEquals(expected, this.extractedText) } } @@ -74,7 +73,7 @@ fun ContentMatcherBuilder<*>.tabbedGroup( block: ContentMatcherBuilder<ContentGroup>.() -> Unit ) = composite<ContentGroup> { 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<ContentGroup> { 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<ContentHeader>.() -> Unit) = composite<ContentHeader> { block() - check { if (expectedLevel != null) assertThat(this::level).isEqualTo(expectedLevel) } + check { if (expectedLevel != null) assertEquals(expectedLevel, this.level) } } fun ContentMatcherBuilder<*>.p(block: ContentMatcherBuilder<ContentGroup>.() -> Unit) = composite<ContentGroup> { block() - check { assertThat(this::style).contains(TextStyle.Paragraph) } + check { assertContains(this.style, TextStyle.Paragraph) } } fun ContentMatcherBuilder<*>.link(block: ContentMatcherBuilder<ContentLink>.() -> Unit) = composite(block) @@ -114,7 +112,7 @@ fun ContentMatcherBuilder<*>.codeInline(block: ContentMatcherBuilder<ContentCode fun ContentMatcherBuilder<*>.caption(block: ContentMatcherBuilder<ContentGroup>.() -> Unit) = composite<ContentGroup> { block() - check { assertThat(this::style).contains(ContentStyle.Caption) } + check { assertContains(this.style, ContentStyle.Caption) } } fun ContentMatcherBuilder<*>.br() = node<ContentBreakLine>() @@ -139,3 +137,13 @@ fun ContentMatcherBuilder<ContentDivergentInstance>.divergent(block: ContentMatc fun ContentMatcherBuilder<ContentDivergentInstance>.after(block: ContentMatcherBuilder<ContentComposite>.() -> Unit) = composite(block) + +/* + * TODO replace with kotlin.test.assertContains after migrating to Kotlin language version 1.5+ + */ +private fun <T> assertContains(iterable: Iterable<T>, element: T) { + asserter.assertTrue( + { "Expected the collection to contain the element.\nCollection <$iterable>, element <$element>." }, + iterable.contains(element) + ) +} |