package de.trainingstagebuch.app.utils

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class JsonSafeUtilsTest {

    @Test
    fun `parseObject and getString extract known keys`() {
        val obj = JsonSafeUtils.parseObject("""{"code":"ERROR_X","message":"Fehler"}""")
        requireNotNull(obj)
        assertEquals("ERROR_X", JsonSafeUtils.getString(obj, "code"))
        assertEquals("Fehler", JsonSafeUtils.getString(obj, "message"))
    }

    @Test
    fun `parseObject returns null for invalid json`() {
        assertNull(JsonSafeUtils.parseObject("not-json"))
    }
}
