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