3e7a25a1f9dfb19a2c343ca6f9f4b119e61f2ec4
[rhynodge.git] / src / test / kotlin / net / pterodactylus / rhynodge / webpages / weather / wetterde / WetterDeFilterTest.kt
1 package net.pterodactylus.rhynodge.webpages.weather.wetterde
2
3 import net.pterodactylus.rhynodge.filters.ResourceLoader
4 import net.pterodactylus.rhynodge.states.AbstractState
5 import net.pterodactylus.rhynodge.states.FailedState
6 import net.pterodactylus.rhynodge.states.HtmlState
7 import net.pterodactylus.rhynodge.webpages.weather.WindDirection
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.`is`
10 import org.hamcrest.Matchers.contains
11 import org.junit.Rule
12 import org.junit.Test
13 import org.junit.rules.ExpectedException
14 import java.time.ZoneId
15 import java.time.ZonedDateTime
16
17 /**
18  * Unit test for [WetterDeFilter].
19
20  * @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net)
21  */
22 class WetterDeFilterTest {
23
24     @Rule @JvmField val expectedException = ExpectedException.none()
25
26     private val url = ""
27     private val filter = WetterDeFilter()
28
29     @Test
30     fun filterReturnsFailedStateIfGivenAFailedState() {
31         val previousState = FailedState.INSTANCE
32         assertThat(filter.filter(previousState).success(), `is`(false))
33     }
34
35     @Test
36     fun filterThrowsExceptionIfNotGivenAnHtmlState() {
37         val successfulHonHtmlState = object : AbstractState(true) {}
38         expectedException.expect(IllegalArgumentException::class.java)
39         filter.filter(successfulHonHtmlState)
40     }
41
42     @Test
43     fun filterCanParseDateCorrectly() {
44         val htmlState = HtmlState(url, ResourceLoader.loadDocument(javaClass, "wetter.de.html", url))
45         val wetterDeState = filter.filter(htmlState) as WetterDeState
46         assertThat(wetterDeState.dateTime, `is`(ZonedDateTime.of(2016, 5, 30, 0, 0, 0, 0, ZoneId.of("Europe/Berlin"))))
47     }
48
49     @Test
50     fun filterParsesHoursCorrectly() {
51         val htmlState = HtmlState(url, ResourceLoader.loadDocument(javaClass, "wetter.de.html", url))
52         val wetterDeState = filter.filter(htmlState) as WetterDeState
53         assertThat(wetterDeState, contains(
54                 HourState(0, 18, 18, 0.47, 0.4, WindDirection.NORTHEAST, 19, 41, 0.91, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/017_M.png?o44shg"),
55                 HourState(1, 18, 18, 0.60, 0.6, WindDirection.NORTHEAST, 20, 39, 0.91, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/017_M.png?o44shg"),
56                 HourState(2, 18, 18, 0.59, 0.6, WindDirection.NORTHEAST, 20, 39, 0.89, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/017_M.png?o44shg"),
57                 HourState(3, 18, 18, 0.49, 0.7, WindDirection.NORTHEAST, 19, 39, 0.89, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/017_M.png?o44shg"),
58                 HourState(4, 18, 18, 0.38, 0.5, WindDirection.NORTHEAST, 19, 39, 0.89, "unbeständig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/022_M.png?o44shg"),
59                 HourState(5, 17, 18, 0.35, 0.4, WindDirection.NORTHEAST, 19, 39, 0.90, "unbeständig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/010_M.png?o44shg"),
60                 HourState(6, 17, 19, 0.45, 0.6, WindDirection.NORTHEAST, 19, 39, 0.91, "unbeständig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/010_M.png?o44shg"),
61                 HourState(7, 18, 19, 0.59, 1.0, WindDirection.NORTHEAST, 19, 39, 0.88, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
62                 HourState(8, 19, 20, 0.64, 0.7, WindDirection.EASTNORTHEAST, 19, 39, 0.83, "unbeständig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/010_M.png?o44shg"),
63                 HourState(9, 20, 21, 0.59, 0.3, WindDirection.EASTNORTHEAST, 20, 41, 0.79, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
64                 HourState(10, 21, 21, 0.50, 0.2, WindDirection.EASTNORTHEAST, 20, 43, 0.75, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
65                 HourState(11, 22, 22, 0.39, 0.1, WindDirection.EASTNORTHEAST, 20, 44, 0.71, "wechselhaft", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/010_M.png?o44shg"),
66                 HourState(12, 23, 23, 0.24, 0.05, WindDirection.EASTNORTHEAST, 20, 44, 0.70, "heiter", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/003_M.png?o44shg"),
67                 HourState(13, 24, 24, 0.13, 0.02, WindDirection.EAST, 20, 46, 0.68, "heiter", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/003_M.png?o44shg"),
68                 HourState(14, 24, 24, 0.11, 0.01, WindDirection.EAST, 20, 48, 0.66, "heiter", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/003_M.png?o44shg"),
69                 HourState(15, 25, 23, 0.17, 0.2, WindDirection.EAST, 22, 48, 0.64, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
70                 HourState(16, 24, 22, 0.23, 0.5, WindDirection.EAST, 22, 50, 0.65, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
71                 HourState(17, 24, 22, 0.27, 0.7, WindDirection.EAST, 24, 50, 0.67, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
72                 HourState(18, 24, 22, 0.34, 1.0, WindDirection.EASTNORTHEAST, 24, 48, 0.68, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
73                 HourState(19, 23, 21, 0.45, 1.6, WindDirection.EASTNORTHEAST, 22, 48, 0.72, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
74                 HourState(20, 22, 23, 0.50, 0.9, WindDirection.EASTNORTHEAST, 20, 44, 0.77, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
75                 HourState(21, 21, 22, 0.44, 0.1, WindDirection.EASTNORTHEAST, 19, 41, 0.80, "gewittrig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/016_M.png?o44shg"),
76                 HourState(22, 20, 20, 0.36, 0.09, WindDirection.EASTNORTHEAST, 17, 39, 0.84, "heiter bis wolkig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/004_M.png?o44shg"),
77                 HourState(23, 19, 19, 0.31, 0.06, WindDirection.EASTNORTHEAST, 17, 35, 0.87, "heiter bis wolkig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/004_M.png?o44shg"),
78                 HourState(24, 19, 20, 0.22, 0.03, WindDirection.EASTNORTHEAST, 15, 33, 0.89, "heiter bis wolkig", "http://cdn.static-fra.de/wetterv3/css/images/icons/weather/m/004_M.png?o44shg")
79         ))
80     }
81
82 }