mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-12-05 04:41:09 +01:00
Fix spotless complaints
This commit is contained in:
parent
b28e234f21
commit
36dd4ddc0a
3 changed files with 19 additions and 25 deletions
|
|
@ -9,15 +9,13 @@ import com.google.gson.JsonSyntaxException
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import java.text.ParseException
|
import java.text.ParseException
|
||||||
|
|
||||||
class GsonParser(
|
class GsonParser(private val gson: Gson = Gson()) : Verification.JSONParser {
|
||||||
private val gson: Gson = Gson()
|
|
||||||
) : Verification.JSONParser {
|
|
||||||
|
|
||||||
override fun parse(string: String): Verification.JSON {
|
override fun parse(string: String): Verification.JSON {
|
||||||
try {
|
try {
|
||||||
return gson.fromJson(string, object : TypeToken<Verification.JSON>(){}.type)
|
return gson.fromJson(string, object : TypeToken<Verification.JSON>() {}.type)
|
||||||
} catch (e: JsonSyntaxException) {
|
} catch (e: JsonSyntaxException) {
|
||||||
throw ParseException(e.message, 0)
|
throw ParseException(e.message, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,9 @@ package sop
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
|
||||||
class GsonSerializer(
|
class GsonSerializer(private val gson: Gson = Gson()) : Verification.JSONSerializer {
|
||||||
private val gson: Gson = Gson()
|
|
||||||
) : Verification.JSONSerializer {
|
|
||||||
|
|
||||||
override fun serialize(json: Verification.JSON): String {
|
override fun serialize(json: Verification.JSON): String {
|
||||||
return gson.toJson(json)
|
return gson.toJson(json)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
package sop
|
package sop
|
||||||
|
|
||||||
|
import java.text.ParseException
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
import java.text.ParseException
|
|
||||||
|
|
||||||
class GsonSerializerAndParserTest {
|
class GsonSerializerAndParserTest {
|
||||||
|
|
||||||
|
|
@ -40,10 +40,7 @@ class GsonSerializerAndParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun withCommentTest() {
|
fun withCommentTest() {
|
||||||
val before = Verification.JSON(
|
val before = Verification.JSON(listOf("/tmp/alice.pgp"), "This is a comment.", null)
|
||||||
listOf("/tmp/alice.pgp"),
|
|
||||||
"This is a comment.",
|
|
||||||
null)
|
|
||||||
|
|
||||||
val json = serializer.serialize(before)
|
val json = serializer.serialize(before)
|
||||||
assertEquals("{\"signers\":[\"/tmp/alice.pgp\"],\"comment\":\"This is a comment.\"}", json)
|
assertEquals("{\"signers\":[\"/tmp/alice.pgp\"],\"comment\":\"This is a comment.\"}", json)
|
||||||
|
|
@ -55,13 +52,14 @@ class GsonSerializerAndParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun withExtStringTest() {
|
fun withExtStringTest() {
|
||||||
val before = Verification.JSON(
|
val before =
|
||||||
listOf("/tmp/alice.pgp"),
|
Verification.JSON(
|
||||||
"This is a comment.",
|
listOf("/tmp/alice.pgp"), "This is a comment.", "This is an ext object string.")
|
||||||
"This is an ext object string.")
|
|
||||||
|
|
||||||
val json = serializer.serialize(before)
|
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)
|
val after = parser.parse(json)
|
||||||
|
|
||||||
|
|
@ -70,13 +68,13 @@ class GsonSerializerAndParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun withExtListTest() {
|
fun withExtListTest() {
|
||||||
val before = Verification.JSON(
|
val before =
|
||||||
listOf("/tmp/alice.pgp"),
|
Verification.JSON(listOf("/tmp/alice.pgp"), "This is a comment.", listOf(1.0, 2.0, 3.0))
|
||||||
"This is a comment.",
|
|
||||||
listOf(1.0,2.0,3.0))
|
|
||||||
|
|
||||||
val json = serializer.serialize(before)
|
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)
|
val after = parser.parse(json)
|
||||||
|
|
||||||
|
|
@ -93,4 +91,4 @@ class GsonSerializerAndParserTest {
|
||||||
// Missing '}'
|
// Missing '}'
|
||||||
assertThrows<ParseException> { parser.parse("{\"signers\":[\"Alice\"]") }
|
assertThrows<ParseException> { parser.parse("{\"signers\":[\"Alice\"]") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue