Skip to content

Issue comparing ByteArrays inside a Map #541

@11aescalante

Description

@11aescalante

When using isEqualTo to compare two ByteArrays it works by using contentEquals internally. But when using isEqualTo on a Collection (or any Collection assert like containsOnly), it seems that it is comparing the ByteArrays by reference. These are two examples:

val a1 = byteArrayOf(0x01, 0x02)
val a2 = byteArrayOf(0x01, 0x02)

assertThat(a1).isEqualTo(a2) //Test pass
val a1 = mapOf(1 to byteArrayOf(0x01, 0x02))
val a2 = mapOf(1 to byteArrayOf(0x01, 0x02))

assertThat(a1).isEqualTo(a2) //This fails "expected:<{1=[1, 2]}> with type:<class java.util.Collections$SingletonMap (Kotlin reflection is not available)> did not compare equal to the same type with the same string representation"
assertThat(a1).containsOnly(*a2.map { it.key to it.value }.toTypedArray()) //This also fails "expected to contain only:<{1=[1, 2]}> but was:<{1=[1, 2]}>"

As containsOnly and the other Collection variants are very useful for testing, I would expect them to compare underlying Collections with their proper comparators. Is there any chance this could be addressed in a future release?

assertk version used 0.28.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions