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