diff options
author | zachdriver <zach@driver.xyz> | 2017-12-20 12:52:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-20 12:52:49 -0800 |
commit | 691a7991f3a7f3836084df3c0ec57a6ee4f76d8a (patch) | |
tree | b7a33c39fabc453a6652b58e355e440b874d7e9d /src/test/scala | |
parent | a2adb740d8abec507846bffb52c764e9226a7817 (diff) | |
parent | 1286317ff473265333a3809d1038aa133fd6d662 (diff) | |
download | driver-core-691a7991f3a7f3836084df3c0ec57a6ee4f76d8a.tar.gz driver-core-691a7991f3a7f3836084df3c0ec57a6ee4f76d8a.tar.bz2 driver-core-691a7991f3a7f3836084df3c0ec57a6ee4f76d8a.zip |
Merge pull request #99 from drivergroup/zsmith/ip-jsonv1.6.11
Add InetAddress JSON format
Diffstat (limited to 'src/test/scala')
-rw-r--r-- | src/test/scala/xyz/driver/core/JsonTest.scala | 19 |
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) + } + } } |