From a3ee15ce3044f6682d9c4e842f76e92ffc01727c Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Fri, 17 May 2024 15:57:03 +0100 Subject: [PATCH 01/10] Rename Throwable extractor functions Prior functions are deprecated --- .../kotlin/assertk/assertions/throwable.kt | 37 +++++++++++++++---- .../kotlin/test/assertk/AssertFailureTest.kt | 4 +- .../test/assertk/assertions/ThrowableTest.kt | 6 +-- .../assertk/assertions/support/SupportTest.kt | 8 ++-- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/throwable.kt b/assertk/src/commonMain/kotlin/assertk/assertions/throwable.kt index a856d3f4..ff52e145 100644 --- a/assertk/src/commonMain/kotlin/assertk/assertions/throwable.kt +++ b/assertk/src/commonMain/kotlin/assertk/assertions/throwable.kt @@ -6,30 +6,51 @@ import assertk.all /** * Returns an assert on the throwable's message. */ -fun Assert.message() = having("message", Throwable::message) +fun Assert.havingMessage() = having("message", Throwable::message) + +@Deprecated( + message = "Function message has been renamed to havingMessage", + replaceWith = ReplaceWith("havingMessage()"), + level = DeprecationLevel.WARNING +) +fun Assert.message() = havingMessage() /** * Returns an assert on the throwable's cause. */ -fun Assert.cause() = having("cause", Throwable::cause) +fun Assert.havingCause() = having("cause", Throwable::cause) + +@Deprecated( + message = "Function cause has been renamed to havingCause", + replaceWith = ReplaceWith("havingCause()"), + level = DeprecationLevel.WARNING +) +fun Assert.cause() = havingCause() /** * Returns an assert on the throwable's root cause. */ -fun Assert.rootCause() = having("rootCause", Throwable::rootCause) +fun Assert.havingRootCause() = having("rootCause", Throwable::rootCause) + +@Deprecated( + message = "Function rootCause has been renamed to havingRootCause", + replaceWith = ReplaceWith("havingRootCause()"), + level = DeprecationLevel.WARNING +) +fun Assert.rootCause() = havingRootCause() /** * Asserts the throwable has the expected message. */ fun Assert.hasMessage(message: String?) { - message().isEqualTo(message) + havingMessage().isEqualTo(message) } /** * Asserts the throwable contains the expected text */ fun Assert.messageContains(text: String) { - message().isNotNull().contains(text) + havingMessage().isNotNull().contains(text) } /** @@ -37,7 +58,7 @@ fun Assert.messageContains(text: String) { * @see [hasNoCause] */ fun Assert.hasCause(cause: Throwable) { - cause().isNotNull().all { + havingCause().isNotNull().all { kClass().isEqualTo(cause::class) hasMessage(cause.message) } @@ -48,14 +69,14 @@ fun Assert.hasCause(cause: Throwable) { * @see [hasCause] */ fun Assert.hasNoCause() { - cause().isNull() + havingCause().isNull() } /** * Asserts the throwable is similar to the expected root cause, checking the type and message. */ fun Assert.hasRootCause(cause: Throwable) { - rootCause().all { + havingRootCause().all { kClass().isEqualTo(cause::class) hasMessage(cause.message) } diff --git a/assertk/src/commonTest/kotlin/test/assertk/AssertFailureTest.kt b/assertk/src/commonTest/kotlin/test/assertk/AssertFailureTest.kt index 48882746..b5bf3c88 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/AssertFailureTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/AssertFailureTest.kt @@ -3,7 +3,7 @@ package test.assertk import assertk.assertFailure import assertk.assertions.isEqualTo import assertk.assertions.isInstanceOf -import assertk.assertions.message +import assertk.assertions.havingMessage import com.willowtreeapps.opentest4k.AssertionFailedError import test.assertk.assertions.valueOrFail import kotlin.coroutines.resume @@ -28,7 +28,7 @@ class AssertFailureTest { fun failure_originating_subject_not_wrapped_in_result() { val t = assertFailsWith { assertFailure { throw RuntimeException("foo") } - .message() + .havingMessage() .isEqualTo("bar") } assertTrue("RuntimeException" in t.message!!) diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/ThrowableTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/ThrowableTest.kt index 008cc9bd..7864e348 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/ThrowableTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/ThrowableTest.kt @@ -14,17 +14,17 @@ class ThrowableTest { @Test fun extracts_message() { - assertEquals(subject.message, assertThat(subject).message().valueOrFail) + assertEquals(subject.message, assertThat(subject).havingMessage().valueOrFail) } @Test fun extracts_cause() { - assertEquals(cause, assertThat(subject).cause().valueOrFail) + assertEquals(cause, assertThat(subject).havingCause().valueOrFail) } @Test fun extracts_root_cause() { - assertEquals(rootCause, assertThat(subject).rootCause().valueOrFail) + assertEquals(rootCause, assertThat(subject).havingRootCause().valueOrFail) } //region hasMessage diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/support/SupportTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/support/SupportTest.kt index 4dff6db2..db619305 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/support/SupportTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/support/SupportTest.kt @@ -1,11 +1,9 @@ package test.assertk.assertions.support import assertk.assertThat -import assertk.assertions.hasMessage -import assertk.assertions.isEqualTo import assertk.assertions.isFailure import assertk.assertions.isSuccess -import assertk.assertions.message +import assertk.assertions.havingMessage import assertk.assertions.support.expected import assertk.assertions.support.fail import assertk.assertions.support.show @@ -236,7 +234,7 @@ class SupportTest { @Test fun expected_originating_throwable_included_as_cause() { val subject = RuntimeException() - val assert = assertThat(subject).message() + val assert = assertThat(subject).havingMessage() val error = assertFailsWith { assert.expected("message") } @@ -246,7 +244,7 @@ class SupportTest { @Test fun expected_originating_failure_result_included_as_cause() { val subject = RuntimeException() - val assert = assertThat(Result.failure(subject)).isFailure().message() + val assert = assertThat(Result.failure(subject)).isFailure().havingMessage() val error = assertFailsWith { assert.expected("message") } From b090d4e2952837943bb75d166d2bcaa40739ebbd Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Fri, 17 May 2024 16:10:50 +0100 Subject: [PATCH 02/10] Rename CharSequence extractor functions --- .../kotlin/assertk/assertions/charsequence.kt | 11 +++++++++-- .../test/assertk/assertions/CharSequenceTest.kt | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/charsequence.kt b/assertk/src/commonMain/kotlin/assertk/assertions/charsequence.kt index ab0115fd..b1fac80a 100644 --- a/assertk/src/commonMain/kotlin/assertk/assertions/charsequence.kt +++ b/assertk/src/commonMain/kotlin/assertk/assertions/charsequence.kt @@ -7,7 +7,14 @@ import assertk.assertions.support.show /** * Returns an assert on the CharSequence's length. */ -fun Assert.length() = having("length", CharSequence::length) +fun Assert.havingLength() = having("length", CharSequence::length) + +@Deprecated( + message = "Function length has been renamed to havingLength", + replaceWith = ReplaceWith("havingLength()"), + level = DeprecationLevel.WARNING +) +fun Assert.length() = havingLength() /** * Asserts the char sequence is empty. @@ -41,7 +48,7 @@ fun Assert.isNullOrEmpty() = given { actual -> * Asserts the char sequence has the expected length. */ fun Assert.hasLength(length: Int) { - length().isEqualTo(length) + havingLength().isEqualTo(length) } /** diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt index 8eb64c0b..f1a40d70 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt @@ -11,7 +11,7 @@ class CharSequenceTest { //region props @Test fun extracts_length() { - assertEquals(4, assertThat("test").length().valueOrFail) + assertEquals(4, assertThat("test").havingLength().valueOrFail) } //endregion From de3d4081a5ce0045e24a4a6fc056b67d16ffdb02 Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Fri, 17 May 2024 16:14:59 +0100 Subject: [PATCH 03/10] Rename Map and Collection extractor functions --- .../kotlin/assertk/assertions/collection.kt | 11 +++++++++-- .../src/commonMain/kotlin/assertk/assertions/map.kt | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/collection.kt b/assertk/src/commonMain/kotlin/assertk/assertions/collection.kt index 18e2cd1f..1d1fe723 100644 --- a/assertk/src/commonMain/kotlin/assertk/assertions/collection.kt +++ b/assertk/src/commonMain/kotlin/assertk/assertions/collection.kt @@ -6,7 +6,14 @@ import assertk.assertions.support.* /** * Returns an assert on the Collection's size. */ -fun Assert>.size() = having("size", Collection<*>::size) +fun Assert>.havingSize() = having("size", Collection<*>::size) + +@Deprecated( + message = "Function size has been renamed to havingSize", + replaceWith = ReplaceWith("havingSize()"), + level = DeprecationLevel.WARNING +) +fun Assert>.size() = havingSize() /** * Asserts the collection is empty. @@ -40,7 +47,7 @@ fun Assert?>.isNullOrEmpty() = given { actual -> * Asserts the collection has the expected size. */ fun Assert>.hasSize(size: Int) { - size().isEqualTo(size) + havingSize().isEqualTo(size) } /** diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/map.kt b/assertk/src/commonMain/kotlin/assertk/assertions/map.kt index e40d28be..dbc41ee5 100644 --- a/assertk/src/commonMain/kotlin/assertk/assertions/map.kt +++ b/assertk/src/commonMain/kotlin/assertk/assertions/map.kt @@ -8,7 +8,14 @@ import assertk.assertions.support.show /** * Returns an assert on the Maps's size. */ -fun Assert>.size() = having("size", Map<*, *>::size) +fun Assert>.havingSize() = having("size", Map<*, *>::size) + +@Deprecated( + message = "Function size has been renamed to havingSize", + replaceWith = ReplaceWith("havingSize()"), + level = DeprecationLevel.WARNING +) +fun Assert>.size() = havingSize() /** * Asserts the collection is empty. @@ -42,7 +49,7 @@ fun Assert?>.isNullOrEmpty() = given { actual -> * Asserts the collection has the expected size. */ fun Assert>.hasSize(size: Int) { - size().isEqualTo(size) + havingSize().isEqualTo(size) } /** From 191927ec63ad359e2660fc2e5db84d11b2942bf1 Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Fri, 17 May 2024 16:22:03 +0100 Subject: [PATCH 04/10] Rename templated Array extractor functions --- .../src/template/assertk/assertions/primitiveArray.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/assertk/src/template/assertk/assertions/primitiveArray.kt b/assertk/src/template/assertk/assertions/primitiveArray.kt index 93d991e9..511a82e5 100644 --- a/assertk/src/template/assertk/assertions/primitiveArray.kt +++ b/assertk/src/template/assertk/assertions/primitiveArray.kt @@ -25,6 +25,15 @@ $T:$N:$E:$A = /** * Returns an assert on the $T's size. */ +@JvmName("$NHavingSize") +$A +fun Assert<$T>.havingSize() = having("size") { it.size } + +@Deprecated( + message = "Function size has been renamed to havingSize", + replaceWith = ReplaceWith("havingSize()"), + level = DeprecationLevel.WARNING +) @JvmName("$NSize") $A fun Assert<$T>.size() = having("size") { it.size } @@ -96,7 +105,7 @@ fun Assert<$T?>.isNullOrEmpty() = given { actual -> @JvmName("$NHasSize") $A fun Assert<$T>.hasSize(size: Int) { - size().isEqualTo(size) + havingSize().isEqualTo(size) } /** From 368f1e7a12517ca21dedfae5a35a9769f3a6714f Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Mon, 20 May 2024 16:27:51 +0100 Subject: [PATCH 05/10] Rename common Any helper functions --- .../kotlin/assertk/assertions/any.kt | 31 ++++++++++++++++--- .../kotlin/assertk/assertions/throwable.kt | 4 +-- .../kotlin/test/assertk/assertions/AnyTest.kt | 6 ++-- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/any.kt b/assertk/src/commonMain/kotlin/assertk/assertions/any.kt index 6ad04107..cfe37ad9 100644 --- a/assertk/src/commonMain/kotlin/assertk/assertions/any.kt +++ b/assertk/src/commonMain/kotlin/assertk/assertions/any.kt @@ -13,17 +13,38 @@ import kotlin.reflect.KProperty1 /** * Returns an assert on the kotlin class of the value. */ -fun Assert.kClass() = having("class") { it::class } +fun Assert.havingKClass() = having("class") { it::class } + +@Deprecated( + message = "Function kClass has been renamed to havingKClass", + replaceWith = ReplaceWith("havingKClass()"), + level = DeprecationLevel.WARNING +) +fun Assert.kClass() = havingKClass() /** * Returns an assert on the toString method of the value. */ -fun Assert.toStringFun() = having("toString", Any?::toString) +fun Assert.havingToStringFun() = having("toString", Any?::toString) + +@Deprecated( + message = "Function toStringFun has been renamed to havingToStringFun", + replaceWith = ReplaceWith("havingToStringFun()"), + level = DeprecationLevel.WARNING +) +fun Assert.toStringFun() = havingToStringFun() /** * Returns an assert on the hasCode method of the value. */ -fun Assert.hashCodeFun() = having("hashCode", Any::hashCode) +fun Assert.havingHashCodeFun() = having("hashCode", Any::hashCode) + +@Deprecated( + message = "Function hashCodeFun has been renamed to havingHashCodeFun", + replaceWith = ReplaceWith("havingHashCodeFun()"), + level = DeprecationLevel.WARNING +) +fun Assert.hashCodeFun() = havingHashCodeFun() /** * Asserts the value is equal to the expected one, using `==`. @@ -110,14 +131,14 @@ fun Assert.isNotIn(vararg values: T) = given { actual -> * Asserts the value has the expected string from it's [toString]. */ fun Assert.hasToString(string: String) { - toStringFun().isEqualTo(string) + havingToStringFun().isEqualTo(string) } /** * Asserts the value has the expected hash code from it's [hashCode]. */ fun Assert.hasHashCode(hashCode: Int) { - hashCodeFun().isEqualTo(hashCode) + havingHashCodeFun().isEqualTo(hashCode) } /** diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/throwable.kt b/assertk/src/commonMain/kotlin/assertk/assertions/throwable.kt index ff52e145..231af46c 100644 --- a/assertk/src/commonMain/kotlin/assertk/assertions/throwable.kt +++ b/assertk/src/commonMain/kotlin/assertk/assertions/throwable.kt @@ -59,7 +59,7 @@ fun Assert.messageContains(text: String) { */ fun Assert.hasCause(cause: Throwable) { havingCause().isNotNull().all { - kClass().isEqualTo(cause::class) + havingKClass().isEqualTo(cause::class) hasMessage(cause.message) } } @@ -77,7 +77,7 @@ fun Assert.hasNoCause() { */ fun Assert.hasRootCause(cause: Throwable) { havingRootCause().all { - kClass().isEqualTo(cause::class) + havingKClass().isEqualTo(cause::class) hasMessage(cause.message) } } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt index 17c9fa52..9d6bd7e6 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt @@ -13,17 +13,17 @@ class AnyTest { @Test fun extracts_kClass() { - assertEquals(BasicObject::class, assertThat(subject as TestObject).kClass().valueOrFail) + assertEquals(BasicObject::class, assertThat(subject as TestObject).havingKClass().valueOrFail) } @Test fun extracts_toStringFun() { - assertEquals("test", assertThat(subject).toStringFun().valueOrFail) + assertEquals("test", assertThat(subject).havingToStringFun().valueOrFail) } @Test fun extracts_hashCodeFun() { - assertEquals(42, assertThat(subject).hashCodeFun().valueOrFail) + assertEquals(42, assertThat(subject).havingHashCodeFun().valueOrFail) } @Test From 8ee7884e463435f48c74880956e6350ac9d12caa Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Mon, 20 May 2024 16:29:50 +0100 Subject: [PATCH 06/10] Rename JVM Any helper functions --- assertk/src/jvmMain/kotlin/assertk/assertions/any.kt | 9 ++++++++- .../kotlin/test/assertk/assertions/JavaAnyTest.kt | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/assertk/src/jvmMain/kotlin/assertk/assertions/any.kt b/assertk/src/jvmMain/kotlin/assertk/assertions/any.kt index c9a6f741..22fc5826 100644 --- a/assertk/src/jvmMain/kotlin/assertk/assertions/any.kt +++ b/assertk/src/jvmMain/kotlin/assertk/assertions/any.kt @@ -15,7 +15,14 @@ import kotlin.reflect.full.memberProperties /** * Returns an assert on the java class of the value. */ -fun Assert.jClass() = having("class") { it::class.java } +fun Assert.havingJClass() = having("class") { it::class.java } + +@Deprecated( + message = "Function jClass has been renamed to havingJClass", + replaceWith = ReplaceWith("havingJClass()"), + level = DeprecationLevel.WARNING +) +fun Assert.jClass() = havingJClass() /** * Asserts the value has the expected java class. This is an exact match, so diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaAnyTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaAnyTest.kt index ed81e3ad..368b061b 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaAnyTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaAnyTest.kt @@ -15,7 +15,7 @@ class JavaAnyTest { //region jClass @Test fun extracts_jClass() { - assertEquals(BasicObject::class.java, assertThat(subject as TestObject).jClass().valueOrFail) + assertEquals(BasicObject::class.java, assertThat(subject as TestObject).havingJClass().valueOrFail) } //endregion From d59cbdd895b921596e7d3a8b4a23636fb3be2436 Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Mon, 20 May 2024 16:31:58 +0100 Subject: [PATCH 07/10] Rename JVM Throwable helper functions --- .../src/jvmMain/kotlin/assertk/assertions/throwable.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/assertk/src/jvmMain/kotlin/assertk/assertions/throwable.kt b/assertk/src/jvmMain/kotlin/assertk/assertions/throwable.kt index aecf439c..05b89804 100644 --- a/assertk/src/jvmMain/kotlin/assertk/assertions/throwable.kt +++ b/assertk/src/jvmMain/kotlin/assertk/assertions/throwable.kt @@ -7,4 +7,11 @@ import assertk.Assert /** * Returns an assert on the throwable's stack trace. */ -fun Assert.stackTrace() = having("stackTrace") { it.stackTrace.map(StackTraceElement::toString) } +fun Assert.havingStackTrace() = having("stackTrace") { it.stackTrace.map(StackTraceElement::toString) } + +@Deprecated( + message = "Function stackTrace has been renamed to havingStackTrace", + replaceWith = ReplaceWith("havingStackTrace()"), + level = DeprecationLevel.WARNING +) +fun Assert.stackTrace() = havingStackTrace() From 3046c24b1e8ea14710af72a7bbb8bdd81048eb5f Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Mon, 20 May 2024 16:37:46 +0100 Subject: [PATCH 08/10] Rename JVM File helper functions N.B. `text` and `bytes` are renamed in separate commits --- .../jvmMain/kotlin/assertk/assertions/file.kt | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/assertk/src/jvmMain/kotlin/assertk/assertions/file.kt b/assertk/src/jvmMain/kotlin/assertk/assertions/file.kt index ec20ae94..ff0a3246 100644 --- a/assertk/src/jvmMain/kotlin/assertk/assertions/file.kt +++ b/assertk/src/jvmMain/kotlin/assertk/assertions/file.kt @@ -11,22 +11,50 @@ import kotlin.io.readBytes /** * Returns an assert on the file's name. */ -fun Assert.name() = having("name", File::getName) +fun Assert.havingName() = having("name", File::getName) + +@Deprecated( + message = "Function name has been renamed to havingName", + replaceWith = ReplaceWith("havingName()"), + level = DeprecationLevel.WARNING +) +fun Assert.name() = havingName() /** * Returns an assert on the file's path. */ -fun Assert.path() = having("path", File::getPath) +fun Assert.havingPath() = having("path", File::getPath) + +@Deprecated( + message = "Function path has been renamed to havingPath", + replaceWith = ReplaceWith("havingPath()"), + level = DeprecationLevel.WARNING +) +fun Assert.path() = havingPath() /** * Returns an assert on the file's parent. */ -fun Assert.parent() = having("parent", File::getParent) +fun Assert.havingParent() = having("parent", File::getParent) + +@Deprecated( + message = "Function parent has been renamed to havingParent", + replaceWith = ReplaceWith("havingParent()"), + level = DeprecationLevel.WARNING +) +fun Assert.parent() = havingParent() /** * Returns an assert on the file's extension. */ -fun Assert.extension() = having("extension", File::extension) +fun Assert.havingExtension() = having("extension", File::extension) + +@Deprecated( + message = "Function extension has been renamed to havingExtension", + replaceWith = ReplaceWith("havingExtension()"), + level = DeprecationLevel.WARNING +) +fun Assert.extension() = havingExtension() /** * Returns an assert on the file's contents as text. @@ -86,28 +114,28 @@ fun Assert.isNotHidden() = given { actual -> * Asserts the file has the expected name. */ fun Assert.hasName(expected: String) { - name().isEqualTo(expected) + havingName().isEqualTo(expected) } /** * Asserts the file has the expected path. */ fun Assert.hasPath(expected: String) { - path().isEqualTo(File(expected).path) + havingPath().isEqualTo(File(expected).path) } /** * Asserts the file has the expected parent path. */ fun Assert.hasParent(expected: String) { - parent().isEqualTo(File(expected).path) + havingParent().isEqualTo(File(expected).path) } /** * Asserts the file has the expected extension. */ fun Assert.hasExtension(expected: String) { - extension().isEqualTo(expected) + havingExtension().isEqualTo(expected) } /** From 0521af002b50826d91915cabdee3f094804ca730 Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Mon, 20 May 2024 16:40:12 +0100 Subject: [PATCH 09/10] Rename JVM File contents helper functions --- .../jvmMain/kotlin/assertk/assertions/file.kt | 20 ++++++++++++++++--- .../test/assertk/assertions/FileTest.kt | 8 ++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/assertk/src/jvmMain/kotlin/assertk/assertions/file.kt b/assertk/src/jvmMain/kotlin/assertk/assertions/file.kt index ff0a3246..1ffe2606 100644 --- a/assertk/src/jvmMain/kotlin/assertk/assertions/file.kt +++ b/assertk/src/jvmMain/kotlin/assertk/assertions/file.kt @@ -59,12 +59,26 @@ fun Assert.extension() = havingExtension() /** * Returns an assert on the file's contents as text. */ -fun Assert.text(charset: Charset = Charsets.UTF_8) = having("text") { it.readText(charset) } +fun Assert.havingText(charset: Charset = Charsets.UTF_8) = having("text") { it.readText(charset) } + +@Deprecated( + message = "Function text has been renamed to havingText", + replaceWith = ReplaceWith("havingText()"), + level = DeprecationLevel.WARNING +) +fun Assert.text(charset: Charset = Charsets.UTF_8) = havingText() /** * Returns an assert on the file's contents as bytes. */ -fun Assert.bytes() = having("bytes", File::readBytes) +fun Assert.havingBytes() = having("bytes", File::readBytes) + +@Deprecated( + message = "Function bytes has been renamed to havingBytes", + replaceWith = ReplaceWith("havingBytes()"), + level = DeprecationLevel.WARNING +) +fun Assert.bytes() = havingBytes() /** * Asserts the file exists. @@ -144,7 +158,7 @@ fun Assert.hasExtension(expected: String) { * @see [hasBytes] */ fun Assert.hasText(expected: String, charset: Charset = Charsets.UTF_8) { - text(charset).isEqualTo(expected) + havingText(charset).isEqualTo(expected) } /** diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt index 3518c891..08746784 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt @@ -204,13 +204,13 @@ class FileTest { //region contains @Test fun contains_correct_substring_passes() { - assertThat(fileWithText).text().contains("Forty-two") + assertThat(fileWithText).havingText().contains("Forty-two") } @Test fun contains_wrong_substring_fails() { val error = assertFailsWith { - assertThat(fileWithText).text().contains("Forty-two!") + assertThat(fileWithText).havingText().contains("Forty-two!") } assertTrue(error.message!!.startsWith("expected [text] to contain:<\"Forty-two!\"> but was:<\"$text\">")) assertTrue(error.message!!.contains("file_contains")) @@ -228,14 +228,14 @@ class FileTest { @Test fun matches_correct_regex_passes() { - assertThat(matchingFile).text().matches(".a...e.".toRegex()) + assertThat(matchingFile).havingText().matches(".a...e.".toRegex()) } @Test fun matches_wrong_regex_fails() { val incorrectRegexp = ".*d".toRegex() val error = assertFailsWith { - assertThat(matchingFile).text().matches(incorrectRegexp) + assertThat(matchingFile).havingText().matches(incorrectRegexp) } assertTrue(error.message!!.startsWith("expected [text] to match: but was:<\"$matchingText\">")) assertTrue(error.message!!.contains("file_contains")) From 575b5c95c7f338d3b1ef718606c9094200d1c9c8 Mon Sep 17 00:00:00 2001 From: Joseph Cooper Date: Mon, 20 May 2024 16:42:50 +0100 Subject: [PATCH 10/10] Rename JVM Path helper functions --- .../jvmMain/kotlin/assertk/assertions/path.kt | 18 ++++++++++++++++-- .../kotlin/test/assertk/assertions/PathTest.kt | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/assertk/src/jvmMain/kotlin/assertk/assertions/path.kt b/assertk/src/jvmMain/kotlin/assertk/assertions/path.kt index d7335397..bdf9880b 100644 --- a/assertk/src/jvmMain/kotlin/assertk/assertions/path.kt +++ b/assertk/src/jvmMain/kotlin/assertk/assertions/path.kt @@ -13,13 +13,27 @@ import java.nio.file.Path * * @param charset charset to use when reading file */ -fun Assert.lines(charset: Charset = Charsets.UTF_8): Assert> = +fun Assert.havingLines(charset: Charset = Charsets.UTF_8): Assert> = transform { actual -> Files.readAllLines(actual, charset) } +@Deprecated( + message = "Function lines has been renamed to havingLines", + replaceWith = ReplaceWith("havingLines()"), + level = DeprecationLevel.WARNING +) +fun Assert.lines(charset: Charset = Charsets.UTF_8): Assert> = havingLines() + /** Assert on file bytes */ -fun Assert.bytes(): Assert = +fun Assert.havingBytes(): Assert = transform { actual -> Files.readAllBytes(actual) } +@Deprecated( + message = "Function bytes has been renamed to havingBytes", + replaceWith = ReplaceWith("havingBytes()"), + level = DeprecationLevel.WARNING +) +fun Assert.bytes(): Assert = havingBytes() + /** Assert that the path is a regular file. * * @param options indicating how symbolic links are handled diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt index 86a92368..e5e77bcd 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt @@ -164,14 +164,14 @@ class PathTest { //region lines @Test fun lines_correct_string_passes() { - assertThat(regularFileWithText!!).lines().containsExactly("a", "b") + assertThat(regularFileWithText!!).havingLines().containsExactly("a", "b") } //endregion //region bytes @Test fun bytes_value_correct_byte_array_passes() { - assertThat(regularFile!!).bytes().containsExactly(*ByteArray(10)) + assertThat(regularFile!!).havingBytes().containsExactly(*ByteArray(10)) } //endregion }