--- /dev/null
+package net.pterodactylus.rhynodge.filters.webpages.epicgames
+
+import net.pterodactylus.rhynodge.Merger
+import net.pterodactylus.rhynodge.states.StateManagerTest.TestState
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.contains
+import org.hamcrest.Matchers.empty
+import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.instanceOf
+import org.junit.Assert.assertThrows
+import org.junit.Test
+import java.time.Instant
+
+class EpicGamesMergerTest {
+
+ @Test
+ fun `merger implements Merger interface`() {
+ assertThat(merger, instanceOf(Merger::class.java))
+ }
+
+ @Test
+ fun `merger throws exception if previous state is not a free games state`() {
+ assertThrows(IllegalArgumentException::class.java) { merger.mergeStates(TestState(), emptyState) }
+ }
+
+ @Test
+ fun `merger throws exception if current state is not a free games state`() {
+ assertThrows(IllegalArgumentException::class.java) { merger.mergeStates(emptyState, TestState()) }
+ }
+
+ @Test
+ fun `merger given two empty free game states returns an empty state`() {
+ val mergedState = merger.mergeStates(emptyState, emptyState) as FreeGamesState
+ assertThat(mergedState.games, empty())
+ }
+
+ @Test
+ fun `merging two empty states results in not-triggered state`() {
+ val mergedState = merger.mergeStates(emptyState, emptyState) as FreeGamesState
+ assertThat(mergedState.triggered(), equalTo(false))
+ }
+
+ @Test
+ fun `merging state without games into state with games returns state without games`() {
+ val mergedState = merger.mergeStates(stateWithOneGame, emptyState) as FreeGamesState
+ assertThat(mergedState.games, empty())
+ }
+
+ @Test
+ fun `merging state without games into state with games returns not-triggered state`() {
+ val mergedState = merger.mergeStates(stateWithOneGame, emptyState) as FreeGamesState
+ assertThat(mergedState.triggered(), equalTo(false))
+ }
+
+ @Test
+ fun `merging state with games into state without games returns state with games`() {
+ val mergedState = merger.mergeStates(emptyState, stateWithOneGame) as FreeGamesState
+ assertThat(mergedState.games, contains(game1))
+ }
+
+ @Test
+ fun `merging state with games into state without games returns a triggered state`() {
+ val mergedState = merger.mergeStates(emptyState, stateWithOneGame) as FreeGamesState
+ assertThat(mergedState.triggered(), equalTo(true))
+ }
+
+ @Test
+ fun `merge state with more games into state with less games returns a triggered state`() {
+ val mergedState = merger.mergeStates(stateWithOneGame, stateWithTwoGames) as FreeGamesState
+ assertThat(mergedState.triggered(), equalTo(true))
+ }
+
+ @Test
+ fun `merge state with less games into state with more games does not return a triggered state`() {
+ val mergedState = merger.mergeStates(stateWithTwoGames, stateWithOneGame) as FreeGamesState
+ assertThat(mergedState.triggered(), equalTo(false))
+ }
+
+ private val merger = EpicGamesMerger()
+
+}
+
+private val emptyState = FreeGamesState(emptySet())
+private val game1 = FreeGame("1", "i", Instant.now(), Instant.now())
+private val game2 = FreeGame("2", "i", Instant.now(), Instant.now())
+private val stateWithOneGame = FreeGamesState(setOf(game1))
+private val stateWithTwoGames = FreeGamesState(setOf(game1, game2))