Skip to content

Commit

Permalink
KTOR-2555 Drop kotlin-test-junit dependency (#2532)
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l authored Jun 30, 2021
1 parent 2a836a5 commit 0dfcb54
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 107 deletions.
5 changes: 0 additions & 5 deletions ktor-io/api/ktor-io.api
Original file line number Diff line number Diff line change
Expand Up @@ -1713,11 +1713,6 @@ public final class io/ktor/utils/io/core/UnsignedTypesKt {
public static final fun writeUShort-SLr1GAc (Lio/ktor/utils/io/core/Output;S)V
}

public final class io/ktor/utils/io/core/UseKt {
public static final fun use (Lio/ktor/utils/io/core/Input;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static final fun use (Lio/ktor/utils/io/core/Output;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
}

public class io/ktor/utils/io/core/internal/ChunkBuffer : io/ktor/utils/io/core/Buffer {
public static final field Companion Lio/ktor/utils/io/core/internal/ChunkBuffer$Companion;
public synthetic fun <init> (Ljava/nio/ByteBuffer;Lio/ktor/utils/io/core/internal/ChunkBuffer;Lio/ktor/utils/io/pool/ObjectPool;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down
17 changes: 0 additions & 17 deletions ktor-io/common/src/io/ktor/utils/io/core/Use.kt

This file was deleted.

2 changes: 1 addition & 1 deletion ktor-server/ktor-server-test-host/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ kotlin.sourceSets {
api("org.mortbay.jetty.alpn:alpn-boot:$jetty_alpn_boot_version")
}

api("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
api("junit:junit:$junit_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutines_version")
}
Expand All @@ -40,6 +39,7 @@ kotlin.sourceSets {
val jvmTest by getting {
dependencies {
api(project(":ktor-server:ktor-server-core", configuration = "testOutput"))
api("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import java.util.concurrent.*
import javax.net.ssl.*
import kotlin.concurrent.*
import kotlin.coroutines.*
import kotlin.test.*

@Suppress("KDocMissingDocumentation")
public abstract class EngineTestBase<TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration>(
Expand Down Expand Up @@ -85,9 +84,10 @@ public abstract class EngineTestBase<TEngine : ApplicationEngine, TConfiguration

protected val socketReadTimeout: Int by lazy { TimeUnit.SECONDS.toMillis(timeout).toInt() }

@BeforeTest
@Before
public fun setUpBase() {
val method = this.javaClass.getMethod(test.methodName) ?: fail("Method ${test.methodName} not found")
val method = this.javaClass.getMethod(test.methodName)
?: throw AssertionError("Method ${test.methodName} not found")

if (method.isAnnotationPresent(Http2Only::class.java)) {
Assume.assumeTrue("http2 is not enabled", enableHttp2)
Expand All @@ -100,14 +100,14 @@ public abstract class EngineTestBase<TEngine : ApplicationEngine, TConfiguration
exceptions.clear()
}

@AfterTest
@After
public fun tearDownBase() {
try {
allConnections.forEach { it.disconnect() }
testLog.trace("Disposing server on port $port (SSL $sslPort)")
(server as? ApplicationEngine)?.stop(1000, 5000, TimeUnit.MILLISECONDS)
if (exceptions.isNotEmpty()) {
fail("Server exceptions logged, consult log output for more information")
throw AssertionError("Server exceptions logged, consult log output for more information")
}
} finally {
testJob.cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@

package io.ktor.server.testing

import io.ktor.application.*
import io.ktor.http.*
import org.junit.Assert.*

/**
* [on] function receiver object
*/
public object On
object On

/**
* [it] function receiver object
*/
public object It
object It

/**
* DSL for creating a test case
*/
@Suppress("UNUSED_PARAMETER")
public fun on(comment: String, body: On.() -> Unit) = On.body()
fun on(comment: String, body: On.() -> Unit) = On.body()

/**
* DSL function for test test case assertions
*/
@Suppress("UNUSED_PARAMETER")
public inline fun On.it(description: String, body: It.() -> Unit) = It.body()
inline fun On.it(description: String, body: It.() -> Unit) = It.body()

/**
* Return parsed content type from the test response
*/
public fun TestApplicationResponse.contentType(): ContentType {
fun TestApplicationResponse.contentType(): ContentType {
val contentTypeHeader = requireNotNull(headers[HttpHeaders.ContentType])
return ContentType.parse(contentTypeHeader)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ package io.ktor.server.testing.client
import io.ktor.client.engine.*
import io.ktor.server.testing.*

public class TestHttpClientConfig : HttpClientEngineConfig() {
class TestHttpClientConfig : HttpClientEngineConfig() {
lateinit var app: TestApplicationEngine
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class TestHttpClientEngine(override val config: TestHttpClientConfig) : H
clientJob.complete()
}

public companion object : HttpClientEngineFactory<TestHttpClientConfig> {
companion object : HttpClientEngineFactory<TestHttpClientConfig> {
override fun create(block: TestHttpClientConfig.() -> Unit): HttpClientEngine {
val config = TestHttpClientConfig().apply(block)
return TestHttpClientEngine(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

package io.ktor.server.testing

import org.junit.Assert.*
import java.io.*
import java.util.zip.*
import kotlin.test.*

internal suspend fun assertFailsSuspend(block: suspend () -> Unit): Throwable {
var exception: Throwable? = null
Expand All @@ -17,7 +17,7 @@ internal suspend fun assertFailsSuspend(block: suspend () -> Unit): Throwable {
}

assertNotNull(exception)
return exception
return exception!!
}

internal fun InputStream.crcWithSize(): Pair<Long, Long> {
Expand Down Expand Up @@ -81,9 +81,9 @@ internal fun BufferedReader.skipHttpResponseContent(contentLength: Int) {
while (current < contentLength) {
val ch = read()
assertNotEquals(
"Server promised $contentLength bytes but we only got $current bytes",
-1,
ch,
"Server promised $contentLength bytes but we only got $current bytes"
ch
)
when (ch.toChar()) {
in '\u0000'..'\u007f' -> current++
Expand All @@ -93,3 +93,15 @@ internal fun BufferedReader.skipHttpResponseContent(contentLength: Int) {
}
}
}

internal inline fun <reified T : Throwable> assertFailsWith(block: () -> Unit) {
var failed = false
try {
block()
} catch (cause: Throwable) {
failed = true
assertTrue(cause is T)
}

assertTrue(failed)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import io.ktor.server.engine.*
import io.ktor.server.testing.*
import io.ktor.utils.io.*
import io.ktor.utils.io.jvm.javaio.*
import org.junit.*
import org.junit.Assert.*
import java.io.*
import java.util.zip.*
import kotlin.test.*

abstract class CompressionTestSuite<TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration>(
hostFactory: ApplicationEngineFactory<TEngine, TConfiguration>
) : EngineTestBase<TEngine, TConfiguration>(hostFactory) {

@Test
fun testLocalFileContentWithCompression() {
val file = loadTestFile()
Expand Down Expand Up @@ -94,9 +96,9 @@ abstract class CompressionTestSuite<TEngine : ApplicationEngine, TConfiguration
) {
assertEquals(HttpStatusCode.PartialContent.value, status.value)
assertEquals(
"It should be no compression if range requested",
file.reader().use { it.read().toChar().toString() },
readText(),
"It should be no compression if range requested"
readText()
)
}
}
Expand Down Expand Up @@ -125,7 +127,7 @@ abstract class CompressionTestSuite<TEngine : ApplicationEngine, TConfiguration
val expected = buildString {
produceText()
}
assertTrue { HttpHeaders.ContentEncoding in headers }
assertTrue(HttpHeaders.ContentEncoding in headers)
val array = receive<ByteArray>()
val text = GZIPInputStream(ByteArrayInputStream(array)).readBytes().toString(Charsets.UTF_8)
assertEquals(expected, text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
package io.ktor.server.testing.suites

import io.ktor.server.engine.*
import io.ktor.server.testing.*
import org.junit.*
import org.junit.Assert.*
import java.util.concurrent.*
import kotlin.test.*

var count = 0

Expand Down
Loading

0 comments on commit 0dfcb54

Please sign in to comment.