How to mock creation of NdefMessage in JUnit test for Android

Viewed 97

In my code I am creating NdefMessage from bytes, which gives me ability to parse the payload from one of its record.

Unfortunately, when I am writing Junit tests for that parser I am getting an exception as I invoking:

NdefMessage(bytesToParse)

So then I am searching for specific payload to return by that parser:

ndefMessage.records.forEach {
    if (it.type?.contentEquals(hexStringToByteArray("617376")) == true)
    {
        return String(it.payload)
    }

}

Unfortunately, I am getting this error in my JUnit test:

java.lang.RuntimeException: Method getRecords in android.nfc.NdefMessage not mocked. See http://g.co/androidstudio/not-mocked for details.

Is it possible to create some substitute from NdefMessage (for just using it to have NdefMessage object structure and ability to get to the payload)? Or just mock the NdefMessage somehow in JUnit?

0 Answers
Related