fun `summary contains date of earliest movie`() {
val movieState = MovieState(
setOf(
- Movie("1", "", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 2, 12, 18, 45), "", "")) },
- Movie("2", "", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 3, 12, 15, 30), "", "")) },
- Movie("3", "", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 2, 11, 21, 15), "", "")) }
+ Movie("1", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 12, 18, 45), "", ""))),
+ Movie("2", "", "", listOf(Performance(LocalDateTime.of(2024, 3, 12, 15, 30), "", ""))),
+ Movie("3", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 11, 21, 15), "", "")))
), emptySet()
)
assertThat(movieState.output(Reaction("", null, null, null)).summary(), containsString("2024-02-11"))
val document = Jsoup.parse(html)
assertThat(
document.select("section.daily-programmes li.performance")
- .map { performance -> listOf(".name", ".time", ".type").map { performance.select(it).text() }.joinToString(" - ")}, contains(
+ .map { performance -> listOf(".name", ".time", ".type").map { performance.select(it).text() }.joinToString(" - ") }, contains(
"Movie 1 - 18:45 - 2D OV", "Movie 1 - 13:30 - 2D", "Movie 1 - 18:15 - 2D OmeU"
)
)
dateTimeString.substring(11..12).toInt(),
)
-private fun movie(name: String, imageUrl: String, description: String = "", vararg times: String) = Movie(name, imageUrl, description).apply {
- times.map(::dateTime).map { Performance(it, "", "https://link/$it") }.forEach(this::addPerformance)
-}
+private fun movie(name: String, imageUrl: String, description: String = "", vararg times: String) =
+ times.map(::dateTime)
+ .map { Performance(it, "", "https://link/$it") }
+ .let { Movie(name, imageUrl, description, it) }
-private fun movie(name: String, imageUrl: String, description: String = "", vararg timesAndTypes: Pair<String, String>) = Movie(name, imageUrl, description).apply {
- timesAndTypes.map { Performance(it.first.let(::dateTime), it.second, "https://link/${it.first}") }.forEach(this::addPerformance)
-}
+private fun movie(name: String, imageUrl: String, description: String = "", vararg timesAndTypes: Pair<String, String>) =
+ timesAndTypes.map { Performance(it.first.let(::dateTime), it.second, "https://link/${it.first}") }
+ .let { Movie(name, imageUrl, description, it) }
@Test
fun `movies with different performances are still considered the same movie`() {
- val oldState = MovieState(setOf(Movie("1", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", "")) }))
- val newState = MovieState(setOf(Movie("1", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 2, 15, 14, 30), "", "")) }))
+ val oldState = MovieState(setOf(Movie("1", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", "")))))
+ val newState = MovieState(setOf(Movie("1", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 15, 14, 30), "", "")))))
val mergedState = merger.mergeStates(oldState, newState) as MovieState
assertThat(mergedState.newMovies, empty())
}
@Test
fun `merging states with movies starting the same day does not create a triggered state`() {
- val oldState = MovieState(setOf(Movie("1", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", "")) }))
- val newState = MovieState(setOf(Movie("1", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 2, 14, 14, 30), "", "")) }))
+ val oldState = MovieState(setOf(Movie("1", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", "")))))
+ val newState = MovieState(setOf(Movie("1", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 14, 14, 30), "", "")))))
val mergedState = merger.mergeStates(oldState, newState) as MovieState
assertThat(mergedState.triggered(), equalTo(false))
}
@Test
fun `merging states with movies starting on different days does create a triggered state`() {
- val oldState = MovieState(setOf(Movie("1", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", "")) }))
- val newState = MovieState(setOf(Movie("1", "").apply { addPerformance(Performance(LocalDateTime.of(2024, 2, 15, 14, 30), "", "")) }))
+ val oldState = MovieState(setOf(Movie("1", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", "")))))
+ val newState = MovieState(setOf(Movie("1", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 15, 14, 30), "", "")))))
val mergedState = merger.mergeStates(oldState, newState) as MovieState
assertThat(mergedState.triggered(), equalTo(true))
}
@Test
fun `merging states where movies have different performances but still on the same day does not create a triggered state`() {
- val oldState = MovieState(setOf(Movie("1", "").apply {
- addPerformance(Performance(LocalDateTime.of(2024, 2, 14, 14, 30), "", ""))
- addPerformance(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", ""))
- }))
- val newState = MovieState(setOf(Movie("1", "").apply {
- addPerformance(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", ""))
- }))
+ val oldState = MovieState(setOf(Movie("1", "", "", listOf(
+ Performance(LocalDateTime.of(2024, 2, 14, 14, 30), "", ""),
+ Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", "")
+ ))))
+ val newState = MovieState(setOf(Movie("1", "", "", listOf(
+ Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", "")
+ ))))
val mergedState = merger.mergeStates(oldState, newState) as MovieState
assertThat(mergedState.triggered(), equalTo(false))
}
@Test
fun `merging states where movies have different performances and are not on the same day anymore does create a triggered state`() {
- val oldState = MovieState(setOf(Movie("1", "").apply {
- addPerformance(Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", ""))
- addPerformance(Performance(LocalDateTime.of(2024, 2, 15, 14, 30), "", ""))
- }))
- val newState = MovieState(setOf(Movie("1", "").apply {
- addPerformance(Performance(LocalDateTime.of(2024, 2, 15, 14, 30), "", ""))
- }))
+ val oldState = MovieState(setOf(Movie("1", "", "", listOf(
+ Performance(LocalDateTime.of(2024, 2, 14, 18, 45), "", ""),
+ Performance(LocalDateTime.of(2024, 2, 15, 14, 30), "", "")
+ ))))
+ val newState = MovieState(setOf(Movie("1", "", "", listOf(
+ Performance(LocalDateTime.of(2024, 2, 15, 14, 30), "", "")
+ ))))
val mergedState = merger.mergeStates(oldState, newState) as MovieState
assertThat(mergedState.triggered(), equalTo(true))
}