Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ subprojects {
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

tasks.withType<AbstractKotlinCompile<*>>().configureEach {
compilerOptions.apply {
freeCompilerArgs.add("-Xexpect-actual-classes")
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ jmh-generator = { module = "org.openjdk.jmh:jmh-generator-annprocess", version.r
jmh-gradle-plugin = { module = "me.champeau.jmh:jmh-gradle-plugin", version = "0.7.3" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
kotlin-test-junit5 = { module = "org.jetbrains.kotlin:kotlin-test-junit5", version.ref = "kotlin" }
kotlin-time = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version = "0.8.0-0.6.x-compat" }
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "8.0.0" }
tapmoc-gradle-plugin = { module = "com.gradleup.tapmoc:com.gradleup.tapmoc.gradle.plugin", version = "0.4.2"}
test-assertk = "com.willowtreeapps.assertk:assertk:0.28.1"
test-jimfs = "com.google.jimfs:jimfs:1.3.2"
test-junit = { module = "junit:junit", version = "4.13.2" }
test-junit5 = { module = "org.junit.jupiter:junit-jupiter-api", version = "5.13.4" }
vanniktech-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.37.0" }
2 changes: 1 addition & 1 deletion okio-testing-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ kotlin {
// On the JVM the kotlin-test library resolves to one of three implementations based on
// which testing framework is in use. JUnit is used downstream, but Gradle can't know that
// here and thus fails to select a variant automatically. Declare it manually instead.
api(libs.kotlin.test.junit)
api(libs.kotlin.test.junit5)
}
}

Expand Down
4 changes: 4 additions & 0 deletions okio-testing-support/src/jvmMain/kotlin/okio/TestingJvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package okio

import java.io.File

actual fun isBrowser() = false

actual fun getEnv(name: String): String? = System.getenv(name)

fun File.newFile(): File = File.createTempFile("tmp_file", null, this)
2 changes: 1 addition & 1 deletion okio/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ kotlin {
dependsOn(nonWasmTest)
dependsOn(zlibTest)
dependencies {
implementation(libs.test.junit)
implementation(libs.test.junit5)
implementation(libs.test.jimfs)
}
}
Expand Down
22 changes: 11 additions & 11 deletions okio/src/jvmTest/kotlin/okio/AsyncTimeoutTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import java.util.concurrent.LinkedBlockingDeque
import java.util.concurrent.TimeUnit
import okio.ByteString.Companion.of
import okio.TestUtil.bufferWithRandomSegmentLayout
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

/**
* This test uses four timeouts of varying durations: 250ms, 500ms, 750ms and
Expand All @@ -42,7 +42,7 @@ class AsyncTimeoutTest {
private val c = RecordingAsyncTimeout()
private val d = RecordingAsyncTimeout()

@Before
@BeforeEach
fun setUp() {
a.timeout(250, TimeUnit.MILLISECONDS)
b.timeout(500, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -154,7 +154,7 @@ class AsyncTimeoutTest {
fun reEnterAfterTimeout() {
a.timeout(1, TimeUnit.MILLISECONDS)
a.enter()
Assert.assertSame(a, timedOut.take())
Assertions.assertSame(a, timedOut.take())
assertTrue(a.exit())
a.enter()
assertFalse(a.exit())
Expand Down Expand Up @@ -345,7 +345,7 @@ class AsyncTimeoutTest {
* unexpected timeout because although the sink was making steady forward
* progress, doing it all as a single write caused a timeout.
*/
@Ignore("Flaky")
@Disabled("Flaky")
@Test
fun sinkSplitsLargeWrites() {
val data = ByteArray(512 * 1024)
Expand Down
8 changes: 4 additions & 4 deletions okio/src/jvmTest/kotlin/okio/AwaitSignalTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import java.util.concurrent.locks.Condition
import java.util.concurrent.locks.ReentrantLock
import kotlin.time.Duration.Companion.milliseconds
import okio.TestUtil.assumeNotWindows
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test

@Burst
class AwaitSignalTest(
Expand Down
10 changes: 5 additions & 5 deletions okio/src/jvmTest/kotlin/okio/BufferCursorKotlinTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
package okio

import app.cash.burst.Burst
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotSame
import kotlin.test.assertSame
import kotlin.test.assertTrue
import okio.Buffer.UnsafeCursor
import okio.TestUtil.deepCopy
import org.junit.Assume.assumeTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.Test

@Burst
class BufferCursorKotlinTest(
Expand Down
18 changes: 9 additions & 9 deletions okio/src/jvmTest/kotlin/okio/BufferCursorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import java.util.Arrays
import okio.ByteString.Companion.of
import okio.TestUtil.SEGMENT_SIZE
import okio.TestUtil.deepCopy
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.fail
import org.junit.Assume.assumeTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.Test

@Burst
class BufferCursorTest(
Expand Down Expand Up @@ -125,7 +125,7 @@ class BufferCursorTest(
try {
var lastOffset = cursor.offset
while (cursor.next().toLong() != -1L) {
Assert.assertTrue(cursor.offset > lastOffset)
Assertions.assertTrue(cursor.offset > lastOffset)
lastOffset = cursor.offset
}
assertEquals(buffer.size, cursor.offset)
Expand Down
2 changes: 1 addition & 1 deletion okio/src/jvmTest/kotlin/okio/BufferKotlinTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package okio
import assertk.assertThat
import assertk.assertions.isEqualTo
import kotlin.test.assertFailsWith
import org.junit.Test
import org.junit.jupiter.api.Test

class BufferKotlinTest {
@Test fun get() {
Expand Down
16 changes: 8 additions & 8 deletions okio/src/jvmTest/kotlin/okio/BufferTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import okio.TestUtil.SEGMENT_SIZE
import okio.TestUtil.bufferWithRandomSegmentLayout
import okio.TestUtil.segmentPoolByteCount
import okio.TestUtil.segmentSizes
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Test
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test

/**
* Tests solely for the behavior of Buffer's implementation. For generic BufferedSink or
Expand Down Expand Up @@ -450,8 +450,8 @@ class BufferTest {
fun equalsAndHashCode() {
val a = Buffer().writeUtf8("dog")
val b = Buffer().writeUtf8("hotdog")
Assert.assertNotEquals(a, b)
Assert.assertNotEquals(a.hashCode().toLong(), b.hashCode().toLong())
Assertions.assertNotEquals(a, b)
Assertions.assertNotEquals(a.hashCode().toLong(), b.hashCode().toLong())
b.readUtf8(3) // Leaves b containing 'dog'.
assertEquals(a, b)
assertEquals(a.hashCode().toLong(), b.hashCode().toLong())
Expand All @@ -468,8 +468,8 @@ class BufferTest {
assertEquals(a.hashCode().toLong(), b.hashCode().toLong())
data[data.size / 2]++ // Change a single byte.
val c = bufferWithRandomSegmentLayout(dice, data)
Assert.assertNotEquals(a, c)
Assert.assertNotEquals(a.hashCode().toLong(), c.hashCode().toLong())
Assertions.assertNotEquals(a, c)
Assertions.assertNotEquals(a.hashCode().toLong(), c.hashCode().toLong())
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions okio/src/jvmTest/kotlin/okio/BufferedSinkJavaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package okio

import java.io.IOException
import okio.TestUtil.SEGMENT_SIZE
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test

/**
* Tests solely for the behavior of RealBufferedSink's implementation. For generic
Expand Down
10 changes: 5 additions & 5 deletions okio/src/jvmTest/kotlin/okio/BufferedSinkTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import okio.ByteString.Companion.decodeHex
import okio.ByteString.Companion.encodeUtf8
import okio.TestUtil.SEGMENT_SIZE
import okio.TestUtil.segmentSizes
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test

@Burst
class BufferedSinkTest(
Expand Down Expand Up @@ -324,7 +324,7 @@ class BufferedSinkTest(
sink.writeDecimalLong(value).writeUtf8("zzz").flush()
val expected = java.lang.Long.toString(value) + "zzz"
val actual = data.readUtf8()
assertEquals("$value expected $expected but was $actual", actual, expected)
assertEquals(actual, expected, "$value expected $expected but was $actual")
}

@Test
Expand Down Expand Up @@ -370,6 +370,6 @@ class BufferedSinkTest(
sink.writeHexadecimalUnsignedLong(value).writeUtf8("zzz").flush()
val expected = String.format("%x", value) + "zzz"
val actual = data.readUtf8()
assertEquals("$value expected $expected but was $actual", actual, expected)
assertEquals(actual, expected, "$value expected $expected but was $actual")
}
}
6 changes: 3 additions & 3 deletions okio/src/jvmTest/kotlin/okio/BufferedSourceJavaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import java.io.EOFException
import java.io.IOException
import kotlin.text.Charsets.UTF_8
import okio.TestUtil.SEGMENT_SIZE
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test

/**
* Tests solely for the behavior of RealBufferedSource's implementation. For generic
Expand Down
16 changes: 8 additions & 8 deletions okio/src/jvmTest/kotlin/okio/BufferedSourceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import okio.TestUtil.assertByteArrayEquals
import okio.TestUtil.assertByteArraysEquals
import okio.TestUtil.randomBytes
import okio.TestUtil.segmentSizes
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Assume.assumeTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.Test

@Burst
class BufferedSourceTest(
Expand Down Expand Up @@ -1227,7 +1227,7 @@ class BufferedSourceTest(
sink.writeUtf8(s)
sink.emit()
val actual = source.readHexadecimalUnsignedLong()
assertEquals("$s --> $expected", expected, actual)
assertEquals(expected, actual, "$s --> $expected")
}

@Test
Expand Down Expand Up @@ -1289,7 +1289,7 @@ class BufferedSourceTest(
sink.writeUtf8("zzz")
sink.emit()
val actual = source.readDecimalLong()
assertEquals("$s --> $expected", expected, actual)
assertEquals(expected, actual, "$s --> $expected")
assertEquals("zzz", source.readUtf8())
}

Expand Down
4 changes: 2 additions & 2 deletions okio/src/jvmTest/kotlin/okio/ByteStringJavaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import okio.TestUtil.assertByteArraysEquals
import okio.TestUtil.assertEquivalent
import okio.TestUtil.makeSegments
import okio.TestUtil.reserialize
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

@Burst
class ByteStringJavaTest(
Expand Down
2 changes: 1 addition & 1 deletion okio/src/jvmTest/kotlin/okio/CipherSinkTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package okio

import app.cash.burst.Burst
import kotlin.random.Random
import org.junit.Test
import org.junit.jupiter.api.Test

@Burst
class CipherSinkTest(
Expand Down
2 changes: 1 addition & 1 deletion okio/src/jvmTest/kotlin/okio/CipherSourceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package okio

import app.cash.burst.Burst
import kotlin.random.Random
import org.junit.Test
import org.junit.jupiter.api.Test

@Burst
class CipherSourceTest(
Expand Down
8 changes: 4 additions & 4 deletions okio/src/jvmTest/kotlin/okio/ConstantTimeEqualsTimingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package okio

import okio.ByteString.Companion.toByteString
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

/**
* Statistical timing test for [ByteString.equals] with [constantTime]=true.
Expand Down Expand Up @@ -58,14 +58,14 @@ class ConstantTimeEqualsTimingTest {
val ctRatio =
if (ctMatch > ctMismatch) ctMatch.toDouble() / ctMismatch else ctMismatch.toDouble() / ctMatch
assertTrue(
"CT(match)=$ctMatch ns and CT(mismatch)=$ctMismatch ns differ by ${ctRatio}x (expected <3x)",
ctRatio < 3.0,
"CT(match)=$ctMatch ns and CT(mismatch)=$ctMismatch ns differ by ${ctRatio}x (expected <3x)",
)

// normal(mismatch) must be significantly faster than CT(mismatch): normal short-circuits at byte 0.
assertTrue(
"normal(mismatch)=$normalMismatch ns should be <2% of CT(mismatch)=$ctMismatch ns (short-circuit at byte 0)",
normalMismatch * 50L < ctMismatch,
"normal(mismatch)=$normalMismatch ns should be <2% of CT(mismatch)=$ctMismatch ns (short-circuit at byte 0)",
)
}

Expand Down
2 changes: 1 addition & 1 deletion okio/src/jvmTest/kotlin/okio/DeflateKotlinTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.util.zip.Deflater
import java.util.zip.Inflater
import kotlin.test.assertEquals
import okio.ByteString.Companion.decodeHex
import org.junit.Test
import org.junit.jupiter.api.Test

class DeflateKotlinTest {
@Test fun deflate() {
Expand Down
Loading
Loading