kotlin.test: Rename jvm module to junit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
|
||||
<id>sources</id>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
|
||||
<baseDirectory>/</baseDirectory>
|
||||
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<filtered>true</filtered>
|
||||
<lineEnding>unix</lineEnding>
|
||||
|
||||
<directory>../shared/src/main/kotlin</directory>
|
||||
|
||||
<outputDirectory/>
|
||||
|
||||
<includes>
|
||||
<include>**/*.kt</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<filtered>true</filtered>
|
||||
<lineEnding>unix</lineEnding>
|
||||
|
||||
<directory>../shared/src/main/kotlin.jvm</directory>
|
||||
<outputDirectory/>
|
||||
|
||||
<includes>
|
||||
<include>**/*.kt</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<filtered>true</filtered>
|
||||
<lineEnding>unix</lineEnding>
|
||||
|
||||
<directory>src/main/kotlin</directory>
|
||||
<outputDirectory/>
|
||||
|
||||
<includes>
|
||||
<include>**/*.kt</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
@@ -0,0 +1,41 @@
|
||||
package kotlin.test.junit
|
||||
|
||||
import org.junit.*
|
||||
import kotlin.test.*
|
||||
|
||||
class JUnitContributor : AsserterContributor {
|
||||
override fun contribute(): Asserter? {
|
||||
for (stackFrame in currentStackTrace()) {
|
||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
val className = stackFrame.className as java.lang.String
|
||||
|
||||
if (className.startsWith("org.junit.") || className.startsWith("junit.")) {
|
||||
return JUnitAsserter
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
object JUnitAsserter : Asserter {
|
||||
override fun assertEquals(message : String?, expected : Any?, actual : Any?) {
|
||||
Assert.assertEquals(message, expected, actual)
|
||||
}
|
||||
|
||||
override fun assertNotEquals(message : String?, illegal : Any?, actual : Any?) {
|
||||
Assert.assertNotEquals(message, illegal, actual)
|
||||
}
|
||||
|
||||
override fun assertNotNull(message : String?, actual : Any?) {
|
||||
Assert.assertNotNull(message ?: "actual value is null", actual)
|
||||
}
|
||||
|
||||
override fun assertNull(message : String?, actual : Any?) {
|
||||
Assert.assertNull(message ?: "actual value is not null", actual)
|
||||
}
|
||||
|
||||
override fun fail(message : String?) {
|
||||
Assert.fail(message)
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
kotlin.test.junit.JUnitContributor
|
||||
@@ -0,0 +1,27 @@
|
||||
package kotlinx.testing.tests
|
||||
|
||||
import org.junit.*
|
||||
import java.util.concurrent.*
|
||||
|
||||
class JUnitContributorTest {
|
||||
@Test
|
||||
fun smokeTest() {
|
||||
Assert.assertEquals("JUnitAsserter", asserter.`class`.simpleName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should fail to contribute if it was run outside of junit`() {
|
||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
val q = ArrayBlockingQueue<java.lang.Object>(1)
|
||||
|
||||
Thread {
|
||||
q.put(asserter)
|
||||
}.start()
|
||||
|
||||
Assert.assertEquals("DefaultAsserter", q.take().`class`.simpleName)
|
||||
}
|
||||
|
||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
private val asserter: java.lang.Object
|
||||
get() = Class.forName("kotlin.test.TestAssertionsKt").getMethod("getAsserter").invoke(null) as java.lang.Object
|
||||
}
|
||||
Reference in New Issue
Block a user