From fe499a357ed801dfe6849d3172dd27225835c5b8 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 10 May 2020 11:01:41 +0200 Subject: [PATCH] Added a few more tests --- .../slimefun4/tests/TestPluginClass.java | 70 +++++++++++++++++++ .../tests/profiles/TestPlayerBackpacks.java | 29 ++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/test/java/io/github/thebusybiscuit/slimefun4/tests/TestPluginClass.java diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/TestPluginClass.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/TestPluginClass.java new file mode 100644 index 000000000..aaa25b594 --- /dev/null +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/TestPluginClass.java @@ -0,0 +1,70 @@ +package io.github.thebusybiscuit.slimefun4.tests; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import be.seeseemelk.mockbukkit.MockBukkit; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; + +public class TestPluginClass { + + @BeforeAll + public static void load() { + MockBukkit.mock(); + MockBukkit.load(SlimefunPlugin.class); + } + + @AfterAll + public static void unload() { + MockBukkit.unmock(); + } + + @Test + public void verifyTestEnvironment() { + MinecraftVersion version = SlimefunPlugin.getMinecraftVersion(); + + Assertions.assertEquals(MinecraftVersion.UNIT_TEST, version); + Assertions.assertEquals("Unit Test Environment", version.getName()); + } + + @Test + public void testConfigs() { + Assertions.assertNotNull(SlimefunPlugin.getCfg()); + Assertions.assertNotNull(SlimefunPlugin.getResearchCfg()); + Assertions.assertNotNull(SlimefunPlugin.getItemCfg()); + } + + @Test + public void testGetters() { + Assertions.assertNotNull(SlimefunPlugin.getTicker()); + Assertions.assertNotNull(SlimefunPlugin.getVersion()); + Assertions.assertNotNull(SlimefunPlugin.getRegistry()); + Assertions.assertNotNull(SlimefunPlugin.getCommand()); + } + + @Test + public void testServicesNotNull() { + Assertions.assertNotNull(SlimefunPlugin.getLocal()); + Assertions.assertNotNull(SlimefunPlugin.getMinecraftRecipes()); + Assertions.assertNotNull(SlimefunPlugin.getItemDataService()); + Assertions.assertNotNull(SlimefunPlugin.getItemTextureService()); + Assertions.assertNotNull(SlimefunPlugin.getPermissionsService()); + Assertions.assertNotNull(SlimefunPlugin.getBlockDataService()); + Assertions.assertNotNull(SlimefunPlugin.getThirdPartySupportService()); + Assertions.assertNotNull(SlimefunPlugin.getWorldSettingsService()); + Assertions.assertNotNull(SlimefunPlugin.getGitHubService()); + Assertions.assertNotNull(SlimefunPlugin.getUpdater()); + } + + @Test + public void testListenersNotNull() { + Assertions.assertNotNull(SlimefunPlugin.getAncientAltarListener()); + Assertions.assertNotNull(SlimefunPlugin.getGrapplingHookListener()); + Assertions.assertNotNull(SlimefunPlugin.getBackpackListener()); + Assertions.assertNotNull(SlimefunPlugin.getBowListener()); + } + +} diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/profiles/TestPlayerBackpacks.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/profiles/TestPlayerBackpacks.java index 04684ece0..d514c66ca 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/profiles/TestPlayerBackpacks.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/profiles/TestPlayerBackpacks.java @@ -2,7 +2,9 @@ package io.github.thebusybiscuit.slimefun4.tests.profiles; import java.util.Optional; +import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -82,4 +84,31 @@ public class TestPlayerBackpacks { Assertions.assertFalse(profile.getBackpack(500).isPresent()); } + @Test + public void testLoadBackpackFromFile() throws InterruptedException { + Player player = server.addPlayer(); + PlayerProfile profile = TestUtilities.awaitProfile(player); + + profile.getConfig().setValue("backpacks.50.size", 27); + + for (int i = 0; i < 27; i++) { + profile.getConfig().setValue("backpacks.50.contents." + i, new ItemStack(Material.DIAMOND)); + } + + Optional optional = profile.getBackpack(50); + Assertions.assertTrue(optional.isPresent()); + + PlayerBackpack backpack = optional.get(); + Assertions.assertEquals(50, backpack.getId()); + Assertions.assertEquals(27, backpack.getSize()); + Assertions.assertEquals(-1, backpack.getInventory().firstEmpty()); + + backpack.getInventory().setItem(1, new ItemStack(Material.NETHER_STAR)); + + Assertions.assertEquals(new ItemStack(Material.DIAMOND), profile.getConfig().getItem("backpacks.50.contents.1")); + + // Saving should write it to the Config file + backpack.save(); + Assertions.assertEquals(new ItemStack(Material.NETHER_STAR), profile.getConfig().getItem("backpacks.50.contents.1")); + } }