diff options
author | Helfull <admin@helfull.de> | 2023-10-16 12:50:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-16 12:50:19 +0200 |
commit | f62eda7516fc377b83e467746dff084701cda679 (patch) | |
tree | fcf9263404a84af4dc9a4f83155b99337790ab16 /src | |
parent | 5f2375401042c9d8a3289237eea50b97ba515c19 (diff) | |
download | skyhanni-f62eda7516fc377b83e467746dff084701cda679.tar.gz skyhanni-f62eda7516fc377b83e467746dff084701cda679.tar.bz2 skyhanni-f62eda7516fc377b83e467746dff084701cda679.zip |
fix(UnitTests): double registration of blocks/items (#578)
Fixed unit tests #578
Diffstat (limited to 'src')
-rw-r--r-- | src/test/java/at/hannibal2/skyhanni/test/BootstrapHook.kt | 13 | ||||
-rw-r--r-- | src/test/java/at/hannibal2/skyhanni/test/ItemUtilsTest.kt | 34 |
2 files changed, 43 insertions, 4 deletions
diff --git a/src/test/java/at/hannibal2/skyhanni/test/BootstrapHook.kt b/src/test/java/at/hannibal2/skyhanni/test/BootstrapHook.kt index 3aff72c2b..ec385d0da 100644 --- a/src/test/java/at/hannibal2/skyhanni/test/BootstrapHook.kt +++ b/src/test/java/at/hannibal2/skyhanni/test/BootstrapHook.kt @@ -14,15 +14,20 @@ import java.util.concurrent.locks.ReentrantLock class BootstrapHook : BeforeAllCallback, Extension { companion object { private val LOCK: Lock = ReentrantLock() + private var bootstrapped = false } override fun beforeAll(p0: ExtensionContext?) { LOCK.lock() try { - Bootstrap::class.java.getDeclaredField("alreadyRegistered").makeAccessible().set(null, true) - Block.registerBlocks() - BlockFire.init() - Item.registerItems() + if (!bootstrapped) { + bootstrapped = true + + Bootstrap::class.java.getDeclaredField("alreadyRegistered").makeAccessible().set(null, true) + Block.registerBlocks() + BlockFire.init() + Item.registerItems() + } } finally { LOCK.unlock() } diff --git a/src/test/java/at/hannibal2/skyhanni/test/ItemUtilsTest.kt b/src/test/java/at/hannibal2/skyhanni/test/ItemUtilsTest.kt new file mode 100644 index 000000000..0ac8cc8de --- /dev/null +++ b/src/test/java/at/hannibal2/skyhanni/test/ItemUtilsTest.kt @@ -0,0 +1,34 @@ +package at.hannibal2.skyhanni.test + +import at.hannibal2.skyhanni.utils.ItemUtils +import org.junit.jupiter.api.Test + +class ItemUtilsTest { + + val items: MutableMap<String, Pair<String, Int>> = mutableMapOf( + "§5Hoe of Greatest Tilling" to Pair("§5Hoe of Greatest Tilling", 1), + "§fSilver medal §8x2" to Pair("§fSilver medal", 2), + "§aJacob's Ticket §8x32" to Pair("§aJacob's Ticket", 32), + "§9Delicate V" to Pair("§9Delicate V", 1), + " §81x §9Enchanted Sugar Cane" to Pair("§9Enchanted Sugar Cane", 1), + "§6Gold medal" to Pair("§6Gold medal", 1), + " §8+§319k §7Farming XP" to Pair("§7Farming XP", 19_000), + " §8+§215 §7Garden Experience" to Pair("§7Garden Experience", 15), + " §8+§c21 Copper" to Pair("Copper", 21), + " §8+§b10 Bits" to Pair("Bits", 10), + " §8+§37.2k §7Farming XP" to Pair("§7Farming XP", 7_200), + ) + + @Test + fun testReadItemAmount() { + for ((itemString, expected) in items) { + val results = ItemUtils.readItemAmount(itemString) + assert(results != null) { + "Could not read item '$itemString'" + } + assert(results?.equals(expected) == true) { + "'${results.toString()}' does not match '$expected'" + } + } + } +}
\ No newline at end of file |