package ch.threema.common.models

import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

class CryptographicByteArrayTest {
    @Test
    fun `equality of 2 arrays`() {
        val array1 = CryptographicByteArray(byteArrayOf(1, 2, 3))
        val array2 = CryptographicByteArray(byteArrayOf(1, 2, 3))
        assertEquals(array1, array2)
    }

    @Test
    fun `inequality of 2 arrays`() {
        val array1 = CryptographicByteArray(byteArrayOf(1, 2, 3))
        val array2 = CryptographicByteArray(byteArrayOf(1, 2, 3, 4))
        assertNotEquals(array1, array2)
    }

    @Test
    fun deconstruction() {
        val (byteArray) = CryptographicByteArray(byteArrayOf(1, 2, 3))
        assertContentEquals(byteArrayOf(1, 2, 3), byteArray)
    }

    @Test
    fun `toString does not reveal the whole array`() {
        val array = CryptographicByteArray(byteArrayOf(33, 10, 3, 100, 1, 2, 3, 4))
        assertEquals("[8 bytes: 21,0a,03,...]", array.toString())
    }
}
