Skip to content

Commit

Permalink
refactor: if AttachmentData is not a supported type, throw exception
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian G <[email protected]>

fix: linting
Signed-off-by: Cristian G <[email protected]>
  • Loading branch information
cristianIOHK committed Aug 7, 2024
1 parent a889273 commit 7977f49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.JsonNames
import kotlinx.serialization.json.jsonObject
import org.hyperledger.identus.apollo.base64.base64UrlDecoded
import org.hyperledger.identus.walletsdk.edgeagent.EdgeAgentError
import java.util.UUID
import kotlin.jvm.JvmOverloads

Expand All @@ -27,31 +28,19 @@ sealed class AttachmentData {
/**
* This method verifies the type of [AttachmentData] and returns the data as a json string.
*/
fun getDataAsJsonString(): String? {
fun getDataAsJsonString(): String {
return when (this) {
is AttachmentHeader -> {
null
}

is AttachmentJws -> {
null
}

is AttachmentJwsData -> {
null
}

is AttachmentBase64 -> {
this.base64.base64UrlDecoded
}

is AttachmentLinkData -> {
null
}

is AttachmentJsonData -> {
this.data
}

else -> {
throw EdgeAgentError.AttachmentTypeNotSupported()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.mockito.Mock
import org.hyperledger.identus.walletsdk.pollux.models.PresentationSubmission
import org.junit.Assert.assertNull
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations
Expand Down Expand Up @@ -1632,8 +1631,9 @@ class EdgeAgentTests {
)
)
val attachments1 = message1.attachments
val attachmentDataString2 = attachments1.first().data.getDataAsJsonString()
assertNull(attachmentDataString2)
assertFailsWith<EdgeAgentError.AttachmentTypeNotSupported> {
attachments1.first().data.getDataAsJsonString()
}
}

val getCredentialDefinitionResponse =
Expand Down

0 comments on commit 7977f49

Please sign in to comment.