Skip to content
Snippets Groups Projects
GameTest.kt 1.81 KiB
Newer Older
reblochor's avatar
reblochor committed
package model

import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.doReturn
import com.nhaarman.mockitokotlin2.whenever
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Condition
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.BeforeEach
import org.mockito.Mockito

internal class GameTest {
    var thirdDeck = Mockito.spy(Deck::class.java)
    var secondDeck = GamePile(mutableListOf(HeartCard(false, 5), ClubCard(true, 6)))

    @BeforeEach
    fun setUp() {
reblochor's avatar
reblochor committed
        doReturn(true).whenever(thirdDeck).pileCompatibilityCheck(any())
reblochor's avatar
reblochor committed
    }

    @Test
    fun place() {
        (Game.gamePiles as MutableList)[2] = thirdDeck
        (Game.gamePiles as MutableList)[1] = secondDeck

        Game.place(1, 2)
        assertThat(Game.gamePiles[1])
            .has(Condition({ deck -> deck.top == HeartCard(true, 5)}, "Top value"))
            .has(Condition({deck -> deck.cards.size == 1}, "One value"))

        assertThat(Game.gamePiles[2].top).isEqualTo(ClubCard(true, 6))
        assertThat(Game.gamePiles[2].cards).hasSize(1)

        Game.place(1,2)
        assertThat(Game.gamePiles[1])
            .has(Condition({ deck -> deck.top == null}, "Top value null"))
            .has(Condition({deck -> deck.cards.isEmpty()}, "Empty deck"))
        assertThat(Game.gamePiles[2].top).isEqualTo(HeartCard(true, 5))
        assertThat(Game.gamePiles[2].cards).hasSize(2)
    }

    @Test
    fun draw() {
        Game.visibleDeck.removeAll()
        Game.visibleDeck += HeartCard(true, 5)
        Game.visibleDeck += HeartCard(true, 6)
        Game.stack.removeAll()
        Game.draw()
        assertThat(Game.visibleDeck.cards).isEmpty()
        assertThat(Game.stack.cards).isEqualTo(mutableListOf(HeartCard(false, 6), HeartCard(false, 5)))
    }

    @Test
    fun store() {
    }
}