Skip to content
This repository was archived by the owner on Jan 3, 2025. It is now read-only.
This repository was archived by the owner on Jan 3, 2025. It is now read-only.

Unintuitive error description #120

@igorwojda

Description

@igorwojda
class StringMaxCharTest {
    @Test
    fun `SOme test`() {
        maxChar("a") shouldEqual 'a'
    }
}

fun maxChar(str: String): Char? {
    val map = mutableMapOf<Char, Int>()

    str.forEach {
        map[it] = (map[it] ?: 0)  + 1
    }

    return map.maxBy { it.value }?.key
}

Above tests works fine, however when we change our assertion to compare with String, not Char:
maxChar("a") shouldEqual "a"

...tests fails with very unintuitive error description
java.lang.AssertionError: Expected <a>, actual <a>.

It's quite easy to make such a mistake by a programmer, so maybe Kluent can address this issue in a better way eg. by checking if the string has a single character and converting it to Char or display data types in error description

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions