X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Frhynodge%2Fwebpages%2Fweather%2Fwettercom%2FWetterComStateTest.kt;h=d32e563e54ad5cb1546af9671a9495f751fe8e14;hb=1fa3a25a6851da90a2f30fd22a97a13b26dd1b6e;hp=e6ab943e432cb9ef2426311d00b0538d9f464c27;hpb=44cf7e2699e1a98263d2ac8e3cfdef16e52b0394;p=rhynodge.git diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt index e6ab943..d32e563 100644 --- a/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt +++ b/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt @@ -1,5 +1,8 @@ package net.pterodactylus.rhynodge.webpages.weather.wettercom +import com.fasterxml.jackson.databind.ObjectMapper +import net.pterodactylus.rhynodge.webpages.weather.HourState +import net.pterodactylus.rhynodge.webpages.weather.WindDirection import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.`is` import org.junit.Test @@ -16,7 +19,7 @@ class WetterComStateTest { @Test fun statesWithoutHoursEqualOneAnother() { - val now = Instant.now().atZone(ZoneId.of("UTC")) + val now = Instant.now().atZone(ZoneId.of("Europe/Berlin")) val firstState = WetterComState(ZonedDateTime.from(now)) val secondState = WetterComState(ZonedDateTime.from(now)) assertThat(firstState, `is`(secondState)) @@ -24,23 +27,36 @@ class WetterComStateTest { @Test fun statesWithTheSameHoursAreEqual() { - val now = Instant.now().atZone(ZoneId.of("UTC")) + val now = Instant.now().atZone(ZoneId.of("Europe/Berlin")) val firstState = WetterComState(ZonedDateTime.from(now)) - firstState.addHour(HourState(0, 10.0, 0.05, 0.0, WindDirection.NORTH, 5.0, "Fine", "http://1")) - firstState.addHour(HourState(1, 12.0, 0.1, 2.0, WindDirection.WEST, 8.0, "Superb", "http://2")) + firstState += HourState(0, 10, null, 0.05, 0.0, WindDirection.NORTH, 5, null, null, "Fine", "http://1") + firstState += HourState(1, 12, null, 0.1, 2.0, WindDirection.WEST, 8, null, null, "Superb", "http://2") val secondState = WetterComState(ZonedDateTime.from(now)) - secondState.addHour(HourState(0, 10.0, 0.05, 0.0, WindDirection.NORTH, 5.0, "Fine", "http://1")) - secondState.addHour(HourState(1, 12.0, 0.1, 2.0, WindDirection.WEST, 8.0, "Superb", "http://2")) + secondState += HourState(0, 10, null, 0.05, 0.0, WindDirection.NORTH, 5, null, null, "Fine", "http://1") + secondState += HourState(1, 12, null, 0.1, 2.0, WindDirection.WEST, 8, null, null, "Superb", "http://2") assertThat(firstState, `is`(secondState)) } @Test fun iteratingDeliversHourStates() { - val now = Instant.now().atZone(ZoneId.of("UTC")) + val now = Instant.now().atZone(ZoneId.of("Europe/Berlin")) val firstState = WetterComState(ZonedDateTime.from(now)) - firstState.addHour(HourState(0, 10.0, 0.05, 0.0, WindDirection.NORTH, 5.0, "Fine", "http://1")) - firstState.addHour(HourState(1, 12.0, 0.1, 2.0, WindDirection.WEST, 8.0, "Superb", "http://2")) + firstState += HourState(0, 10, null, 0.05, 0.0, WindDirection.NORTH, 5, null, null, "Fine", "http://1") + firstState += HourState(1, 12, null, 0.1, 2.0, WindDirection.WEST, 8, null, null, "Superb", "http://2") assertThat(firstState.iterator().asSequence().toList(), `is`(firstState.hours as Iterable)) } + @Test + fun stateIsSerializableAsJson() { + val objectMapper = ObjectMapper() + val now = Instant.now().atZone(ZoneId.of("Europe/Berlin")) + val originalState = WetterComState(ZonedDateTime.from(now)) + originalState += HourState(0, 10, null, 0.05, 0.0, WindDirection.NORTH, 5, null, null, "Fine", "http://1") + originalState += HourState(1, 12, null, 0.1, 2.0, WindDirection.WEST, 8, null, null, "Superb", "http://2") + val json = objectMapper.writeValueAsString(originalState) + println(json) + val parsedState = objectMapper.readValue(json, WetterComState::class.java) + assertThat(parsedState, `is`(originalState)) + } + }