aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/transformers/isExceptionTest.kt
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2020-10-15 09:40:09 +0200
committerGitHub <noreply@github.com>2020-10-15 09:40:09 +0200
commitbf5e18fd1694882a318e204be6a31bc1757db72d (patch)
treeeddc619638733a6b5822d6a95855842bf6bf1102 /plugins/base/src/test/kotlin/transformers/isExceptionTest.kt
parent7e2678e5e182afc10c3ca98107aae3c7590b909b (diff)
downloaddokka-bf5e18fd1694882a318e204be6a31bc1757db72d.tar.gz
dokka-bf5e18fd1694882a318e204be6a31bc1757db72d.tar.bz2
dokka-bf5e18fd1694882a318e204be6a31bc1757db72d.zip
IsException should also be true when class inherits from Exception (#1558)
Diffstat (limited to 'plugins/base/src/test/kotlin/transformers/isExceptionTest.kt')
-rw-r--r--plugins/base/src/test/kotlin/transformers/isExceptionTest.kt142
1 files changed, 142 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/transformers/isExceptionTest.kt b/plugins/base/src/test/kotlin/transformers/isExceptionTest.kt
new file mode 100644
index 00000000..131c7b77
--- /dev/null
+++ b/plugins/base/src/test/kotlin/transformers/isExceptionTest.kt
@@ -0,0 +1,142 @@
+package transformers
+
+import org.jetbrains.dokka.base.transformers.documentables.isException
+import org.jetbrains.dokka.model.DClass
+import org.jetbrains.dokka.model.DTypeAlias
+import org.junit.jupiter.api.Test
+import utils.AbstractModelTest
+
+class IsExceptionKotlinTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "classes") {
+ @Test
+ fun `isException should work for kotlin exception`(){
+ inlineModelTest(
+ """
+ |class ExampleException(): Exception()"""
+ ) {
+ with((this / "classes" / "ExampleException").cast<DClass>()) {
+ name equals "ExampleException"
+ isException equals true
+ }
+ }
+ }
+
+ @Test
+ fun `isException should work for java exceptions`(){
+ inlineModelTest(
+ """
+ |class ExampleException(): java.lang.Exception()"""
+ ) {
+ with((this / "classes" / "ExampleException").cast<DClass>()) {
+ name equals "ExampleException"
+ isException equals true
+ }
+ }
+ }
+
+ @Test
+ fun `isException should work for RuntimeException`(){
+ inlineModelTest(
+ """
+ |class ExampleException(reason: String): RuntimeException(reason)"""
+ ) {
+ with((this / "classes" / "ExampleException").cast<DClass>()) {
+ name equals "ExampleException"
+ isException equals true
+ }
+ }
+ }
+
+ @Test
+ fun `isException should work if exception is typealiased`(){
+ inlineModelTest(
+ """
+ |typealias ExampleException = java.lang.Exception"""
+ ) {
+ with((this / "classes" / "ExampleException").cast<DTypeAlias>()) {
+ name equals "ExampleException"
+ isException equals true
+ }
+ }
+ }
+
+ @Test
+ fun `isException should work if exception is extending a typaliased class`(){
+ inlineModelTest(
+ """
+ |class ExampleException(): Exception()
+ |typealias ExampleExceptionAlias = ExampleException"""
+ ) {
+ with((this / "classes" / "ExampleExceptionAlias").cast<DTypeAlias>()) {
+ name equals "ExampleExceptionAlias"
+ isException equals true
+ }
+ }
+ }
+
+ @Test
+ fun `isException should return false for a basic class`(){
+ inlineModelTest(
+ """
+ |class NotAnException(): Serializable"""
+ ) {
+ with((this / "classes" / "NotAnException").cast<DClass>()) {
+ name equals "NotAnException"
+ isException equals false
+ }
+ }
+ }
+
+ @Test
+ fun `isException should return false for a typealias`(){
+ inlineModelTest(
+ """
+ |typealias NotAnException = Serializable"""
+ ) {
+ with((this / "classes" / "NotAnException").cast<DTypeAlias>()) {
+ name equals "NotAnException"
+ isException equals false
+ }
+ }
+ }
+}
+
+class IsExceptionJavaTest: AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
+ @Test
+ fun `isException should work for java exceptions`(){
+ inlineModelTest(
+ """
+ |class ExampleException extends java.lang.Exception { }"""
+ ) {
+ with((this / "java" / "ExampleException").cast<DClass>()) {
+ name equals "ExampleException"
+ isException equals true
+ }
+ }
+ }
+
+ @Test
+ fun `isException should work for RuntimeException`(){
+ inlineModelTest(
+ """
+ |class ExampleException extends java.lang.RuntimeException"""
+ ) {
+ with((this / "java" / "ExampleException").cast<DClass>()) {
+ name equals "ExampleException"
+ isException equals true
+ }
+ }
+ }
+
+ @Test
+ fun `isException should return false for a basic class`(){
+ inlineModelTest(
+ """
+ |class NotAnException extends Serializable"""
+ ) {
+ with((this / "java" / "NotAnException").cast<DClass>()) {
+ name equals "NotAnException"
+ isException equals false
+ }
+ }
+ }
+} \ No newline at end of file