Use correct timezone in tests
[rhynodge.git] / src / test / kotlin / net / pterodactylus / rhynodge / webpages / weather / wettercom / WetterComStateTest.kt
index 2b52a77..149b9a2 100644 (file)
@@ -4,8 +4,8 @@ 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
+import java.time.ZonedDateTime
 
 /**
  * Unit test for [WetterComState].
@@ -16,24 +16,31 @@ 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))
+        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))
     }
 
     @Test
     fun statesWithTheSameHoursAreEqual() {
-        val now = Instant.now().atZone(ZoneId.of("UTC"))
-        println("%s %s".format(now, now.javaClass))
-        val firstState = WetterComState(LocalDateTime.from(now))
+        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"))
-        val secondState = WetterComState(LocalDateTime.from(now))
+        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"))
         assertThat(firstState, `is`(secondState))
     }
 
+    @Test
+    fun iteratingDeliversHourStates() {
+        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"))
+        assertThat(firstState.iterator().asSequence().toList(), `is`(firstState.hours as Iterable<HourState>))
+    }
+
 }