-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Begin test about shift inventory animation
- Loading branch information
1 parent
84af5c9
commit 134ccf6
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/test/kotlin/com/github/rushyverse/api/gui/load/ShiftInventoryLoadingAnimationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.github.rushyverse.api.gui.load | ||
|
||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
import kotlin.time.Duration.Companion.milliseconds | ||
import kotlinx.coroutines.cancelAndJoin | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
import org.bukkit.inventory.Inventory | ||
import org.bukkit.inventory.ItemStack | ||
|
||
class ShiftInventoryLoadingAnimationTest { | ||
|
||
private lateinit var inventory: Inventory | ||
|
||
@BeforeTest | ||
fun onBefore() { | ||
inventory = mockk { | ||
val contents = arrayOfNulls<ItemStack>(9 * 3) | ||
every { size } returns contents.size | ||
every { getContents() } returns contents | ||
every { setContents(any()) } answers { | ||
val items = firstArg<Array<ItemStack?>>() | ||
items.forEachIndexed { index, itemStack -> | ||
contents[index] = itemStack | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `should not change inventory if initialize is empty`() { | ||
val delay = 10.milliseconds | ||
val animation = ShiftInventoryLoadingAnimation<Unit>( | ||
initialize = { emptySequence() }, | ||
shift = 1, | ||
delay = delay | ||
) | ||
|
||
runBlocking { | ||
val job = launch { animation.loading(Unit, inventory) } | ||
delay(delay * 3) | ||
job.cancelAndJoin() | ||
} | ||
|
||
inventory.contents shouldBe arrayOfNulls(inventory.size) | ||
} | ||
|
||
@Test | ||
fun `should just initialize if shift is zero`() = runBlocking { | ||
val delay = 10.milliseconds | ||
val items = Array(inventory.size) { mockk<ItemStack>() } | ||
|
||
val animation = ShiftInventoryLoadingAnimation<Unit>( | ||
initialize = { items.asSequence() }, | ||
shift = 0, | ||
delay = delay | ||
) | ||
|
||
val job = launch { animation.loading(Unit, inventory) } | ||
delay(delay * 3) | ||
job.cancelAndJoin() | ||
|
||
inventory.contents.toList() shouldContainExactly items.toList() | ||
} | ||
} |