Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assertk/src/jvmMain/kotlin/assertk/assertions/any.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ private fun <T> Assert<T>.isDataClassEqualToImpl(expected: T, kclass: KClass<*>?
/**
* Returns an assert that compares all accessible properties except the given properties on the calling class.
* @param other Other value to compare to
* @param properties properties of the type with which been ignored
* @param properties properties of the type which will be ignored during comparison
*
* ```
* assertThat(person).isEqualToIgnoringGivenProperties(other, Person::name, Person::age)
* ```
*/
fun <T : Any> Assert<T>.isEqualToIgnoringGivenProperties(other: T, vararg properties: KProperty1<T, Any?>) {
fun <T : Any> Assert<T>.isEqualToIgnoringGivenProperties(other: T, vararg properties: KProperty1<out T, Any?>) {
all {
for (prop in other::class.memberProperties) {
if (!properties.contains(prop)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ class JavaAnyTest {
BasicObject::failing
)
}

@Test
fun isEqualToIgnoringGivenProperties_passes_subclass() {
fun testObject(): TestObject {
return BasicObject(str = "Rarity")
}

assertThat(
testObject()
).isEqualToIgnoringGivenProperties(
BasicObject(str = "notRarity"),
BasicObject::str,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to the change this would fail to compile, since at compilation time T == TestObject, so the method only allows passing properties of TestObject and not its subclasses.

BasicObject::other,
BasicObject::failing
)
}
//endregion

open class TestObject
Expand Down