Fix spotless complaints

This commit is contained in:
Paul Schaub 2025-09-25 23:05:30 +02:00
parent b28e234f21
commit 36dd4ddc0a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 19 additions and 25 deletions

View file

@ -9,15 +9,13 @@ import com.google.gson.JsonSyntaxException
import com.google.gson.reflect.TypeToken
import java.text.ParseException
class GsonParser(
private val gson: Gson = Gson()
) : Verification.JSONParser {
class GsonParser(private val gson: Gson = Gson()) : Verification.JSONParser {
override fun parse(string: String): Verification.JSON {
try {
return gson.fromJson(string, object : TypeToken<Verification.JSON>(){}.type)
return gson.fromJson(string, object : TypeToken<Verification.JSON>() {}.type)
} catch (e: JsonSyntaxException) {
throw ParseException(e.message, 0)
}
}
}
}

View file

@ -6,11 +6,9 @@ package sop
import com.google.gson.Gson
class GsonSerializer(
private val gson: Gson = Gson()
) : Verification.JSONSerializer {
class GsonSerializer(private val gson: Gson = Gson()) : Verification.JSONSerializer {
override fun serialize(json: Verification.JSON): String {
return gson.toJson(json)
}
}
}

View file

@ -4,10 +4,10 @@
package sop
import java.text.ParseException
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import java.text.ParseException
class GsonSerializerAndParserTest {
@ -40,10 +40,7 @@ class GsonSerializerAndParserTest {
@Test
fun withCommentTest() {
val before = Verification.JSON(
listOf("/tmp/alice.pgp"),
"This is a comment.",
null)
val before = Verification.JSON(listOf("/tmp/alice.pgp"), "This is a comment.", null)
val json = serializer.serialize(before)
assertEquals("{\"signers\":[\"/tmp/alice.pgp\"],\"comment\":\"This is a comment.\"}", json)
@ -55,13 +52,14 @@ class GsonSerializerAndParserTest {
@Test
fun withExtStringTest() {
val before = Verification.JSON(
listOf("/tmp/alice.pgp"),
"This is a comment.",
"This is an ext object string.")
val before =
Verification.JSON(
listOf("/tmp/alice.pgp"), "This is a comment.", "This is an ext object string.")
val json = serializer.serialize(before)
assertEquals("{\"signers\":[\"/tmp/alice.pgp\"],\"comment\":\"This is a comment.\",\"ext\":\"This is an ext object string.\"}", json)
assertEquals(
"{\"signers\":[\"/tmp/alice.pgp\"],\"comment\":\"This is a comment.\",\"ext\":\"This is an ext object string.\"}",
json)
val after = parser.parse(json)
@ -70,13 +68,13 @@ class GsonSerializerAndParserTest {
@Test
fun withExtListTest() {
val before = Verification.JSON(
listOf("/tmp/alice.pgp"),
"This is a comment.",
listOf(1.0,2.0,3.0))
val before =
Verification.JSON(listOf("/tmp/alice.pgp"), "This is a comment.", listOf(1.0, 2.0, 3.0))
val json = serializer.serialize(before)
assertEquals("{\"signers\":[\"/tmp/alice.pgp\"],\"comment\":\"This is a comment.\",\"ext\":[1.0,2.0,3.0]}", json)
assertEquals(
"{\"signers\":[\"/tmp/alice.pgp\"],\"comment\":\"This is a comment.\",\"ext\":[1.0,2.0,3.0]}",
json)
val after = parser.parse(json)
@ -93,4 +91,4 @@ class GsonSerializerAndParserTest {
// Missing '}'
assertThrows<ParseException> { parser.parse("{\"signers\":[\"Alice\"]") }
}
}
}