aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/xyz/driver/core/JsonTest.scala
diff options
context:
space:
mode:
authorZach Smith <zach@driver.xyz>2017-12-20 12:34:56 -0800
committerZach Smith <zach@driver.xyz>2017-12-20 12:34:56 -0800
commit1286317ff473265333a3809d1038aa133fd6d662 (patch)
treeb7a33c39fabc453a6652b58e355e440b874d7e9d /src/test/scala/xyz/driver/core/JsonTest.scala
parenta2adb740d8abec507846bffb52c764e9226a7817 (diff)
downloaddriver-core-1286317ff473265333a3809d1038aa133fd6d662.tar.gz
driver-core-1286317ff473265333a3809d1038aa133fd6d662.tar.bz2
driver-core-1286317ff473265333a3809d1038aa133fd6d662.zip
Add InetAddress JSON format
Diffstat (limited to 'src/test/scala/xyz/driver/core/JsonTest.scala')
-rw-r--r--src/test/scala/xyz/driver/core/JsonTest.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/core/JsonTest.scala b/src/test/scala/xyz/driver/core/JsonTest.scala
index 26e3796..a45025a 100644
--- a/src/test/scala/xyz/driver/core/JsonTest.scala
+++ b/src/test/scala/xyz/driver/core/JsonTest.scala
@@ -1,5 +1,7 @@
package xyz.driver.core
+import java.net.InetAddress
+
import eu.timepit.refined.collection.NonEmpty
import eu.timepit.refined.numeric.Positive
import eu.timepit.refined.refineMV
@@ -198,4 +200,21 @@ class JsonTest extends FlatSpec with Matchers {
val parsedRefinedNumber = jsonFormat.read(writtenJson)
parsedRefinedNumber should be(referenceRefinedNumber)
}
+
+ "InetAddress format" should "read and write correct JSON" in {
+ val address = InetAddress.getByName("127.0.0.1")
+ val json = inetAddressFormat.write(address)
+
+ json shouldBe JsString("127.0.0.1")
+
+ val parsed = inetAddressFormat.read(json)
+ parsed shouldBe address
+ }
+
+ it should "throw a DeserializationException for an invalid IP Address" in {
+ assertThrows[DeserializationException] {
+ val invalidAddress = JsString("foobar")
+ inetAddressFormat.read(invalidAddress)
+ }
+ }
}