1 package net.pterodactylus.rhynodge.webpages.weather.wettercom
3 import net.pterodactylus.rhynodge.Reaction
4 import net.pterodactylus.rhynodge.webpages.weather.HourState
5 import net.pterodactylus.rhynodge.webpages.weather.WindDirection
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.`is`
8 import org.hamcrest.Matchers.containsString
10 import org.mockito.Mockito
11 import java.time.ZoneId
12 import java.time.ZonedDateTime
15 * Unit test for [WetterComTrigger].
17 * @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net)
19 class WetterComTriggerTest {
21 private val trigger = WetterComTrigger()
22 private val now = ZonedDateTime.now()
23 private val previousState = WetterComState(now)
26 fun equalStatesAreNotMerged() {
27 val currentState = WetterComState(now)
28 val newState = trigger.mergeStates(previousState, currentState) as WetterComState
29 assertThat(newState, `is`(previousState))
30 assertThat(newState, `is`(currentState))
34 fun currentStateIsReturnedIfDifferentFromPreviousState() {
35 val currentState = WetterComState(now.minusDays(1))
36 val newState = trigger.mergeStates(previousState, currentState) as WetterComState
37 assertThat(newState, `is`(currentState))
41 fun mergingEqualStatesDoesNotTrigger() {
42 val currentState = WetterComState(now)
43 trigger.mergeStates(previousState, currentState) as WetterComState
44 assertThat(trigger.triggers(), `is`(false))
48 fun mergingDifferentStatesDoesTrigger() {
49 val currentState = WetterComState(now.minusDays(1))
50 trigger.mergeStates(previousState, currentState) as WetterComState
51 assertThat(trigger.triggers(), `is`(true))
55 fun outputSummaryContainsCorrectDate() {
56 val currentState = WetterComState(ZonedDateTime.of(2000, 1, 1, 5, 0, 0, 0, ZoneId.of("Europe/Berlin")))
57 trigger.mergeStates(previousState, currentState) as WetterComState
58 val reaction = Mockito.mock(Reaction::class.java)
59 val output = trigger.output(reaction)
60 assertThat(output.summary(), `is`("The weather (according to wetter.com) on January 1, 2000"))
64 fun outputHtmlContainsHourStates() {
65 val currentState = WetterComState(now.minusDays(1))
66 currentState += HourState(0, 10, null, 0.11, 12.0, WindDirection.NORTH, 13, null, null, "Rain", "http://1")
67 currentState += HourState(1, 14, null, 0.15, 16.0, WindDirection.SOUTH, 17, null, null, "Sun", "http://2")
68 trigger.mergeStates(previousState, currentState) as WetterComState
69 val reaction = Mockito.mock(Reaction::class.java)
70 val output = trigger.output(reaction)
71 val htmlText = output.text("text/html", -1)
72 assertThat(htmlText, containsString("10 °C"))
73 assertThat(htmlText, containsString("11%"))
74 assertThat(htmlText, containsString("12 l/m"))
75 assertThat(htmlText, containsString("13 km/h"))
76 assertThat(htmlText, containsString("Rain"))
77 assertThat(htmlText, containsString("http://1"))
78 assertThat(htmlText, containsString("14 °C"))
79 assertThat(htmlText, containsString("15%"))
80 assertThat(htmlText, containsString("16 l/m"))
81 assertThat(htmlText, containsString("17 km/h"))
82 assertThat(htmlText, containsString("Sun"))
83 assertThat(htmlText, containsString("http://2"))