mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
unit test for config phase events
This commit is contained in:
parent
87e837a4b1
commit
4d956baa56
2 changed files with 98 additions and 0 deletions
|
|
@ -0,0 +1,49 @@
|
||||||
|
package xyz.alexcrea.cuanvil.api.event;
|
||||||
|
|
||||||
|
import io.delilaheve.CustomAnvil;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockbukkit.mockbukkit.MockBukkit;
|
||||||
|
import org.mockbukkit.mockbukkit.matcher.plugin.PluginManagerFiredEventClassMatcher;
|
||||||
|
import xyz.alexcrea.cuanvil.tests.SharedOnlyMockBukkit;
|
||||||
|
|
||||||
|
public class CAConfigReadyEventTest extends SharedOnlyMockBukkit {
|
||||||
|
|
||||||
|
private CustomAnvil plugin;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startup() {
|
||||||
|
boolean beforeStart = PluginManagerFiredEventClassMatcher
|
||||||
|
.hasNotFiredEventInstance(CAConfigReadyEvent.class)
|
||||||
|
.matches(server.getPluginManager());
|
||||||
|
|
||||||
|
Assertions.assertTrue(beforeStart, "Somehow, event fired before plugin being loaded ?");
|
||||||
|
|
||||||
|
// Load the plugin
|
||||||
|
plugin = MockBukkit.load(CustomAnvil.class);
|
||||||
|
|
||||||
|
boolean postStart = PluginManagerFiredEventClassMatcher
|
||||||
|
.hasNotFiredEventInstance(CAConfigReadyEvent.class)
|
||||||
|
.matches(server.getPluginManager());
|
||||||
|
|
||||||
|
Assertions.assertTrue(postStart, "Event fired before plugin finished being loaded");
|
||||||
|
|
||||||
|
// Config load phase
|
||||||
|
server.getScheduler().performOneTick();
|
||||||
|
boolean postConfig = PluginManagerFiredEventClassMatcher
|
||||||
|
.hasFiredEventInstance(CAConfigReadyEvent.class)
|
||||||
|
.matches(server.getPluginManager());
|
||||||
|
|
||||||
|
Assertions.assertTrue(postConfig, "Event did not fire after the config phase");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void pluginTeardown() {
|
||||||
|
if (plugin != null) {
|
||||||
|
server.getPluginManager().disablePlugin(plugin);
|
||||||
|
plugin = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package xyz.alexcrea.cuanvil.api.event;
|
||||||
|
|
||||||
|
import io.delilaheve.CustomAnvil;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockbukkit.mockbukkit.MockBukkit;
|
||||||
|
import org.mockbukkit.mockbukkit.matcher.plugin.PluginManagerFiredEventClassMatcher;
|
||||||
|
import xyz.alexcrea.cuanvil.tests.SharedOnlyMockBukkit;
|
||||||
|
|
||||||
|
public class CAEnchantRegistryReadyEventTest extends SharedOnlyMockBukkit {
|
||||||
|
|
||||||
|
private CustomAnvil plugin;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startup() {
|
||||||
|
boolean beforeStart = PluginManagerFiredEventClassMatcher
|
||||||
|
.hasNotFiredEventInstance(CAEnchantRegistryReadyEvent.class)
|
||||||
|
.matches(server.getPluginManager());
|
||||||
|
|
||||||
|
Assertions.assertTrue(beforeStart, "Somehow, event fired before plugin being loaded ?");
|
||||||
|
|
||||||
|
// Load the plugin
|
||||||
|
plugin = MockBukkit.load(CustomAnvil.class);
|
||||||
|
|
||||||
|
boolean postStart = PluginManagerFiredEventClassMatcher
|
||||||
|
.hasNotFiredEventInstance(CAEnchantRegistryReadyEvent.class)
|
||||||
|
.matches(server.getPluginManager());
|
||||||
|
|
||||||
|
Assertions.assertTrue(postStart, "Event fired before plugin finished being loaded");
|
||||||
|
|
||||||
|
// Config load phase
|
||||||
|
server.getScheduler().performOneTick();
|
||||||
|
boolean postConfig = PluginManagerFiredEventClassMatcher
|
||||||
|
.hasFiredEventInstance(CAEnchantRegistryReadyEvent.class)
|
||||||
|
.matches(server.getPluginManager());
|
||||||
|
|
||||||
|
Assertions.assertTrue(postConfig, "Event did not fire after the config phase");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void pluginTeardown() {
|
||||||
|
if (plugin != null) {
|
||||||
|
server.getPluginManager().disablePlugin(plugin);
|
||||||
|
plugin = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue