From: David ‘Bombe’ Roden Date: Thu, 26 May 2016 16:04:58 +0000 (+0200) Subject: Add unit test for wetter.com state X-Git-Tag: v2~142 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=eee28069a5ca66d8fbbcaa124dd3267779c9f832;p=rhynodge.git Add unit test for wetter.com state --- diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComState.kt b/src/main/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComState.kt index 06411cf..f14337f 100644 --- a/src/main/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComState.kt +++ b/src/main/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComState.kt @@ -16,4 +16,9 @@ class WetterComState(val dateTime: LocalDateTime) : AbstractState(true) { (hours as MutableList).add(hourState) } + override fun equals(other: Any?): Boolean { + other as? WetterComState ?: return false + return (dateTime == other.dateTime) and (hours == other.hours) + } + } 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 new file mode 100644 index 0000000..2b52a77 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/rhynodge/webpages/weather/wettercom/WetterComStateTest.kt @@ -0,0 +1,39 @@ +package net.pterodactylus.rhynodge.webpages.weather.wettercom + +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.`is` +import org.junit.Test +import java.time.Instant +import java.time.LocalDateTime +import java.time.ZoneId + +/** + * Unit test for [WetterComState]. + + * @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net) + */ +class WetterComStateTest { + + @Test + fun statesWithoutHoursEqualOneAnother() { + val now = Instant.now().atZone(ZoneId.of("UTC")) + println("%s %s".format(now, now.javaClass)) + val firstState = WetterComState(LocalDateTime.from(now)) + val secondState = WetterComState(LocalDateTime.from(now)) + assertThat(firstState, `is`(secondState)) + } + + @Test + fun statesWithTheSameHoursAreEqual() { + val now = Instant.now().atZone(ZoneId.of("UTC")) + println("%s %s".format(now, now.javaClass)) + val firstState = WetterComState(LocalDateTime.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")) + val secondState = WetterComState(LocalDateTime.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")) + assertThat(firstState, `is`(secondState)) + } + +}