Skip to content

Commit

Permalink
Cleanup kt tests with assertThrows
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Aug 16, 2024
1 parent dc0376c commit acdf9b1
Showing 1 changed file with 14 additions and 47 deletions.
61 changes: 14 additions & 47 deletions bound/kt/src/test/kotlin/web5/sdk/vc/VerifiableCredentialTest.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package web5.sdk.vc

import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.fail
import web5.sdk.UnitTestSuite
import web5.sdk.rust.Web5Exception
Expand Down Expand Up @@ -115,19 +113,12 @@ class VerifiableCredentialTest {
fun test_issuer_string_must_not_be_empty() {
this.testSuite.include()
val emptyIssuer = Issuer.StringIssuer("")
try {

val exception = assertThrows<Web5Exception.Exception> {
VerifiableCredential.create(emptyIssuer, CREDENTIAL_SUBJECT, VerifiableCredentialCreateOptions())
fail("Expected an exception to be thrown")
} catch (e: Web5Exception) {
when (e) {
is Web5Exception.Exception -> {
assertEquals(e.msg, "parameter error issuer id must not be empty")
}
else -> {
fail("Caught an unexpected exception type")
}
}
}

assertEquals("parameter error issuer id must not be empty", exception.msg)
}

@Test
Expand All @@ -142,39 +133,23 @@ class VerifiableCredentialTest {
this.testSuite.include()
val issuer = Issuer.ObjectIssuer("", "Example Name")

try {
val exception = assertThrows<Web5Exception.Exception> {
VerifiableCredential.create(issuer, CREDENTIAL_SUBJECT, VerifiableCredentialCreateOptions())
fail("Expected an exception to be thrown")
} catch (e: Web5Exception) {
when (e) {
is Web5Exception.Exception -> {
assertEquals(e.msg, "parameter error issuer id must not be empty")
}
else -> {
fail("Caught an unexpected exception type")
}
}
}

assertEquals("parameter error issuer id must not be empty", exception.msg)
}

@Test
fun test_issuer_object_name_must_not_be_empty() {
this.testSuite.include()
val issuer = Issuer.ObjectIssuer(ISSUER_DID_URI, "")

try {
val exception = assertThrows<Web5Exception.Exception> {
VerifiableCredential.create(issuer, CREDENTIAL_SUBJECT, VerifiableCredentialCreateOptions())
fail("Expected an exception to be thrown")
} catch (e: Web5Exception) {
when (e) {
is Web5Exception.Exception -> {
assertEquals(e.msg, "parameter error named issuer name must not be empty")
}
else -> {
fail("Caught an unexpected exception type")
}
}
}

assertEquals("parameter error named issuer name must not be empty", exception.msg)
}

@Test
Expand Down Expand Up @@ -211,19 +186,11 @@ class VerifiableCredentialTest {
this.testSuite.include()
val credentialSubject = CredentialSubject("")

try {
val exception = assertThrows<Web5Exception.Exception> {
VerifiableCredential.create(ISSUER, credentialSubject, VerifiableCredentialCreateOptions())
fail("Expected an exception to be thrown")
} catch (e: Web5Exception) {
when (e) {
is Web5Exception.Exception -> {
assertEquals(e.msg, "parameter error subject id must not be empty")
}
else -> {
fail("Caught an unexpected exception type")
}
}
}

assertEquals("parameter error subject id must not be empty", exception.msg)
}

@Test
Expand Down

0 comments on commit acdf9b1

Please sign in to comment.