1 package net.pterodactylus.rhynodge.webpages.weather.wetterde
3 import net.pterodactylus.rhynodge.Reaction
4 import net.pterodactylus.rhynodge.State
5 import net.pterodactylus.rhynodge.webpages.weather.HourState
6 import net.pterodactylus.rhynodge.webpages.weather.WindDirection
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.`is`
9 import org.hamcrest.Matchers.containsString
11 import org.mockito.Mockito.mock
12 import java.time.ZoneId.of
13 import java.time.ZonedDateTime
16 * Unit test for [WetterDeTriggerTest].
18 * @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net)
20 class WetterDeTriggerTest {
22 private val now = ZonedDateTime.now(of("Europe/Berlin"))
23 private val previousState = WetterDeState(now.minusDays(1))
24 private val trigger = WetterDeTrigger()
27 fun currentStateIsAlwaysReturned() {
28 val currentState = WetterDeState(now)
29 assertThat(trigger.mergeStates(previousState, currentState), `is`(currentState as State))
33 fun triggerDoesNotTriggerIfStateHasNotChanged() {
34 val currentState = WetterDeState(now.minusDays(1))
35 trigger.mergeStates(previousState, currentState)
36 assertThat(trigger.triggers(), `is`(false))
40 fun triggerDoesTriggerIfStateHasChanged() {
41 val currentState = WetterDeState(now)
42 trigger.mergeStates(previousState, currentState)
43 assertThat(trigger.triggers(), `is`(true))
47 fun outputContainsCorrectSummary() {
48 val currentState = WetterDeState(ZonedDateTime.of(2016, 5, 28, 0, 0, 0, 0, of("Europe/Berlin")))
49 trigger.mergeStates(previousState, currentState)
50 val reaction = mock(Reaction::class.java)
51 val output = trigger.output(reaction)
52 assertThat(output.summary(), `is`("The Weather (according to wetter.de) on May 28, 2016"))
56 fun outputContainsCorrectHourData() {
57 val currentState = WetterDeState(ZonedDateTime.of(2016, 5, 28, 0, 0, 0, 0, of("Europe/Berlin")))
58 currentState += HourState(0, 10, 11, 0.12, 13.0, WindDirection.SOUTHSOUTHEAST, 14, 15, 0.16, "17", "http://18")
59 currentState += HourState(1, 20, 21, 0.22, 23.0, WindDirection.NORTHNORTHWEST, 24, 25, 0.26, "27", "http://28")
60 trigger.mergeStates(previousState, currentState)
61 val reaction = mock(Reaction::class.java)
62 val output = trigger.output(reaction)
63 val htmlText = output.text("text/html", -1)
64 assertThat(htmlText, containsString("00:00"))
65 assertThat(htmlText, containsString("10 °C"))
66 assertThat(htmlText, containsString("(11 °C)"))
67 assertThat(htmlText, containsString("12%"))
68 assertThat(htmlText, containsString("13 l/m²"))
69 assertThat(htmlText, containsString("↖↑"))
70 assertThat(htmlText, containsString("14 km/h"))
71 assertThat(htmlText, containsString("15 km/h"))
72 assertThat(htmlText, containsString("16%"))
73 assertThat(htmlText, containsString("17"))
74 assertThat(htmlText, containsString("http://18"))
75 assertThat(htmlText, containsString("01:00"))
76 assertThat(htmlText, containsString("20 °C"))
77 assertThat(htmlText, containsString("(21 °C)"))
78 assertThat(htmlText, containsString("22%"))
79 assertThat(htmlText, containsString("23 l/m²"))
80 assertThat(htmlText, containsString("↘↓"))
81 assertThat(htmlText, containsString("24 km/h"))
82 assertThat(htmlText, containsString("25 km/h"))
83 assertThat(htmlText, containsString("26%"))
84 assertThat(htmlText, containsString("27"))
85 assertThat(htmlText, containsString("http://28"))