From bf5e18fd1694882a318e204be6a31bc1757db72d Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Thu, 15 Oct 2020 09:40:09 +0200 Subject: IsException should also be true when class inherits from Exception (#1558) --- .../test/kotlin/transformers/isExceptionTest.kt | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 plugins/base/src/test/kotlin/transformers/isExceptionTest.kt (limited to 'plugins/base/src/test/kotlin/transformers') 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()) { + 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()) { + 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()) { + 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()) { + 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()) { + 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()) { + name equals "NotAnException" + isException equals false + } + } + } + + @Test + fun `isException should return false for a typealias`(){ + inlineModelTest( + """ + |typealias NotAnException = Serializable""" + ) { + with((this / "classes" / "NotAnException").cast()) { + 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()) { + 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()) { + 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()) { + name equals "NotAnException" + isException equals false + } + } + } +} \ No newline at end of file -- cgit