Skip to content

Commit 656ccb0

Browse files
committed
[android] Add test for catching .NET exceptions
1 parent 8a3a281 commit 656ccb0

File tree

1 file changed

+24
-1
lines changed
  • Samples/Beyond.NET.Sample.Android/app/src/androidTest/java/com/example/beyondnetsampleandroid

1 file changed

+24
-1
lines changed

Samples/Beyond.NET.Sample.Android/app/src/androidTest/java/com/example/beyondnetsampleandroid/SystemExceptionTests.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,28 @@ class SystemExceptionTests {
2121
assertEquals(exceptionMessage, retrievedExceptionMessage)
2222
}
2323

24-
// TODO: Add tests for throwing/catching exceptions that occur within .NET
24+
@Test
25+
fun testCatchingDNExceptions() {
26+
val exceptionMessage = "I'm a nice exception"
27+
val createdException = System_Exception(exceptionMessage.toDotNETString())
28+
29+
var caughtThrowable: Throwable?
30+
31+
try {
32+
Beyond_NET_Sample_ExceptionTests.`throw`(createdException)
33+
caughtThrowable = null
34+
} catch (e: Throwable) {
35+
caughtThrowable = e
36+
}
37+
38+
assertNotNull(caughtThrowable)
39+
assertTrue(caughtThrowable is DNException)
40+
41+
val caughtException = caughtThrowable as DNException
42+
assertEquals(caughtException.dnException, createdException)
43+
44+
assertEquals(caughtException.message, exceptionMessage)
45+
assertNotNull(caughtException.dnStackTrace)
46+
assertFalse(caughtException.dnStackTrace!!.isEmpty())
47+
}
2548
}

0 commit comments

Comments
 (0)