Make wetter.com state JSON-serializable
[rhynodge.git] / src / test / kotlin / net / pterodactylus / rhynodge / webpages / weather / wettercom / WetterComStateTest.kt
index 149b9a2..cdab7b6 100644 (file)
@@ -1,5 +1,6 @@
 package net.pterodactylus.rhynodge.webpages.weather.wettercom
 
+import com.fasterxml.jackson.databind.ObjectMapper
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.`is`
 import org.junit.Test
@@ -43,4 +44,17 @@ class WetterComStateTest {
         assertThat(firstState.iterator().asSequence().toList(), `is`(firstState.hours as Iterable<HourState>))
     }
 
+    @Test
+    fun stateIsSerializableAsJson() {
+        val objectMapper = ObjectMapper()
+        val now = Instant.now().atZone(ZoneId.of("Europe/Berlin"))
+        val originalState = WetterComState(ZonedDateTime.from(now))
+        originalState.addHour(HourState(0, 10.0, 0.05, 0.0, WindDirection.NORTH, 5.0, "Fine", "http://1"))
+        originalState.addHour(HourState(1, 12.0, 0.1, 2.0, WindDirection.WEST, 8.0, "Superb", "http://2"))
+        val json = objectMapper.writeValueAsString(originalState)
+        println(json)
+        val parsedState = objectMapper.readValue(json, WetterComState::class.java)
+        assertThat(parsedState, `is`(originalState))
+    }
+
 }