From 359891c01e812c382a19caa0a57214134b463c26 Mon Sep 17 00:00:00 2001 From: Graham Date: Wed, 10 Feb 2021 22:28:56 +0000 Subject: [PATCH] Convert all test objects to classes This is required for IDEA to display the run test icon in the gutter. Signed-off-by: Graham --- .../openrs2/buffer/ByteBufExtensionsTest.kt | 2 +- .../openrs2/cache/BufferedFileChannelTest.kt | 2 +- .../kotlin/org/openrs2/cache/DiskStoreTest.kt | 8 +- .../openrs2/cache/DiskStoreZipWriterTest.kt | 8 +- .../org/openrs2/cache/FlatFileStoreTest.kt | 10 +- .../kotlin/org/openrs2/cache/GroupTest.kt | 26 +-- .../org/openrs2/cache/Js5CompressionTest.kt | 10 +- .../kotlin/org/openrs2/cache/Js5IndexTest.kt | 188 +++++++++--------- .../org/openrs2/cache/Js5MasterIndexTest.kt | 162 +++++++-------- .../openrs2/cache/NamedEntryCollectionTest.kt | 2 +- .../kotlin/org/openrs2/cache/StoreTest.kt | 10 +- .../org/openrs2/cache/VersionTrailerTest.kt | 2 +- .../org/openrs2/crypto/IsaacRandomTest.kt | 40 ++-- .../test/kotlin/org/openrs2/crypto/RsaTest.kt | 76 +++---- .../org/openrs2/crypto/WhirlpoolTest.kt | 132 ++++++------ .../kotlin/org/openrs2/crypto/XteaTest.kt | 42 ++-- .../org/openrs2/db/BackoffStrategyTest.kt | 2 +- .../kotlin/org/openrs2/db/DatabaseTest.kt | 32 +-- .../org/openrs2/db/DeadlockDetectorTest.kt | 2 +- .../org/openrs2/protocol/Rs2DecoderTest.kt | 2 +- .../org/openrs2/protocol/Rs2EncoderTest.kt | 2 +- .../jaggrab/JaggrabRequestDecoderTest.kt | 2 +- .../jaggrab/JaggrabRequestEncoderTest.kt | 2 +- .../protocol/js5/Js5RequestDecoderTest.kt | 2 +- .../protocol/js5/Js5RequestEncoderTest.kt | 2 +- .../protocol/js5/Js5ResponseDecoderTest.kt | 2 +- .../protocol/js5/Js5ResponseEncoderTest.kt | 2 +- .../openrs2/protocol/js5/XorDecoderTest.kt | 2 +- .../openrs2/protocol/js5/XorEncoderTest.kt | 2 +- .../org/openrs2/util/StringUtilsTest.kt | 2 +- .../openrs2/util/charset/Cp1252CharsetTest.kt | 2 +- .../util/charset/ModifiedUtf8CharsetTest.kt | 2 +- .../util/collect/ForestDisjointSetTest.kt | 2 +- .../openrs2/util/collect/IterableUtilsTest.kt | 2 +- .../io/DeterministicJarOutputStreamTest.kt | 9 +- .../openrs2/util/io/SkipOutputStreamTest.kt | 2 +- 36 files changed, 413 insertions(+), 384 deletions(-) diff --git a/buffer/src/test/kotlin/org/openrs2/buffer/ByteBufExtensionsTest.kt b/buffer/src/test/kotlin/org/openrs2/buffer/ByteBufExtensionsTest.kt index 66e10a41..050ad750 100644 --- a/buffer/src/test/kotlin/org/openrs2/buffer/ByteBufExtensionsTest.kt +++ b/buffer/src/test/kotlin/org/openrs2/buffer/ByteBufExtensionsTest.kt @@ -7,7 +7,7 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertFalse -object ByteBufExtensionsTest { +class ByteBufExtensionsTest { @Test fun testWrappedBuffer() { wrappedBuffer(1, 2, 3).use { actual -> diff --git a/cache/src/test/kotlin/org/openrs2/cache/BufferedFileChannelTest.kt b/cache/src/test/kotlin/org/openrs2/cache/BufferedFileChannelTest.kt index 9aa09d5a..0ad0d4cc 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/BufferedFileChannelTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/BufferedFileChannelTest.kt @@ -17,7 +17,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object BufferedFileChannelTest { +class BufferedFileChannelTest { @Test fun testEmpty() { Jimfs.newFileSystem(Configuration.unix()).use { fs -> diff --git a/cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt b/cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt index 51b2f694..8a3bee7e 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt @@ -15,9 +15,7 @@ import kotlin.test.assertFailsWith import kotlin.test.assertFalse import kotlin.test.assertTrue -object DiskStoreTest { - private val ROOT = Path.of(DiskStoreTest::class.java.getResource("disk-store").toURI()) - +class DiskStoreTest { @Test fun testBounds() { readTest("empty") { store -> @@ -758,4 +756,8 @@ object DiskStoreTest { assertTrue(expected.recursiveEquals(actual)) } } + + private companion object { + private val ROOT = Path.of(DiskStoreTest::class.java.getResource("disk-store").toURI()) + } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt b/cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt index f7e90f53..b95d61e8 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/DiskStoreZipWriterTest.kt @@ -14,9 +14,7 @@ import kotlin.test.Test import kotlin.test.assertFailsWith import kotlin.test.assertTrue -object DiskStoreZipWriterTest { - private val ROOT = Path.of(DiskStoreZipWriterTest::class.java.getResource("zip").toURI()) - +class DiskStoreZipWriterTest { @Test fun testBounds() { DiskStoreZipWriter(ZipOutputStream(OutputStream.nullOutputStream())).use { store -> @@ -118,4 +116,8 @@ object DiskStoreZipWriterTest { assertTrue(ROOT.recursiveEquals(actual)) } } + + private companion object { + private val ROOT = Path.of(DiskStoreZipWriterTest::class.java.getResource("zip").toURI()) + } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/FlatFileStoreTest.kt b/cache/src/test/kotlin/org/openrs2/cache/FlatFileStoreTest.kt index 9759e181..b4b696e9 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/FlatFileStoreTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/FlatFileStoreTest.kt @@ -15,10 +15,7 @@ import kotlin.test.assertFailsWith import kotlin.test.assertFalse import kotlin.test.assertTrue -object FlatFileStoreTest { - private val IGNORE_GIT_EMPTY = { path: Path -> path.fileName.toString() != ".gitempty" } - private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("flat-file-store").toURI()) - +class FlatFileStoreTest { @Test fun testBounds() { readTest("empty") { store -> @@ -273,4 +270,9 @@ object FlatFileStoreTest { assertTrue(expected.recursiveEquals(actual, filter = IGNORE_GIT_EMPTY)) } } + + private companion object { + private val IGNORE_GIT_EMPTY = { path: Path -> path.fileName.toString() != ".gitempty" } + private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("flat-file-store").toURI()) + } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/GroupTest.kt b/cache/src/test/kotlin/org/openrs2/cache/GroupTest.kt index 014a4228..821f6350 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/GroupTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/GroupTest.kt @@ -10,18 +10,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object GroupTest { - private val index = Js5Index(Js5Protocol.ORIGINAL) - private val zeroFiles = index.createOrGet(0) - private val oneFile = index.createOrGet(1).apply { - createOrGet(1) - } - private val multipleFiles = index.createOrGet(2).apply { - createOrGet(0) - createOrGet(1) - createOrGet(3) - } - +class GroupTest { @Test fun testPackEmpty() { assertFailsWith { @@ -177,4 +166,17 @@ object GroupTest { expected.values.forEach(ByteBuf::release) } } + + private companion object { + private val index = Js5Index(Js5Protocol.ORIGINAL) + private val zeroFiles = index.createOrGet(0) + private val oneFile = index.createOrGet(1).apply { + createOrGet(1) + } + private val multipleFiles = index.createOrGet(2).apply { + createOrGet(0) + createOrGet(1) + createOrGet(3) + } + } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt b/cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt index fbeb61fb..571d91a6 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/Js5CompressionTest.kt @@ -13,10 +13,7 @@ import kotlin.test.assertFalse import kotlin.test.assertNotEquals import kotlin.test.assertTrue -object Js5CompressionTest { - private val KEY = XteaKey.fromHex("00112233445566778899AABBCCDDEEFF") - private val INVALID_KEY = XteaKey.fromHex("0123456789ABCDEF0123456789ABCDEF") - +class Js5CompressionTest { @Test fun testCompressNone() { read("none.dat").use { expected -> @@ -503,4 +500,9 @@ object Js5CompressionTest { return Unpooled.wrappedBuffer(input.readAllBytes()) } } + + private companion object { + private val KEY = XteaKey.fromHex("00112233445566778899AABBCCDDEEFF") + private val INVALID_KEY = XteaKey.fromHex("0123456789ABCDEF0123456789ABCDEF") + } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/Js5IndexTest.kt b/cache/src/test/kotlin/org/openrs2/cache/Js5IndexTest.kt index 85dd3aa6..7c250051 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/Js5IndexTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/Js5IndexTest.kt @@ -14,99 +14,7 @@ import kotlin.test.assertFalse import kotlin.test.assertNull import kotlin.test.assertTrue -object Js5IndexTest { - private val emptyIndex = Js5Index(Js5Protocol.ORIGINAL) - - private val versionedIndex = Js5Index(Js5Protocol.VERSIONED, version = 0x12345678) - - private val noFlagsIndex = Js5Index(Js5Protocol.ORIGINAL).apply { - val group0 = createOrGet(0) - group0.checksum = 0x01234567 - group0.version = 0 - group0.createOrGet(0) - - val group1 = createOrGet(1) - group1.checksum = 0x89ABCDEF.toInt() - group1.version = 10 - - val group2 = createOrGet(3) - group2.checksum = 0xAAAA5555.toInt() - group2.version = 20 - group2.createOrGet(1) - group2.createOrGet(3) - } - - private val namedIndex = Js5Index(Js5Protocol.ORIGINAL, hasNames = true).apply { - val group0 = createOrGet("hello") - group0.checksum = 0x01234567 - group0.version = 0x89ABCDEF.toInt() - group0.createOrGet("world") - } - - private val smartIndex = Js5Index(Js5Protocol.SMART).apply { - val group0 = createOrGet(0) - group0.checksum = 0x01234567 - group0.version = 0x89ABCDEF.toInt() - group0.createOrGet(0) - group0.createOrGet(100000) - - val group1 = createOrGet(100000) - group1.checksum = 0xAAAA5555.toInt() - group1.version = 0x5555AAAA - } - - private val digestIndex = Js5Index(Js5Protocol.ORIGINAL, hasDigests = true).apply { - val group = createOrGet(0) - group.checksum = 0x01234567 - group.version = 0x89ABCDEF.toInt() - group.digest = ByteBufUtil.decodeHexDump( - "19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" + - "3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3" - ) - } - - private val nullDigestIndex = Js5Index(Js5Protocol.ORIGINAL, hasDigests = true).apply { - val group = createOrGet(0) - group.checksum = 0x01234567 - group.version = 0x89ABCDEF.toInt() - group.digest = null - } - - private val lengthsIndex = Js5Index(Js5Protocol.ORIGINAL, hasLengths = true).apply { - val group = createOrGet(0) - group.checksum = 0x01234567 - group.version = 0x89ABCDEF.toInt() - group.length = 1000 - group.uncompressedLength = 2000 - } - - private val uncompressedChecksumIndex = Js5Index(Js5Protocol.ORIGINAL, hasUncompressedChecksums = true).apply { - val group = createOrGet(0) - group.checksum = 0x01234567 - group.version = 0x89ABCDEF.toInt() - group.uncompressedChecksum = 0xAAAA5555.toInt() - } - - private val allFlagsIndex = Js5Index( - Js5Protocol.ORIGINAL, - hasNames = true, - hasDigests = true, - hasLengths = true, - hasUncompressedChecksums = true - ).apply { - val group = createOrGet("hello") - group.checksum = 0x01234567 - group.version = 0x89ABCDEF.toInt() - group.digest = ByteBufUtil.decodeHexDump( - "19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" + - "3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3" - ) - group.length = 1000 - group.uncompressedLength = 2000 - group.uncompressedChecksum = 0xAAAA5555.toInt() - group.createOrGet("world") - } - +class Js5IndexTest { @Test fun testReadEmpty() { read("empty.dat").use { buf -> @@ -412,4 +320,98 @@ object Js5IndexTest { return Unpooled.wrappedBuffer(input.readAllBytes()) } } + + private companion object { + private val emptyIndex = Js5Index(Js5Protocol.ORIGINAL) + + private val versionedIndex = Js5Index(Js5Protocol.VERSIONED, version = 0x12345678) + + private val noFlagsIndex = Js5Index(Js5Protocol.ORIGINAL).apply { + val group0 = createOrGet(0) + group0.checksum = 0x01234567 + group0.version = 0 + group0.createOrGet(0) + + val group1 = createOrGet(1) + group1.checksum = 0x89ABCDEF.toInt() + group1.version = 10 + + val group2 = createOrGet(3) + group2.checksum = 0xAAAA5555.toInt() + group2.version = 20 + group2.createOrGet(1) + group2.createOrGet(3) + } + + private val namedIndex = Js5Index(Js5Protocol.ORIGINAL, hasNames = true).apply { + val group0 = createOrGet("hello") + group0.checksum = 0x01234567 + group0.version = 0x89ABCDEF.toInt() + group0.createOrGet("world") + } + + private val smartIndex = Js5Index(Js5Protocol.SMART).apply { + val group0 = createOrGet(0) + group0.checksum = 0x01234567 + group0.version = 0x89ABCDEF.toInt() + group0.createOrGet(0) + group0.createOrGet(100000) + + val group1 = createOrGet(100000) + group1.checksum = 0xAAAA5555.toInt() + group1.version = 0x5555AAAA + } + + private val digestIndex = Js5Index(Js5Protocol.ORIGINAL, hasDigests = true).apply { + val group = createOrGet(0) + group.checksum = 0x01234567 + group.version = 0x89ABCDEF.toInt() + group.digest = ByteBufUtil.decodeHexDump( + "19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" + + "3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3" + ) + } + + private val nullDigestIndex = Js5Index(Js5Protocol.ORIGINAL, hasDigests = true).apply { + val group = createOrGet(0) + group.checksum = 0x01234567 + group.version = 0x89ABCDEF.toInt() + group.digest = null + } + + private val lengthsIndex = Js5Index(Js5Protocol.ORIGINAL, hasLengths = true).apply { + val group = createOrGet(0) + group.checksum = 0x01234567 + group.version = 0x89ABCDEF.toInt() + group.length = 1000 + group.uncompressedLength = 2000 + } + + private val uncompressedChecksumIndex = Js5Index(Js5Protocol.ORIGINAL, hasUncompressedChecksums = true).apply { + val group = createOrGet(0) + group.checksum = 0x01234567 + group.version = 0x89ABCDEF.toInt() + group.uncompressedChecksum = 0xAAAA5555.toInt() + } + + private val allFlagsIndex = Js5Index( + Js5Protocol.ORIGINAL, + hasNames = true, + hasDigests = true, + hasLengths = true, + hasUncompressedChecksums = true + ).apply { + val group = createOrGet("hello") + group.checksum = 0x01234567 + group.version = 0x89ABCDEF.toInt() + group.digest = ByteBufUtil.decodeHexDump( + "19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" + + "3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3" + ) + group.length = 1000 + group.uncompressedLength = 2000 + group.uncompressedChecksum = 0xAAAA5555.toInt() + group.createOrGet("world") + } + } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt b/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt index ac90e2d4..d7e5ad55 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt @@ -10,86 +10,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object Js5MasterIndexTest { - private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("master-index").toURI()) - private val PRIVATE_KEY = Rsa.readPrivateKey(ROOT.resolve("private.key")) - private val PUBLIC_KEY = Rsa.readPublicKey(ROOT.resolve("public.key")) - - private val encodedOriginal = ByteBufUtil.decodeHexDump("000000010000000300000005") - private val decodedOriginal = Js5MasterIndex( - MasterIndexFormat.ORIGINAL, - mutableListOf( - Js5MasterIndex.Entry(0, 1, null), - Js5MasterIndex.Entry(0, 3, null), - Js5MasterIndex.Entry(0, 5, null) - ) - ) - - private val encodedVersioned = ByteBufUtil.decodeHexDump("000000010000000000000003000000020000000500000004") - private val decodedVersioned = Js5MasterIndex( - MasterIndexFormat.VERSIONED, - mutableListOf( - Js5MasterIndex.Entry(0, 1, null), - Js5MasterIndex.Entry(2, 3, null), - Js5MasterIndex.Entry(4, 5, null) - ) - ) - - private val encodedWhirlpool = ByteBufUtil.decodeHexDump( - "01" + - "89abcdef" + - "01234567" + - "0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" + - "4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" + - "0a" + - "ee8f66a2ce0b07de4d2b792eed26ae7a6c307b763891d085c63ea55b4c003bc0" + - "b3ecb77cc1a8f9ccd53c405b3264e598820b4940f630ff079a9feb950f639671" - ) - private val decodedWhirlpool = Js5MasterIndex( - MasterIndexFormat.WHIRLPOOL, - mutableListOf( - Js5MasterIndex.Entry( - 0x01234567, 0x89ABCDEF.toInt(), ByteBufUtil.decodeHexDump( - "0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" + - "4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" - ) - ) - ) - ) - - private val encodedWhirlpoolNullDigest = ByteBufUtil.decodeHexDump( - "01" + - "89abcdef" + - "01234567" + - "0000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000000" + - "0a" + - "4a0e22540fb0a9bc06fe84bfb35f9281ba9fbd30288c3375c508ad741c4d4491" + - "8a65765bc2dce9d67029be79bd544f96055a41d725c080bc5b85a48b5aae6e4d" - ) - private val decodedWhirlpoolNullDigest = Js5MasterIndex( - MasterIndexFormat.WHIRLPOOL, - mutableListOf( - Js5MasterIndex.Entry(0x01234567, 0x89ABCDEF.toInt(), null) - ) - ) - - private val encodedSigned = ByteBufUtil.decodeHexDump( - "01" + - "89abcdef" + - "01234567" + - "0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" + - "4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" + - "2134b1e637d4c9f3b7bdd446ad40cedb6d824cfb48f937ae0d6e2ba3977881ea" + - "ed02adae179ed89cea56e98772186bb569bb24a4951e441716df0d5d7199c088" + - "28974d43c3644e74bf29ec1435e425f6cb05aca14a84163c5b46b6e6a9362f22" + - "4f69f4a5888b3fe7aec0141da25b17c7f65069eed59f3be134fa1ade4e191b41" + - "d561447446cd1cc4d11e6499c49e00066173908491d8d2ff282aefa86e6c6b15" + - "dceb437d0436b6195ef60d4128e1e0184bf6929b73abd1a8aa2a047e3cb90d03" + - "57707ce3f4f5a7af8471eda5c0c0748454a9cbb48c25ebe4e7fd94e3881b6461" + - "d06e2bce128dc96decb537b8e9611591d445d7dfd3701d25ac05f8d091581aef" - ) - +class Js5MasterIndexTest { @Test fun testCreateOriginal() { val index = Store.open(ROOT.resolve("original")).use { store -> @@ -320,4 +241,85 @@ object Js5MasterIndexTest { } } } + + private companion object { + private val ROOT = Path.of(FlatFileStoreTest::class.java.getResource("master-index").toURI()) + private val PRIVATE_KEY = Rsa.readPrivateKey(ROOT.resolve("private.key")) + private val PUBLIC_KEY = Rsa.readPublicKey(ROOT.resolve("public.key")) + + private val encodedOriginal = ByteBufUtil.decodeHexDump("000000010000000300000005") + private val decodedOriginal = Js5MasterIndex( + MasterIndexFormat.ORIGINAL, + mutableListOf( + Js5MasterIndex.Entry(0, 1, null), + Js5MasterIndex.Entry(0, 3, null), + Js5MasterIndex.Entry(0, 5, null) + ) + ) + + private val encodedVersioned = ByteBufUtil.decodeHexDump("000000010000000000000003000000020000000500000004") + private val decodedVersioned = Js5MasterIndex( + MasterIndexFormat.VERSIONED, + mutableListOf( + Js5MasterIndex.Entry(0, 1, null), + Js5MasterIndex.Entry(2, 3, null), + Js5MasterIndex.Entry(4, 5, null) + ) + ) + + private val encodedWhirlpool = ByteBufUtil.decodeHexDump( + "01" + + "89abcdef" + + "01234567" + + "0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" + + "4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" + + "0a" + + "ee8f66a2ce0b07de4d2b792eed26ae7a6c307b763891d085c63ea55b4c003bc0" + + "b3ecb77cc1a8f9ccd53c405b3264e598820b4940f630ff079a9feb950f639671" + ) + private val decodedWhirlpool = Js5MasterIndex( + MasterIndexFormat.WHIRLPOOL, + mutableListOf( + Js5MasterIndex.Entry( + 0x01234567, 0x89ABCDEF.toInt(), ByteBufUtil.decodeHexDump( + "0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" + + "4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" + ) + ) + ) + ) + + private val encodedWhirlpoolNullDigest = ByteBufUtil.decodeHexDump( + "01" + + "89abcdef" + + "01234567" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000" + + "0a" + + "4a0e22540fb0a9bc06fe84bfb35f9281ba9fbd30288c3375c508ad741c4d4491" + + "8a65765bc2dce9d67029be79bd544f96055a41d725c080bc5b85a48b5aae6e4d" + ) + private val decodedWhirlpoolNullDigest = Js5MasterIndex( + MasterIndexFormat.WHIRLPOOL, + mutableListOf( + Js5MasterIndex.Entry(0x01234567, 0x89ABCDEF.toInt(), null) + ) + ) + + private val encodedSigned = ByteBufUtil.decodeHexDump( + "01" + + "89abcdef" + + "01234567" + + "0e1a2b93c80a41c7ad2a985dff707a6a8ff82e229cbc468f04191198920955a1" + + "4b3d7eab77a17faf99208dee5b44afb789962ad79f230b3b59106a0af892219c" + + "2134b1e637d4c9f3b7bdd446ad40cedb6d824cfb48f937ae0d6e2ba3977881ea" + + "ed02adae179ed89cea56e98772186bb569bb24a4951e441716df0d5d7199c088" + + "28974d43c3644e74bf29ec1435e425f6cb05aca14a84163c5b46b6e6a9362f22" + + "4f69f4a5888b3fe7aec0141da25b17c7f65069eed59f3be134fa1ade4e191b41" + + "d561447446cd1cc4d11e6499c49e00066173908491d8d2ff282aefa86e6c6b15" + + "dceb437d0436b6195ef60d4128e1e0184bf6929b73abd1a8aa2a047e3cb90d03" + + "57707ce3f4f5a7af8471eda5c0c0748454a9cbb48c25ebe4e7fd94e3881b6461" + + "d06e2bce128dc96decb537b8e9611591d445d7dfd3701d25ac05f8d091581aef" + ) + } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/NamedEntryCollectionTest.kt b/cache/src/test/kotlin/org/openrs2/cache/NamedEntryCollectionTest.kt index feb38ff7..897feaf7 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/NamedEntryCollectionTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/NamedEntryCollectionTest.kt @@ -8,7 +8,7 @@ import kotlin.test.assertFalse import kotlin.test.assertNull import kotlin.test.assertTrue -object NamedEntryCollectionTest { +class NamedEntryCollectionTest { private class TestEntry( parent: NamedEntryCollection, override val id: Int diff --git a/cache/src/test/kotlin/org/openrs2/cache/StoreTest.kt b/cache/src/test/kotlin/org/openrs2/cache/StoreTest.kt index 56698f3f..118133a8 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/StoreTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/StoreTest.kt @@ -4,10 +4,7 @@ import java.nio.file.Path import kotlin.test.Test import kotlin.test.assertTrue -object StoreTest { - private val DISK_ROOT = Path.of(StoreTest::class.java.getResource("disk-store/empty").toURI()) - private val FLAT_FILE_ROOT = Path.of(StoreTest::class.java.getResource("flat-file-store/empty").toURI()) - +class StoreTest { @Test fun testOpen() { Store.open(DISK_ROOT).use { store -> @@ -18,4 +15,9 @@ object StoreTest { assertTrue(store is FlatFileStore) } } + + private companion object { + private val DISK_ROOT = Path.of(StoreTest::class.java.getResource("disk-store/empty").toURI()) + private val FLAT_FILE_ROOT = Path.of(StoreTest::class.java.getResource("flat-file-store/empty").toURI()) + } } diff --git a/cache/src/test/kotlin/org/openrs2/cache/VersionTrailerTest.kt b/cache/src/test/kotlin/org/openrs2/cache/VersionTrailerTest.kt index 42de407b..300c4575 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/VersionTrailerTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/VersionTrailerTest.kt @@ -7,7 +7,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull -object VersionTrailerTest { +class VersionTrailerTest { @Test fun testStrip() { assertNull(VersionTrailer.strip(Unpooled.EMPTY_BUFFER)) diff --git a/crypto/src/test/kotlin/org/openrs2/crypto/IsaacRandomTest.kt b/crypto/src/test/kotlin/org/openrs2/crypto/IsaacRandomTest.kt index 9a2fa0f2..e59d03fb 100644 --- a/crypto/src/test/kotlin/org/openrs2/crypto/IsaacRandomTest.kt +++ b/crypto/src/test/kotlin/org/openrs2/crypto/IsaacRandomTest.kt @@ -5,16 +5,7 @@ import java.nio.ByteOrder import kotlin.test.Test import kotlin.test.assertEquals -object IsaacRandomTest { - // test vector from https://burtleburtle.net/bob/rand/randvect.txt - private val ZERO_SEED_VECTOR = readVector("randvect.txt") - - // generated by changing randinit(1) to randinit(0) in readable.c - private val NO_SEED_VECTOR = readVector("noseedvect.txt") - - // generated with https://burtleburtle.net/bob/c/randtest.c - private val SEED_VECTOR = readVector("seedvect.txt") - +class IsaacRandomTest { @Test fun testZeroSeed() { val random = IsaacRandom(IntArray(256)) @@ -58,18 +49,29 @@ object IsaacRandomTest { } } - private fun readVector(file: String): IntArray { - val input = IsaacRandomTest::class.java.getResourceAsStream("isaac/$file") - return input.bufferedReader().useLines { lines -> - val elements = mutableListOf() + private companion object { + // test vector from https://burtleburtle.net/bob/rand/randvect.txt + private val ZERO_SEED_VECTOR = readVector("randvect.txt") + + // generated by changing randinit(1) to randinit(0) in readable.c + private val NO_SEED_VECTOR = readVector("noseedvect.txt") - for (line in lines) { - for (i in line.indices step 8) { - elements += Integer.parseUnsignedInt(line, i, i + 8, 16) + // generated with https://burtleburtle.net/bob/c/randtest.c + private val SEED_VECTOR = readVector("seedvect.txt") + + private fun readVector(file: String): IntArray { + val input = IsaacRandomTest::class.java.getResourceAsStream("isaac/$file") + return input.bufferedReader().useLines { lines -> + val elements = mutableListOf() + + for (line in lines) { + for (i in line.indices step 8) { + elements += Integer.parseUnsignedInt(line, i, i + 8, 16) + } } - } - elements.toIntArray() + elements.toIntArray() + } } } } diff --git a/crypto/src/test/kotlin/org/openrs2/crypto/RsaTest.kt b/crypto/src/test/kotlin/org/openrs2/crypto/RsaTest.kt index aefe6d28..c59db86a 100644 --- a/crypto/src/test/kotlin/org/openrs2/crypto/RsaTest.kt +++ b/crypto/src/test/kotlin/org/openrs2/crypto/RsaTest.kt @@ -15,37 +15,7 @@ import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue -object RsaTest { - private const val ALLOW_UNSAFE_MOD = "org.bouncycastle.rsa.allow_unsafe_mod" - - // example data from https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Example - private val PUBLIC_KEY = allowUnsafeMod { RSAKeyParameters(false, BigInteger("3233"), BigInteger("17")) } - private val PRIVATE_KEY = allowUnsafeMod { RSAKeyParameters(true, BigInteger("3233"), BigInteger("413")) } - private val PRIVATE_KEY_CRT = allowUnsafeMod { - RSAPrivateCrtKeyParameters( - BigInteger("3233"), // modulus - BigInteger("17"), // public exponent - BigInteger("413"), // private exponent - BigInteger("61"), // p - BigInteger("53"), // q - BigInteger("53"), // dP - BigInteger("49"), // dQ - BigInteger("38") // qInv - ) - } - - private val PUBLIC_KEY_PEM = listOf( - "-----BEGIN PUBLIC KEY-----", - "MBswDQYJKoZIhvcNAQEBBQADCgAwBwICDKECARE=", - "-----END PUBLIC KEY-----" - ) - private val PRIVATE_KEY_PEM = listOf( - "-----BEGIN PRIVATE KEY-----", - "MDMCAQAwDQYJKoZIhvcNAQEBBQAEHzAdAgEAAgIMoQIBEQICAZ0CAT0CATUCATUC", - "ATECASY=", - "-----END PRIVATE KEY-----" - ) - +class RsaTest { @Test fun testGenerateKeyPair() { val (public, private) = Rsa.generateKeyPair(Rsa.CLIENT_KEY_LENGTH) @@ -160,12 +130,44 @@ object RsaTest { assertEquals(PUBLIC_KEY.exponent, public.exponent) } - private fun allowUnsafeMod(f: () -> T): T { - Properties.setThreadOverride(ALLOW_UNSAFE_MOD, true) - try { - return f() - } finally { - Properties.setThreadOverride(ALLOW_UNSAFE_MOD, false) + private companion object { + private const val ALLOW_UNSAFE_MOD = "org.bouncycastle.rsa.allow_unsafe_mod" + + // example data from https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Example + private val PUBLIC_KEY = allowUnsafeMod { RSAKeyParameters(false, BigInteger("3233"), BigInteger("17")) } + private val PRIVATE_KEY = allowUnsafeMod { RSAKeyParameters(true, BigInteger("3233"), BigInteger("413")) } + private val PRIVATE_KEY_CRT = allowUnsafeMod { + RSAPrivateCrtKeyParameters( + BigInteger("3233"), // modulus + BigInteger("17"), // public exponent + BigInteger("413"), // private exponent + BigInteger("61"), // p + BigInteger("53"), // q + BigInteger("53"), // dP + BigInteger("49"), // dQ + BigInteger("38") // qInv + ) + } + + private val PUBLIC_KEY_PEM = listOf( + "-----BEGIN PUBLIC KEY-----", + "MBswDQYJKoZIhvcNAQEBBQADCgAwBwICDKECARE=", + "-----END PUBLIC KEY-----" + ) + private val PRIVATE_KEY_PEM = listOf( + "-----BEGIN PRIVATE KEY-----", + "MDMCAQAwDQYJKoZIhvcNAQEBBQAEHzAdAgEAAgIMoQIBEQICAZ0CAT0CATUCATUC", + "ATECASY=", + "-----END PRIVATE KEY-----" + ) + + private fun allowUnsafeMod(f: () -> T): T { + Properties.setThreadOverride(ALLOW_UNSAFE_MOD, true) + try { + return f() + } finally { + Properties.setThreadOverride(ALLOW_UNSAFE_MOD, false) + } } } } diff --git a/crypto/src/test/kotlin/org/openrs2/crypto/WhirlpoolTest.kt b/crypto/src/test/kotlin/org/openrs2/crypto/WhirlpoolTest.kt index ba877c76..243cd53e 100644 --- a/crypto/src/test/kotlin/org/openrs2/crypto/WhirlpoolTest.kt +++ b/crypto/src/test/kotlin/org/openrs2/crypto/WhirlpoolTest.kt @@ -10,76 +10,12 @@ import kotlin.streams.toList import kotlin.test.Test import kotlin.test.assertFailsWith -object WhirlpoolTest { +class WhirlpoolTest { private class IsoTestVector(input: String, expected: String) { val input = input.toByteArray(Charsets.US_ASCII) val expected: ByteArray = ByteBufUtil.decodeHexDump(expected) } - private val ISO_TEST_VECTORS = listOf( - IsoTestVector( - "", - "19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" + - "3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3" - ), - IsoTestVector( - "a", - "8ACA2602792AEC6F11A67206531FB7D7F0DFF59413145E6973C45001D0087B42" + - "D11BC645413AEFF63A42391A39145A591A92200D560195E53B478584FDAE231A" - ), - IsoTestVector( - "abc", - "4E2448A4C6F486BB16B6562C73B4020BF3043E3A731BCE721AE1B303D97E6D4C" + - "7181EEBDB6C57E277D0E34957114CBD6C797FC9D95D8B582D225292076D4EEF5" - ), - IsoTestVector( - "message digest", - "378C84A4126E2DC6E56DCC7458377AAC838D00032230F53CE1F5700C0FFB4D3B" + - "8421557659EF55C106B4B52AC5A4AAA692ED920052838F3362E86DBD37A8903E" - ), - IsoTestVector( - "abcdefghijklmnopqrstuvwxyz", - "F1D754662636FFE92C82EBB9212A484A8D38631EAD4238F5442EE13B8054E41B" + - "08BF2A9251C30B6A0B8AAE86177AB4A6F68F673E7207865D5D9819A3DBA4EB3B" - ), - IsoTestVector( - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "DC37E008CF9EE69BF11F00ED9ABA26901DD7C28CDEC066CC6AF42E40F82F3A1E" + - "08EBA26629129D8FB7CB57211B9281A65517CC879D7B962142C65F5A7AF01467" - ), - IsoTestVector( - "1234567890".repeat(8), - "466EF18BABB0154D25B9D38A6414F5C08784372BCCB204D6549C4AFADB601429" + - "4D5BD8DF2A6C44E538CD047B2681A51A2C60481E88C5A20B2C2A80CF3A9A083B" - ), - IsoTestVector( - "abcdbcdecdefdefgefghfghighijhijk", - "2A987EA40F917061F5D6F0A0E4644F488A7A5A52DEEE656207C562F988E95C69" + - "16BDC8031BC5BE1B7B947639FE050B56939BAAA0ADFF9AE6745B7B181C3BE3FD" - ), - IsoTestVector( - "a".repeat(1000000), - "0C99005BEB57EFF50A7CF005560DDF5D29057FD86B20BFD62DECA0F1CCEA4AF5" + - "1FC15490EDDC47AF32BB2B66C34FF9AD8C6008AD677F77126953B226E4ED8B01" - ) - ) - - private val NESSIE_ZERO_VECTORS = readVectors("nessie-zero-vectors.txt") - private val NESSIE_ONE_VECTORS = readVectors("nessie-one-vectors.txt") - private val QUICK_BROWN_FOX = ByteBufUtil.decodeHexDump( - "B97DE512E91E3828B40D2B0FDCE9CEB3C4A71F9BEA8D88E75C4FA854DF36725F" + - "D2B52EB6544EDCACD6F8BEDDFEA403CB55AE31F03AD62A5EF54E42EE82C3FB35" - ) - - private fun readVectors(file: String): List { - val input = WhirlpoolTest::class.java.getResourceAsStream("whirlpool/$file") - return input.bufferedReader().use { reader -> - reader.lines() - .map(ByteBufUtil::decodeHexDump) - .toList() - } - } - @Test fun testIsoVectors() { for (vector in ISO_TEST_VECTORS) { @@ -163,4 +99,70 @@ object WhirlpoolTest { Unpooled.EMPTY_BUFFER.whirlpool(0, 1) } } + + private companion object { + private val ISO_TEST_VECTORS = listOf( + IsoTestVector( + "", + "19FA61D75522A4669B44E39C1D2E1726C530232130D407F89AFEE0964997F7A7" + + "3E83BE698B288FEBCF88E3E03C4F0757EA8964E59B63D93708B138CC42A66EB3" + ), + IsoTestVector( + "a", + "8ACA2602792AEC6F11A67206531FB7D7F0DFF59413145E6973C45001D0087B42" + + "D11BC645413AEFF63A42391A39145A591A92200D560195E53B478584FDAE231A" + ), + IsoTestVector( + "abc", + "4E2448A4C6F486BB16B6562C73B4020BF3043E3A731BCE721AE1B303D97E6D4C" + + "7181EEBDB6C57E277D0E34957114CBD6C797FC9D95D8B582D225292076D4EEF5" + ), + IsoTestVector( + "message digest", + "378C84A4126E2DC6E56DCC7458377AAC838D00032230F53CE1F5700C0FFB4D3B" + + "8421557659EF55C106B4B52AC5A4AAA692ED920052838F3362E86DBD37A8903E" + ), + IsoTestVector( + "abcdefghijklmnopqrstuvwxyz", + "F1D754662636FFE92C82EBB9212A484A8D38631EAD4238F5442EE13B8054E41B" + + "08BF2A9251C30B6A0B8AAE86177AB4A6F68F673E7207865D5D9819A3DBA4EB3B" + ), + IsoTestVector( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "DC37E008CF9EE69BF11F00ED9ABA26901DD7C28CDEC066CC6AF42E40F82F3A1E" + + "08EBA26629129D8FB7CB57211B9281A65517CC879D7B962142C65F5A7AF01467" + ), + IsoTestVector( + "1234567890".repeat(8), + "466EF18BABB0154D25B9D38A6414F5C08784372BCCB204D6549C4AFADB601429" + + "4D5BD8DF2A6C44E538CD047B2681A51A2C60481E88C5A20B2C2A80CF3A9A083B" + ), + IsoTestVector( + "abcdbcdecdefdefgefghfghighijhijk", + "2A987EA40F917061F5D6F0A0E4644F488A7A5A52DEEE656207C562F988E95C69" + + "16BDC8031BC5BE1B7B947639FE050B56939BAAA0ADFF9AE6745B7B181C3BE3FD" + ), + IsoTestVector( + "a".repeat(1000000), + "0C99005BEB57EFF50A7CF005560DDF5D29057FD86B20BFD62DECA0F1CCEA4AF5" + + "1FC15490EDDC47AF32BB2B66C34FF9AD8C6008AD677F77126953B226E4ED8B01" + ) + ) + + private val NESSIE_ZERO_VECTORS = readVectors("nessie-zero-vectors.txt") + private val NESSIE_ONE_VECTORS = readVectors("nessie-one-vectors.txt") + private val QUICK_BROWN_FOX = ByteBufUtil.decodeHexDump( + "B97DE512E91E3828B40D2B0FDCE9CEB3C4A71F9BEA8D88E75C4FA854DF36725F" + + "D2B52EB6544EDCACD6F8BEDDFEA403CB55AE31F03AD62A5EF54E42EE82C3FB35" + ) + + private fun readVectors(file: String): List { + val input = WhirlpoolTest::class.java.getResourceAsStream("whirlpool/$file") + return input.bufferedReader().use { reader -> + reader.lines() + .map(ByteBufUtil::decodeHexDump) + .toList() + } + } + } } diff --git a/crypto/src/test/kotlin/org/openrs2/crypto/XteaTest.kt b/crypto/src/test/kotlin/org/openrs2/crypto/XteaTest.kt index add5a41c..bbdbc140 100644 --- a/crypto/src/test/kotlin/org/openrs2/crypto/XteaTest.kt +++ b/crypto/src/test/kotlin/org/openrs2/crypto/XteaTest.kt @@ -6,32 +6,13 @@ import org.openrs2.buffer.use import kotlin.test.Test import kotlin.test.assertEquals -object XteaTest { +class XteaTest { private class TestVector(key: String, plaintext: String, ciphertext: String) { val key = XteaKey.fromHex(key) val plaintext: ByteArray = ByteBufUtil.decodeHexDump(plaintext) val ciphertext: ByteArray = ByteBufUtil.decodeHexDump(ciphertext) } - private val TEST_VECTORS = listOf( - // empty - TestVector("00000000000000000000000000000000", "", ""), - - // standard single block test vectors - TestVector("000102030405060708090a0b0c0d0e0f", "4142434445464748", "497df3d072612cb5"), - TestVector("000102030405060708090a0b0c0d0e0f", "4141414141414141", "e78f2d13744341d8"), - TestVector("000102030405060708090a0b0c0d0e0f", "5a5b6e278948d77f", "4141414141414141"), - TestVector("00000000000000000000000000000000", "4142434445464748", "a0390589f8b8efa5"), - TestVector("00000000000000000000000000000000", "4141414141414141", "ed23375a821a8c2d"), - TestVector("00000000000000000000000000000000", "70e1225d6e4e7655", "4141414141414141"), - - // two blocks - TestVector( - "00000000000000000000000000000000", "70e1225d6e4e76554141414141414141", - "4141414141414141ed23375a821a8c2d" - ) - ) - @Test fun testEncrypt() { for (vector in TEST_VECTORS) { @@ -71,4 +52,25 @@ object XteaTest { } } } + + private companion object { + private val TEST_VECTORS = listOf( + // empty + TestVector("00000000000000000000000000000000", "", ""), + + // standard single block test vectors + TestVector("000102030405060708090a0b0c0d0e0f", "4142434445464748", "497df3d072612cb5"), + TestVector("000102030405060708090a0b0c0d0e0f", "4141414141414141", "e78f2d13744341d8"), + TestVector("000102030405060708090a0b0c0d0e0f", "5a5b6e278948d77f", "4141414141414141"), + TestVector("00000000000000000000000000000000", "4142434445464748", "a0390589f8b8efa5"), + TestVector("00000000000000000000000000000000", "4141414141414141", "ed23375a821a8c2d"), + TestVector("00000000000000000000000000000000", "70e1225d6e4e7655", "4141414141414141"), + + // two blocks + TestVector( + "00000000000000000000000000000000", "70e1225d6e4e76554141414141414141", + "4141414141414141ed23375a821a8c2d" + ) + ) + } } diff --git a/db/src/test/kotlin/org/openrs2/db/BackoffStrategyTest.kt b/db/src/test/kotlin/org/openrs2/db/BackoffStrategyTest.kt index 55b80173..2b4c9c31 100644 --- a/db/src/test/kotlin/org/openrs2/db/BackoffStrategyTest.kt +++ b/db/src/test/kotlin/org/openrs2/db/BackoffStrategyTest.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object BackoffStrategyTest { +class BackoffStrategyTest { @Test fun testFixedBackoff() { val strategy = FixedBackoffStrategy(1000) diff --git a/db/src/test/kotlin/org/openrs2/db/DatabaseTest.kt b/db/src/test/kotlin/org/openrs2/db/DatabaseTest.kt index 39ceb15c..d32863a4 100644 --- a/db/src/test/kotlin/org/openrs2/db/DatabaseTest.kt +++ b/db/src/test/kotlin/org/openrs2/db/DatabaseTest.kt @@ -10,7 +10,7 @@ import kotlin.test.assertFailsWith import kotlin.test.assertTrue @ExperimentalCoroutinesApi -object DatabaseTest { +class DatabaseTest { private class TestException : Exception { constructor() : super() constructor(cause: Throwable) : super(cause) @@ -19,20 +19,6 @@ object DatabaseTest { private class DeadlockException : SQLException(null, null, 40001) private class NonDeadlockException : SQLException() - private const val DELAY = 10L - private const val ATTEMPTS = 5 - - private val dataSource = JdbcDataSource().apply { - setUrl("jdbc:h2:mem:") - } - - private val database = Database( - dataSource, - deadlockDetector = H2DeadlockDetector, - backoffStrategy = FixedBackoffStrategy(DELAY), - attempts = ATTEMPTS - ) - @Test fun testBounds() { assertFailsWith { @@ -182,4 +168,20 @@ object DatabaseTest { assertEquals(1, attempts) } + + private companion object { + private const val DELAY = 10L + private const val ATTEMPTS = 5 + + private val dataSource = JdbcDataSource().apply { + setUrl("jdbc:h2:mem:") + } + + private val database = Database( + dataSource, + deadlockDetector = H2DeadlockDetector, + backoffStrategy = FixedBackoffStrategy(DELAY), + attempts = ATTEMPTS + ) + } } diff --git a/db/src/test/kotlin/org/openrs2/db/DeadlockDetectorTest.kt b/db/src/test/kotlin/org/openrs2/db/DeadlockDetectorTest.kt index 24cccc22..ee2d008a 100644 --- a/db/src/test/kotlin/org/openrs2/db/DeadlockDetectorTest.kt +++ b/db/src/test/kotlin/org/openrs2/db/DeadlockDetectorTest.kt @@ -5,7 +5,7 @@ import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue -object DeadlockDetectorTest { +class DeadlockDetectorTest { @Test fun testDefault() { assertTrue(DefaultDeadlockDetector.isDeadlock(SQLException())) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/Rs2DecoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/Rs2DecoderTest.kt index 915e0b9f..e24deb86 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/Rs2DecoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/Rs2DecoderTest.kt @@ -8,7 +8,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object Rs2DecoderTest { +class Rs2DecoderTest { @Test fun testDecode() { testDecode(byteArrayOf(0, 0x11, 0x22, 0x33, 0x44), FixedPacket(0x11223344)) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/Rs2EncoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/Rs2EncoderTest.kt index d69985f7..2914fb9b 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/Rs2EncoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/Rs2EncoderTest.kt @@ -10,7 +10,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object Rs2EncoderTest { +class Rs2EncoderTest { @Test fun testEncode() { testEncode(FixedPacket(0x11223344), byteArrayOf(0, 0x11, 0x22, 0x33, 0x44)) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestDecoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestDecoderTest.kt index 7b3d5bf6..2e4859c5 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestDecoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestDecoderTest.kt @@ -6,7 +6,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object JaggrabRequestDecoderTest { +class JaggrabRequestDecoderTest { @Test fun testDecode() { val channel = EmbeddedChannel(JaggrabRequestDecoder) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestEncoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestEncoderTest.kt index 34457012..2d698058 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestEncoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/jaggrab/JaggrabRequestEncoderTest.kt @@ -4,7 +4,7 @@ import io.netty.channel.embedded.EmbeddedChannel import kotlin.test.Test import kotlin.test.assertEquals -object JaggrabRequestEncoderTest { +class JaggrabRequestEncoderTest { @Test fun testEncode() { val channel = EmbeddedChannel(JaggrabRequestEncoder) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestDecoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestDecoderTest.kt index 0a046eb8..030cb2cb 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestDecoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestDecoderTest.kt @@ -8,7 +8,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object Js5RequestDecoderTest { +class Js5RequestDecoderTest { @Test fun testDecode() { testDecode(byteArrayOf(0, 2, 0, 3), Js5Request.Group(true, 2, 3)) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt index 5be09682..5f330b0c 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt @@ -7,7 +7,7 @@ import org.openrs2.buffer.use import kotlin.test.Test import kotlin.test.assertEquals -object Js5RequestEncoderTest { +class Js5RequestEncoderTest { @Test fun testEncode() { testEncode(Js5Request.Group(true, 2, 3), byteArrayOf(0, 2, 0, 3)) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt index c79b9433..c8d5e863 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoderTest.kt @@ -11,7 +11,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object Js5ResponseDecoderTest { +class Js5ResponseDecoderTest { @Test fun testDecode() { testDecode("509.dat", "509-prefetch.dat", true) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt index 277c97fc..f903ea6b 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt @@ -9,7 +9,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object Js5ResponseEncoderTest { +class Js5ResponseEncoderTest { @Test fun testEncode() { testEncode("509.dat", "509-prefetch.dat", true) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorDecoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorDecoderTest.kt index 94840481..c68d4a5e 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorDecoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorDecoderTest.kt @@ -8,7 +8,7 @@ import org.openrs2.buffer.use import kotlin.test.Test import kotlin.test.assertEquals -object XorDecoderTest { +class XorDecoderTest { @Test fun testDecode() { testDecode(0, "OpenRS2", false) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorEncoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorEncoderTest.kt index 6918b37b..0a6ed56b 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorEncoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/XorEncoderTest.kt @@ -8,7 +8,7 @@ import org.openrs2.buffer.use import kotlin.test.Test import kotlin.test.assertEquals -object XorEncoderTest { +class XorEncoderTest { @Test fun testEncode() { testEncode(0, "OpenRS2", false) diff --git a/util/src/test/kotlin/org/openrs2/util/StringUtilsTest.kt b/util/src/test/kotlin/org/openrs2/util/StringUtilsTest.kt index 5b5dde79..c633a118 100644 --- a/util/src/test/kotlin/org/openrs2/util/StringUtilsTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/StringUtilsTest.kt @@ -4,7 +4,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -object StringUtilsTest { +class StringUtilsTest { @Test fun testIndefiniteArticle() { assertEquals("a", "book".indefiniteArticle()) diff --git a/util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt b/util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt index 7246267b..72f86e34 100644 --- a/util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/charset/Cp1252CharsetTest.kt @@ -6,7 +6,7 @@ import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue -object Cp1252CharsetTest { +class Cp1252CharsetTest { @Test fun testEncodeChar() { // edge cases diff --git a/util/src/test/kotlin/org/openrs2/util/charset/ModifiedUtf8CharsetTest.kt b/util/src/test/kotlin/org/openrs2/util/charset/ModifiedUtf8CharsetTest.kt index db219544..cd514a0e 100644 --- a/util/src/test/kotlin/org/openrs2/util/charset/ModifiedUtf8CharsetTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/charset/ModifiedUtf8CharsetTest.kt @@ -5,7 +5,7 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue -object ModifiedUtf8CharsetTest { +class ModifiedUtf8CharsetTest { @Test fun testEncode() { assertArrayEquals(byteArrayOf(0xC0.toByte(), 0x80.toByte()), "\u0000".toByteArray(ModifiedUtf8Charset)) diff --git a/util/src/test/kotlin/org/openrs2/util/collect/ForestDisjointSetTest.kt b/util/src/test/kotlin/org/openrs2/util/collect/ForestDisjointSetTest.kt index 1e40a94b..65250d82 100644 --- a/util/src/test/kotlin/org/openrs2/util/collect/ForestDisjointSetTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/collect/ForestDisjointSetTest.kt @@ -5,7 +5,7 @@ import kotlin.test.assertEquals import kotlin.test.assertNotEquals import kotlin.test.assertNull -object ForestDisjointSetTest { +class ForestDisjointSetTest { @Test fun testAdd() { val set = ForestDisjointSet() diff --git a/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt b/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt index 4c9b51b4..5f65dbd9 100644 --- a/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt @@ -7,7 +7,7 @@ import kotlin.test.assertFalse import kotlin.test.assertNull import kotlin.test.assertTrue -object IterableUtilsTest { +class IterableUtilsTest { @Test fun testRemoveFirst() { val list = mutableListOf(1, 2, 3) diff --git a/util/src/test/kotlin/org/openrs2/util/io/DeterministicJarOutputStreamTest.kt b/util/src/test/kotlin/org/openrs2/util/io/DeterministicJarOutputStreamTest.kt index df31c8f1..81250b00 100644 --- a/util/src/test/kotlin/org/openrs2/util/io/DeterministicJarOutputStreamTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/io/DeterministicJarOutputStreamTest.kt @@ -12,9 +12,7 @@ import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertNull -object DeterministicJarOutputStreamTest { - private val UNIX_EPOCH = FileTime.fromMillis(0) - private val Y2K = FileTime.fromMillis(946684800) +class DeterministicJarOutputStreamTest { private val manifest = Manifest().apply { mainAttributes[Attributes.Name.MANIFEST_VERSION] = "1.0" mainAttributes[Attributes.Name.MAIN_CLASS] = "Hello" @@ -60,4 +58,9 @@ object DeterministicJarOutputStreamTest { } } } + + private companion object { + private val UNIX_EPOCH = FileTime.fromMillis(0) + private val Y2K = FileTime.fromMillis(946684800) + } } diff --git a/util/src/test/kotlin/org/openrs2/util/io/SkipOutputStreamTest.kt b/util/src/test/kotlin/org/openrs2/util/io/SkipOutputStreamTest.kt index 47e5a597..bb1cfdad 100644 --- a/util/src/test/kotlin/org/openrs2/util/io/SkipOutputStreamTest.kt +++ b/util/src/test/kotlin/org/openrs2/util/io/SkipOutputStreamTest.kt @@ -7,7 +7,7 @@ import java.io.OutputStream import kotlin.test.Test import kotlin.test.assertTrue -object SkipOutputStreamTest { +class SkipOutputStreamTest { @Test fun testSkipBytes() { for (n in 0..5) {