From f062582eff26673e47f89fbc1fb6275d4779544f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Dean=20K=C3=BCpper?= Date: Sun, 3 Nov 2024 20:12:29 +0100 Subject: [PATCH] bump dependencies --- README.md | 4 +- build.gradle.kts | 1 - gradle/libs.versions.toml | 22 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../scrayos/xenos/client/GrpcXenosClient.kt | 122 ++++++++---------- .../net/scrayos/xenos/client/data/CapeInfo.kt | 10 +- .../net/scrayos/xenos/client/data/HeadInfo.kt | 12 +- .../scrayos/xenos/client/data/ProfileInfo.kt | 28 ++-- .../net/scrayos/xenos/client/data/SkinInfo.kt | 12 +- .../net/scrayos/xenos/client/data/UuidInfo.kt | 24 ++-- .../xenos/client/GrpcXenosClientTest.kt | 18 +-- .../scrayos/xenos/client/data/CapeInfoTest.kt | 33 ++--- .../scrayos/xenos/client/data/HeadInfoTest.kt | 37 +++--- .../xenos/client/data/ProfileInfoTest.kt | 93 ++++++------- .../scrayos/xenos/client/data/SkinInfoTest.kt | 37 +++--- .../scrayos/xenos/client/data/UuidInfoTest.kt | 101 ++++++++------- .../xenos/client/utility/ImageUtilityTest.kt | 91 ++++++------- 17 files changed, 314 insertions(+), 333 deletions(-) diff --git a/README.md b/README.md index e0fceda..0bca2a5 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,10 @@ After your instance is up and running, you have to add Xenos Client for Kotlin t ```kotlin dependencies { // make sure to specify the latest version - api("net.scrayos", "xenos-client", "0.1.0") + api("net.scrayos", "xenos-client", "0.8.0") // choose your own gRPC runtime or use an existing one - runtimeOnly("io.grpc", "grpc-netty", "1.63.0") + runtimeOnly("io.grpc", "grpc-netty", "1.68.1") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 7c181d7..057f3f8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -42,7 +42,6 @@ dependencies { // specify test dependencies testImplementation(libs.kotlin.test) testImplementation(libs.bundles.kotest) - testImplementation(libs.mockk) testImplementation(libs.bundles.log4j) testRuntimeOnly(libs.grpc.netty) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 21af4c3..0aa1f0b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,17 +1,16 @@ [versions] -kotlin = "2.0.0" +kotlin = "2.0.21" dokka = "1.9.20" -ktlint = "1.2.1" -junit = "5.10.2" -kotest-core = "5.9.0" +ktlint = "1.4.0" +junit = "5.11.3" +kotest-core = "5.9.1" kotest-testcontainers = "2.0.2" -protobuf = "3.25.3" -protoc-java = "1.64.0" +protobuf = "4.28.3" +protoc-java = "1.68.1" protoc-kotlin = "1.4.1" -kotlin-coroutines = "1.8.1" -slf4j = "2.0.13" -log4j = "2.23.1" -mockk = "1.13.11" +kotlin-coroutines = "1.9.0" +slf4j = "2.0.16" +log4j = "2.24.1" [libraries] protobuf-kotlin = { group = "com.google.protobuf", name = "protobuf-kotlin", version.ref = "protobuf" } @@ -28,7 +27,6 @@ log4j-slf4j = { group = "org.apache.logging.log4j", name = "log4j-slf4j-impl", v protoc-core = { group = "com.google.protobuf", name = "protoc", version.ref = "protobuf" } protoc-genJava = { group = "io.grpc", name = "protoc-gen-grpc-java", version.ref = "protoc-java" } protoc-genKotlin = { group = "io.grpc", name = "protoc-gen-grpc-kotlin", version.ref = "protoc-kotlin" } -mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" } [bundles] kotest = ["kotest-runner", "kotest-testcontainers"] @@ -44,4 +42,4 @@ kover = { id = "org.jetbrains.kotlinx.kover", version = "0.8.0" } protobuf = { id = "com.google.protobuf", version = "0.9.4" } sonarqube = { id = "org.sonarqube", version = "5.0.0.4638" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "12.1.1" } -mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.28.0" } +mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.29.0" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a441313..df97d72 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/kotlin/net/scrayos/xenos/client/GrpcXenosClient.kt b/src/main/kotlin/net/scrayos/xenos/client/GrpcXenosClient.kt index d2616a9..34a91c5 100644 --- a/src/main/kotlin/net/scrayos/xenos/client/GrpcXenosClient.kt +++ b/src/main/kotlin/net/scrayos/xenos/client/GrpcXenosClient.kt @@ -57,19 +57,17 @@ class GrpcXenosClient( /** The coroutine-based stub for the communication with the gRPC interface of Xenos. */ private val stub: ProfileGrpcKt.ProfileCoroutineStub = ProfileGrpcKt.ProfileCoroutineStub(channel) - override suspend fun getUuid(name: String): UuidInfo? { - return try { - stub.getUuid( - uuidRequest { - username = name - }, - ).toResult() - } catch (ex: StatusException) { - when (ex.status.code) { - UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested uuid") - NOT_FOUND -> null - else -> throw ex - } + override suspend fun getUuid(name: String): UuidInfo? = try { + stub.getUuid( + uuidRequest { + username = name + }, + ).toResult() + } catch (ex: StatusException) { + when (ex.status.code) { + UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested uuid") + NOT_FOUND -> null + else -> throw ex } } @@ -79,68 +77,60 @@ class GrpcXenosClient( }, ).toResult() - override suspend fun getProfile(userId: UUID): ProfileInfo? { - return try { - stub.getProfile( - profileRequest { - uuid = userId.toString() - }, - ).toResult() - } catch (ex: StatusException) { - when (ex.status.code) { - UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested profile") - NOT_FOUND -> null - else -> throw ex - } + override suspend fun getProfile(userId: UUID): ProfileInfo? = try { + stub.getProfile( + profileRequest { + uuid = userId.toString() + }, + ).toResult() + } catch (ex: StatusException) { + when (ex.status.code) { + UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested profile") + NOT_FOUND -> null + else -> throw ex } } - override suspend fun getSkin(userId: UUID): SkinInfo? { - return try { - stub.getSkin( - skinRequest { - uuid = userId.toString() - }, - ).toResult() - } catch (ex: StatusException) { - when (ex.status.code) { - UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested skin") - NOT_FOUND -> null - else -> throw ex - } + override suspend fun getSkin(userId: UUID): SkinInfo? = try { + stub.getSkin( + skinRequest { + uuid = userId.toString() + }, + ).toResult() + } catch (ex: StatusException) { + when (ex.status.code) { + UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested skin") + NOT_FOUND -> null + else -> throw ex } } - override suspend fun getCape(userId: UUID): CapeInfo? { - return try { - stub.getCape( - capeRequest { - uuid = userId.toString() - }, - ).toResult() - } catch (ex: StatusException) { - when (ex.status.code) { - UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested cape") - NOT_FOUND -> null - else -> throw ex - } + override suspend fun getCape(userId: UUID): CapeInfo? = try { + stub.getCape( + capeRequest { + uuid = userId.toString() + }, + ).toResult() + } catch (ex: StatusException) { + when (ex.status.code) { + UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested cape") + NOT_FOUND -> null + else -> throw ex } } - override suspend fun getHead(userId: UUID, includeOverlay: Boolean): HeadInfo? { - return try { - stub.getHead( - headRequest { - uuid = userId.toString() - overlay = includeOverlay - }, - ).toResult() - } catch (ex: StatusException) { - when (ex.status.code) { - UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested head") - NOT_FOUND -> null - else -> throw ex - } + override suspend fun getHead(userId: UUID, includeOverlay: Boolean): HeadInfo? = try { + stub.getHead( + headRequest { + uuid = userId.toString() + overlay = includeOverlay + }, + ).toResult() + } catch (ex: StatusException) { + when (ex.status.code) { + UNAVAILABLE -> throw IllegalStateException("Xenos could not fetch the requested head") + NOT_FOUND -> null + else -> throw ex } } diff --git a/src/main/kotlin/net/scrayos/xenos/client/data/CapeInfo.kt b/src/main/kotlin/net/scrayos/xenos/client/data/CapeInfo.kt index b53a0dd..47a23bf 100644 --- a/src/main/kotlin/net/scrayos/xenos/client/data/CapeInfo.kt +++ b/src/main/kotlin/net/scrayos/xenos/client/data/CapeInfo.kt @@ -23,9 +23,7 @@ data class CapeInfo( * information that is related to the gRPC origin and is therefore independent of the client implementation, that was * used to retrieve the data from Xenos. */ -internal fun CapeResponse.toResult(): CapeInfo { - return CapeInfo( - bytes.toImage(), - Instant.ofEpochSecond(timestamp), - ) -} +internal fun CapeResponse.toResult(): CapeInfo = CapeInfo( + bytes.toImage(), + Instant.ofEpochSecond(timestamp), +) diff --git a/src/main/kotlin/net/scrayos/xenos/client/data/HeadInfo.kt b/src/main/kotlin/net/scrayos/xenos/client/data/HeadInfo.kt index 4f7fda8..f8e73e6 100644 --- a/src/main/kotlin/net/scrayos/xenos/client/data/HeadInfo.kt +++ b/src/main/kotlin/net/scrayos/xenos/client/data/HeadInfo.kt @@ -25,10 +25,8 @@ data class HeadInfo( * information that is related to the gRPC origin and is therefore independent of the client implementation, that was * used to retrieve the data from Xenos. */ -internal fun HeadResponse.toResult(): HeadInfo { - return HeadInfo( - bytes.toImage(), - Instant.ofEpochSecond(timestamp), - default, - ) -} +internal fun HeadResponse.toResult(): HeadInfo = HeadInfo( + bytes.toImage(), + Instant.ofEpochSecond(timestamp), + default, +) diff --git a/src/main/kotlin/net/scrayos/xenos/client/data/ProfileInfo.kt b/src/main/kotlin/net/scrayos/xenos/client/data/ProfileInfo.kt index d9a989d..f5c63df 100644 --- a/src/main/kotlin/net/scrayos/xenos/client/data/ProfileInfo.kt +++ b/src/main/kotlin/net/scrayos/xenos/client/data/ProfileInfo.kt @@ -43,18 +43,16 @@ data class ProfileInfo( * information that is related to the gRPC origin and is therefore independent of the client implementation, that was * used to retrieve the data from Xenos. */ -internal fun ProfileResponse.toResult(): ProfileInfo { - return ProfileInfo( - UUID.fromString(uuid), - name, - propertiesList.map { - ProfileInfo.Property( - it.name, - it.value, - if (it.hasSignature()) it.signature else null, - ) - }.toSet(), - profileActionsList.toSet(), - Instant.ofEpochSecond(timestamp), - ) -} +internal fun ProfileResponse.toResult(): ProfileInfo = ProfileInfo( + UUID.fromString(uuid), + name, + propertiesList.map { + ProfileInfo.Property( + it.name, + it.value, + if (it.hasSignature()) it.signature else null, + ) + }.toSet(), + profileActionsList.toSet(), + Instant.ofEpochSecond(timestamp), +) diff --git a/src/main/kotlin/net/scrayos/xenos/client/data/SkinInfo.kt b/src/main/kotlin/net/scrayos/xenos/client/data/SkinInfo.kt index 0f6ea1a..e7733fb 100644 --- a/src/main/kotlin/net/scrayos/xenos/client/data/SkinInfo.kt +++ b/src/main/kotlin/net/scrayos/xenos/client/data/SkinInfo.kt @@ -25,10 +25,8 @@ data class SkinInfo( * information that is related to the gRPC origin and is therefore independent of the client implementation, that was * used to retrieve the data from Xenos. */ -internal fun SkinResponse.toResult(): SkinInfo { - return SkinInfo( - bytes.toImage(), - Instant.ofEpochSecond(timestamp), - default, - ) -} +internal fun SkinResponse.toResult(): SkinInfo = SkinInfo( + bytes.toImage(), + Instant.ofEpochSecond(timestamp), + default, +) diff --git a/src/main/kotlin/net/scrayos/xenos/client/data/UuidInfo.kt b/src/main/kotlin/net/scrayos/xenos/client/data/UuidInfo.kt index 65093c1..1b74e99 100644 --- a/src/main/kotlin/net/scrayos/xenos/client/data/UuidInfo.kt +++ b/src/main/kotlin/net/scrayos/xenos/client/data/UuidInfo.kt @@ -26,13 +26,11 @@ data class UuidInfo( * information that is related to the gRPC origin and is therefore independent of the client implementation, that was * used to retrieve the data from Xenos. */ -internal fun UuidResponse.toResult(): UuidInfo { - return UuidInfo( - UUID.fromString(uuid), - username, - Instant.ofEpochSecond(timestamp), - ) -} +internal fun UuidResponse.toResult(): UuidInfo = UuidInfo( + UUID.fromString(uuid), + username, + Instant.ofEpochSecond(timestamp), +) /** * Converts the raw response from gRPC into a more user-friendly data class, that encapsulates the contained data in an @@ -40,10 +38,8 @@ internal fun UuidResponse.toResult(): UuidInfo { * information that is related to the gRPC origin and is therefore independent of the client implementation, that was * used to retrieve the data from Xenos. */ -internal fun UuidsResponse.toResult(): Map { - return resolvedMap - .mapValues { - it.value.toResult() - } - .toMap() -} +internal fun UuidsResponse.toResult(): Map = resolvedMap + .mapValues { + it.value.toResult() + } + .toMap() diff --git a/src/test/kotlin/net/scrayos/xenos/client/GrpcXenosClientTest.kt b/src/test/kotlin/net/scrayos/xenos/client/GrpcXenosClientTest.kt index 9c2a5c2..8100e28 100644 --- a/src/test/kotlin/net/scrayos/xenos/client/GrpcXenosClientTest.kt +++ b/src/test/kotlin/net/scrayos/xenos/client/GrpcXenosClientTest.kt @@ -19,9 +19,9 @@ import net.scrayos.xenos.client.utility.toImage import org.testcontainers.containers.GenericContainer import java.util.UUID -class GrpcXenosClientTest : ShouldSpec( - { - val container = GenericContainer("ghcr.io/scrayosnet/xenos:v0.3.0-static").apply { +class GrpcXenosClientTest : ShouldSpec() { + init { + val container = GenericContainer("ghcr.io/scrayosnet/xenos:0.6.1-testing").apply { withExposedPorts(50051) } val xenos = install(ContainerExtension(container)) @@ -161,10 +161,10 @@ class GrpcXenosClientTest : ShouldSpec( result.properties shouldContainExactly setOf( ProfileInfo.Property( "textures", - "eyJ0aW1lc3RhbXAiOjAsInByb2ZpbGVJZCI6IjljMDllZWY0LWY2OGQtNDM4Ny05NzUxLTcyYmJmZjUzZDVhM" + - "CIsInByb2ZpbGVOYW1lIjoiU2NyYXlvcyIsInNpZ25hdHVyZVJlcXVpcmVkIjpudWxsLCJ0ZXh0dXJlcyI6eyJT" + - "S0lOIjp7InVybCI6InNraW5fOWMwOWVlZjQtZjY4ZC00Mzg3LTk3NTEtNzJiYmZmNTNkNWEwIiwibWV0YWRhdGE" + - "iOm51bGx9LCJDQVBFIjpudWxsfX0=", + "eyJ0aW1lc3RhbXAiOjAsInByb2ZpbGVJZCI6IjljMDllZWY0LWY2OGQtNDM4Ny05NzUxLTcyYmJmZjUzZD" + + "VhMCIsInByb2ZpbGVOYW1lIjoiU2NyYXlvcyIsInNpZ25hdHVyZVJlcXVpcmVkIjpudWxsLCJ0ZXh0dXJlcy" + + "I6eyJTS0lOIjp7InVybCI6InNraW5fOWMwOWVlZjQtZjY4ZC00Mzg3LTk3NTEtNzJiYmZmNTNkNWEwIiwibW" + + "V0YWRhdGEiOm51bGx9LCJDQVBFIjpudWxsfX0=", null, ), ) @@ -274,5 +274,5 @@ class GrpcXenosClientTest : ShouldSpec( Thread.interrupted().shouldBeTrue() } } - }, -) + } +} diff --git a/src/test/kotlin/net/scrayos/xenos/client/data/CapeInfoTest.kt b/src/test/kotlin/net/scrayos/xenos/client/data/CapeInfoTest.kt index a938e99..bf3fecc 100644 --- a/src/test/kotlin/net/scrayos/xenos/client/data/CapeInfoTest.kt +++ b/src/test/kotlin/net/scrayos/xenos/client/data/CapeInfoTest.kt @@ -10,21 +10,22 @@ import net.scrayos.xenos.client.utility.toImage import scrayosnet.xenos.capeResponse import java.time.Instant -class CapeInfoTest : ShouldSpec( - { - context("#toResult") { - should("contain original data") { - val response = capeResponse { - bytes = ByteString.copyFrom(resourceAsBytes("/image_test.png")) - timestamp = 60 - } - val image = ByteString.copyFrom(resourceAsBytes("/image_test.png")).toImage() - val result = response.toResult() +class CapeInfoTest : + ShouldSpec( + { + context("#toResult") { + should("contain original data") { + val response = capeResponse { + bytes = ByteString.copyFrom(resourceAsBytes("/image_test.png")) + timestamp = 60 + } + val image = ByteString.copyFrom(resourceAsBytes("/image_test.png")).toImage() + val result = response.toResult() - result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(60) - result.texture shouldBeOfEqualDimensions image - result.texture shouldHaveEqualPixels image + result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(60) + result.texture shouldBeOfEqualDimensions image + result.texture shouldHaveEqualPixels image + } } - } - }, -) + }, + ) diff --git a/src/test/kotlin/net/scrayos/xenos/client/data/HeadInfoTest.kt b/src/test/kotlin/net/scrayos/xenos/client/data/HeadInfoTest.kt index 7fe3c06..62cf3f5 100644 --- a/src/test/kotlin/net/scrayos/xenos/client/data/HeadInfoTest.kt +++ b/src/test/kotlin/net/scrayos/xenos/client/data/HeadInfoTest.kt @@ -10,23 +10,24 @@ import net.scrayos.xenos.client.utility.toImage import scrayosnet.xenos.headResponse import java.time.Instant -class HeadInfoTest : ShouldSpec( - { - context("#toResult") { - should("contain original data") { - val response = headResponse { - bytes = ByteString.copyFrom(resourceAsBytes("/image_test.png")) - timestamp = 60 - default = true - } - val image = ByteString.copyFrom(resourceAsBytes("/image_test.png")).toImage() - val result = response.toResult() +class HeadInfoTest : + ShouldSpec( + { + context("#toResult") { + should("contain original data") { + val response = headResponse { + bytes = ByteString.copyFrom(resourceAsBytes("/image_test.png")) + timestamp = 60 + default = true + } + val image = ByteString.copyFrom(resourceAsBytes("/image_test.png")).toImage() + val result = response.toResult() - result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(60) - result.texture shouldBeOfEqualDimensions image - result.texture shouldHaveEqualPixels image - result.default shouldBe true + result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(60) + result.texture shouldBeOfEqualDimensions image + result.texture shouldHaveEqualPixels image + result.default shouldBe true + } } - } - }, -) + }, + ) diff --git a/src/test/kotlin/net/scrayos/xenos/client/data/ProfileInfoTest.kt b/src/test/kotlin/net/scrayos/xenos/client/data/ProfileInfoTest.kt index bdec90c..1d39f72 100644 --- a/src/test/kotlin/net/scrayos/xenos/client/data/ProfileInfoTest.kt +++ b/src/test/kotlin/net/scrayos/xenos/client/data/ProfileInfoTest.kt @@ -8,54 +8,55 @@ import scrayosnet.xenos.profileResponse import java.time.Instant import java.util.UUID -class ProfileInfoTest : ShouldSpec( - { - context("#toResult") { - should("contain original data") { - val testUuid = UUID.randomUUID() - val response = profileResponse { - uuid = testUuid.toString() - name = "Scrayos" - properties.addAll( - setOf( - profileProperty { - name = "texture" - value = "abc" - signature = "cde" - }, - profileProperty { - name = "meta" - value = "data" - }, +class ProfileInfoTest : + ShouldSpec( + { + context("#toResult") { + should("contain original data") { + val testUuid = UUID.randomUUID() + val response = profileResponse { + uuid = testUuid.toString() + name = "Scrayos" + properties.addAll( + setOf( + profileProperty { + name = "texture" + value = "abc" + signature = "cde" + }, + profileProperty { + name = "meta" + value = "data" + }, + ), + ) + profileActions.addAll( + setOf( + "IMPORTANT_ACTION", + "OTHER_ACTION", + ), + ) + timestamp = 65 + } + val result = response.toResult() + + result.id shouldBe testUuid + result.name shouldBe "Scrayos" + result.properties shouldContainExactly setOf( + ProfileInfo.Property( + "texture", + "abc", + "cde", ), - ) - profileActions.addAll( - setOf( - "IMPORTANT_ACTION", - "OTHER_ACTION", + ProfileInfo.Property( + "meta", + "data", + null, ), ) - timestamp = 65 + result.actions.shouldContainExactly("IMPORTANT_ACTION", "OTHER_ACTION") + result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(65) } - val result = response.toResult() - - result.id shouldBe testUuid - result.name shouldBe "Scrayos" - result.properties shouldContainExactly setOf( - ProfileInfo.Property( - "texture", - "abc", - "cde", - ), - ProfileInfo.Property( - "meta", - "data", - null, - ), - ) - result.actions.shouldContainExactly("IMPORTANT_ACTION", "OTHER_ACTION") - result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(65) } - } - }, -) + }, + ) diff --git a/src/test/kotlin/net/scrayos/xenos/client/data/SkinInfoTest.kt b/src/test/kotlin/net/scrayos/xenos/client/data/SkinInfoTest.kt index a9eea37..9b3e90a 100644 --- a/src/test/kotlin/net/scrayos/xenos/client/data/SkinInfoTest.kt +++ b/src/test/kotlin/net/scrayos/xenos/client/data/SkinInfoTest.kt @@ -10,23 +10,24 @@ import net.scrayos.xenos.client.utility.toImage import scrayosnet.xenos.skinResponse import java.time.Instant -class SkinInfoTest : ShouldSpec( - { - context("#toResult") { - should("contain original data") { - val response = skinResponse { - bytes = ByteString.copyFrom(resourceAsBytes("/image_test.png")) - timestamp = 60 - default = true - } - val image = ByteString.copyFrom(resourceAsBytes("/image_test.png")).toImage() - val result = response.toResult() +class SkinInfoTest : + ShouldSpec( + { + context("#toResult") { + should("contain original data") { + val response = skinResponse { + bytes = ByteString.copyFrom(resourceAsBytes("/image_test.png")) + timestamp = 60 + default = true + } + val image = ByteString.copyFrom(resourceAsBytes("/image_test.png")).toImage() + val result = response.toResult() - result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(60) - result.texture shouldBeOfEqualDimensions image - result.texture shouldHaveEqualPixels image - result.default shouldBe true + result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(60) + result.texture shouldBeOfEqualDimensions image + result.texture shouldHaveEqualPixels image + result.default shouldBe true + } } - } - }, -) + }, + ) diff --git a/src/test/kotlin/net/scrayos/xenos/client/data/UuidInfoTest.kt b/src/test/kotlin/net/scrayos/xenos/client/data/UuidInfoTest.kt index 7aae749..24fc975 100644 --- a/src/test/kotlin/net/scrayos/xenos/client/data/UuidInfoTest.kt +++ b/src/test/kotlin/net/scrayos/xenos/client/data/UuidInfoTest.kt @@ -9,60 +9,61 @@ import scrayosnet.xenos.uuidsResponse import java.time.Instant import java.util.UUID -class UuidInfoTest : ShouldSpec( - { - context("UuidResponse#toResult") { - should("contain original data") { - val testName = "Scrayos" - val testUuid = UUID.randomUUID() - val response = uuidResponse { - uuid = testUuid.toString() - username = testName - timestamp = 65 +class UuidInfoTest : + ShouldSpec( + { + context("UuidResponse#toResult") { + should("contain original data") { + val testName = "Scrayos" + val testUuid = UUID.randomUUID() + val response = uuidResponse { + uuid = testUuid.toString() + username = testName + timestamp = 65 + } + val result = response.toResult() + result.id shouldBe testUuid + result.username shouldBe testName + result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(65) } - val result = response.toResult() - result.id shouldBe testUuid - result.username shouldBe testName - result.retrievedAt shouldBe Instant.EPOCH.plusSeconds(65) } - } - context("UuidsResponse#toResult") { - should("contain original data") { - val scrayosUuid = UUID.randomUUID() - val hydrofinUuid = UUID.randomUUID() - val response = uuidsResponse { - resolved.putAll( - mapOf( - "scrayos" to uuidResponse { - uuid = scrayosUuid.toString() - username = "Scrayos" - timestamp = 65 - }, - "hydrofin" to uuidResponse { - uuid = hydrofinUuid.toString() - username = "Hydrofin" - timestamp = 70 - }, - ), - ) - } - val result = response.toResult() + context("UuidsResponse#toResult") { + should("contain original data") { + val scrayosUuid = UUID.randomUUID() + val hydrofinUuid = UUID.randomUUID() + val response = uuidsResponse { + resolved.putAll( + mapOf( + "scrayos" to uuidResponse { + uuid = scrayosUuid.toString() + username = "Scrayos" + timestamp = 65 + }, + "hydrofin" to uuidResponse { + uuid = hydrofinUuid.toString() + username = "Hydrofin" + timestamp = 70 + }, + ), + ) + } + val result = response.toResult() - result.shouldContainKeys("scrayos", "hydrofin") + result.shouldContainKeys("scrayos", "hydrofin") - val scrayos = result["scrayos"] - scrayos.shouldNotBeNull() - scrayos.id shouldBe scrayosUuid - scrayos.username shouldBe "Scrayos" - scrayos.retrievedAt shouldBe Instant.EPOCH.plusSeconds(65) + val scrayos = result["scrayos"] + scrayos.shouldNotBeNull() + scrayos.id shouldBe scrayosUuid + scrayos.username shouldBe "Scrayos" + scrayos.retrievedAt shouldBe Instant.EPOCH.plusSeconds(65) - val hydrofin = result["hydrofin"] - hydrofin.shouldNotBeNull() - hydrofin.id shouldBe hydrofinUuid - hydrofin.username shouldBe "Hydrofin" - hydrofin.retrievedAt shouldBe Instant.EPOCH.plusSeconds(70) + val hydrofin = result["hydrofin"] + hydrofin.shouldNotBeNull() + hydrofin.id shouldBe hydrofinUuid + hydrofin.username shouldBe "Hydrofin" + hydrofin.retrievedAt shouldBe Instant.EPOCH.plusSeconds(70) + } } - } - }, -) + }, + ) diff --git a/src/test/kotlin/net/scrayos/xenos/client/utility/ImageUtilityTest.kt b/src/test/kotlin/net/scrayos/xenos/client/utility/ImageUtilityTest.kt index b362baf..cef48dd 100644 --- a/src/test/kotlin/net/scrayos/xenos/client/utility/ImageUtilityTest.kt +++ b/src/test/kotlin/net/scrayos/xenos/client/utility/ImageUtilityTest.kt @@ -9,62 +9,63 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.string.startWith @OptIn(ExperimentalStdlibApi::class) -class ImageUtilityTest : ShouldSpec( - { - context("ByteString.toImage") { - should("throw ISE for empty bytes") { - val exception = shouldThrow { - ByteString.empty().toImage() - } +class ImageUtilityTest : + ShouldSpec( + { + context("ByteString.toImage") { + should("throw ISE for empty bytes") { + val exception = shouldThrow { + ByteString.empty().toImage() + } - exception.message?.should(startWith("Image cannot be created from empty ByteString!")) - } + exception.message?.should(startWith("Image cannot be created from empty ByteString!")) + } - should("return correct dimensions for image") { - val resourceBytes = resourceAsBytes("/image_test.png") - val image = ByteString.copyFrom(resourceBytes).toImage() + should("return correct dimensions for image") { + val resourceBytes = resourceAsBytes("/image_test.png") + val image = ByteString.copyFrom(resourceBytes).toImage() - image.width shouldBe 4 - image.height shouldBe 4 - } + image.width shouldBe 4 + image.height shouldBe 4 + } - should("return correct data for image") { - val resourceBytes = resourceAsBytes("/image_test.png") - val image = ByteString.copyFrom(resourceBytes).toImage() + should("return correct data for image") { + val resourceBytes = resourceAsBytes("/image_test.png") + val image = ByteString.copyFrom(resourceBytes).toImage() - val testValues = listOf( - Triple(3, 0, 0xFFFFFFFF), + val testValues = listOf( + Triple(3, 0, 0xFFFFFFFF), - Triple(2, 0, 0xFFBCBCBC), - Triple(3, 1, 0xFFBCBCBC), + Triple(2, 0, 0xFFBCBCBC), + Triple(3, 1, 0xFFBCBCBC), - Triple(1, 0, 0xFF939393), - Triple(2, 1, 0xFF939393), - Triple(3, 2, 0xFF939393), + Triple(1, 0, 0xFF939393), + Triple(2, 1, 0xFF939393), + Triple(3, 2, 0xFF939393), - Triple(0, 0, 0xFF6B6B6B), - Triple(1, 1, 0xFF6B6B6B), - Triple(2, 2, 0xFF6B6B6B), - Triple(3, 3, 0xFF6B6B6B), + Triple(0, 0, 0xFF6B6B6B), + Triple(1, 1, 0xFF6B6B6B), + Triple(2, 2, 0xFF6B6B6B), + Triple(3, 3, 0xFF6B6B6B), - Triple(0, 1, 0xFF434343), - Triple(1, 2, 0xFF434343), - Triple(2, 3, 0xFF434343), + Triple(0, 1, 0xFF434343), + Triple(1, 2, 0xFF434343), + Triple(2, 3, 0xFF434343), - Triple(0, 2, 0xFF282828), - Triple(1, 3, 0xFF282828), + Triple(0, 2, 0xFF282828), + Triple(1, 3, 0xFF282828), - Triple(0, 3, 0xFF000000), - ) - for (v in testValues) { - val actual = image.getRGB(v.first, v.second) - val expected = v.third.toInt() - val expectedHex = expected.toHexString(HexFormat.UpperCase) - withClue("Pixel at (${v.first}, ${v.second}) should be color #$expectedHex") { - actual shouldBe expected + Triple(0, 3, 0xFF000000), + ) + for (v in testValues) { + val actual = image.getRGB(v.first, v.second) + val expected = v.third.toInt() + val expectedHex = expected.toHexString(HexFormat.UpperCase) + withClue("Pixel at (${v.first}, ${v.second}) should be color #$expectedHex") { + actual shouldBe expected + } } } } - } - }, -) + }, + )