mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Added unit test for event
I'm not so sure about this. I've never writed any tests before
This commit is contained in:
parent
19133a05f9
commit
f987e6b85d
@ -2,6 +2,10 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.researches;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.events.PreCanUnlockResearchEvent;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
@ -19,6 +23,7 @@ import io.github.thebusybiscuit.slimefun4.core.researching.Research;
|
|||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
|
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
class TestResearches {
|
class TestResearches {
|
||||||
|
|
||||||
@ -182,4 +187,29 @@ class TestResearches {
|
|||||||
Assertions.assertTrue(research.canUnlock(player));
|
Assertions.assertTrue(research.canUnlock(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test PreCanUnlockResearchEvent")
|
||||||
|
void testPreCanUnlockResearchEvent() throws InterruptedException {
|
||||||
|
SlimefunPlugin.getRegistry().setResearchingEnabled(true);
|
||||||
|
|
||||||
|
NamespacedKey key = new NamespacedKey(plugin, "simple_research");
|
||||||
|
Research research = new Research(key, 250, "Test", 10);
|
||||||
|
research.register();
|
||||||
|
|
||||||
|
SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class);
|
||||||
|
Player player = server.addPlayer();
|
||||||
|
PlayerProfile profile = TestUtilities.awaitProfile(player);
|
||||||
|
SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, "RESEARCH_TEST", new CustomItem(Material.TORCH, "&bResearch Test"));
|
||||||
|
|
||||||
|
research.guideClickInteraction(guide,player,profile,sfItem,sfItem.getCategory(),0);
|
||||||
|
|
||||||
|
server.getPluginManager().assertEventFired(PreCanUnlockResearchEvent.class, event -> {
|
||||||
|
Assertions.assertEquals(player, event.getPlayer());
|
||||||
|
Assertions.assertEquals(research, event.getResearch());
|
||||||
|
Assertions.assertEquals(sfItem,event.getSlimefunItem());
|
||||||
|
Assertions.assertFalse(event.isCancelled());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user