Package be.seeseemelk.mockbukkit
Class MockBukkit
java.lang.Object
be.seeseemelk.mockbukkit.MockBukkit
Handles mocking the
Bukkit server, along with containing some handy utility methods.-
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull MockPluginCreates a mock instance of aJavaPluginimplementation.static @NotNull MockPlugincreateMockPlugin(@NotNull String pluginName) Creates a mock instance of aJavaPluginimplementation and gives you a chance to name the plugin.static @NotNull MockPlugincreateMockPlugin(@NotNull String pluginName, @NotNull String pluginVersion) Creates a mock instance of aJavaPluginimplementation and gives you a chance to name the plugin.static voidThrows an IllegalStateException when not mocked.static @Nullable ServerMockgetMock()Get the mock server instance.static @Nullable ServerMockGet the mock server instance.static booleanisMocked()Checks if Bukkit is being mocked.static <T extends org.bukkit.plugin.java.JavaPlugin>
TLoads and enables a plugin for mocking.static <T extends org.bukkit.plugin.java.JavaPlugin>
TLoads and enables a plugin for mocking.static voidLoads a plugin from a jar.static voidLoads a plugin from a jar.static <T extends org.bukkit.plugin.java.JavaPlugin>
TloadSimple(@NotNull Class<T> plugin, Object @NotNull ... parameters) Loads and enables a plugin for mocking.static <T extends org.bukkit.plugin.java.JavaPlugin>
TLoads and enables a plugin for mocking.static <T extends org.bukkit.plugin.java.JavaPlugin>
TloadWith(@NotNull Class<T> plugin, @NotNull InputStream descriptionInput, Object... parameters) Loads and enables a plugin for mocking.static <T extends org.bukkit.plugin.java.JavaPlugin>
TLoads and enables a plugin for mocking.static <T extends org.bukkit.plugin.java.JavaPlugin>
TloadWith(@NotNull Class<T> plugin, @NotNull org.bukkit.plugin.PluginDescriptionFile descriptionFile, Object @NotNull ... parameters) Loads and enables a plugin for mocking.static @NotNull ServerMockmock()Start mocking theBukkitsingleton.static <T extends ServerMock>
Tmock(T serverMockImplementation) Start mocking theBukkitsingleton.protected static voidSets the global server singleton inBukkitback to zero.static voidunmock()Unload all loaded plugins.
-
Method Details
-
setServerInstanceToNull
protected static void setServerInstanceToNull()Sets the global server singleton inBukkitback to zero. -
mock
Start mocking theBukkitsingleton. Also returns theServerMockthat was created for ease of use.- Returns:
- The created
ServerMock.
-
mock
Start mocking theBukkitsingleton. You can pass your own implementation of theServerMockinstance. The instance you passed is returned.- Type Parameters:
T- The mock implementation to use.- Parameters:
serverMockImplementation- your customServerMockimplementation.- Returns:
- The provided
ServerMock.
-
getOrCreateMock
Get the mock server instance. If no instance exists one will be created. Otherwise existing one is returned- Returns:
- The
ServerMockinstance.
-
getMock
Get the mock server instance.- Returns:
- The
ServerMockinstance ornullif none is set up yet.
-
isMocked
public static boolean isMocked()Checks if Bukkit is being mocked.- Returns:
trueif Bukkit is being mocked,falseif it is not.
-
loadJar
Loads a plugin from a jar.- Parameters:
path- Path to the jar.
-
loadJar
public static void loadJar(@NotNull @NotNull File jarFile) throws org.bukkit.plugin.InvalidPluginException Loads a plugin from a jar.- Parameters:
jarFile- Path to the jar.- Throws:
org.bukkit.plugin.InvalidPluginException- If an exception occurred while loading a plugin.
-
load
@NotNull public static <T extends org.bukkit.plugin.java.JavaPlugin> T load(@NotNull @NotNull Class<T> plugin) Loads and enables a plugin for mocking.- Type Parameters:
T- The plugin's main class to load.- Parameters:
plugin- The plugin to load for mocking.- Returns:
- An instance of the plugin's main class.
-
load
@NotNull public static <T extends org.bukkit.plugin.java.JavaPlugin> T load(@NotNull @NotNull Class<T> plugin, Object @NotNull ... parameters) Loads and enables a plugin for mocking.- Type Parameters:
T- The plugin's main class to load.- Parameters:
plugin- The plugin to load for mocking.parameters- Extra parameters to pass on to the plugin constructor.- Returns:
- An instance of the plugin's main class.
-
loadWith
@NotNull public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadWith(@NotNull @NotNull Class<T> plugin, @NotNull @NotNull org.bukkit.plugin.PluginDescriptionFile descriptionFile, Object @NotNull ... parameters) Loads and enables a plugin for mocking. It receives theplugin.ymlto use as an extraInputStreamargument.- Type Parameters:
T- The plugin's main class to load.- Parameters:
plugin- The plugin to load for mocking.descriptionFile- The plugin description file to use instead ofplugin.yml.parameters- Extra parameters to pass on to the plugin constructor.- Returns:
- An instance of the plugin's main class.
-
loadWith
@NotNull public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadWith(@NotNull @NotNull Class<T> plugin, @NotNull @NotNull InputStream descriptionInput, Object... parameters) Loads and enables a plugin for mocking. It receives theplugin.ymlto use as an extraFileargument.- Type Parameters:
T- The plugin's main class to load.- Parameters:
plugin- The plugin to load for mocking.descriptionInput- The input stream to use instead ofplugin.yml.parameters- Extra parameters to pass on to the plugin constructor.- Returns:
- An instance of the plugin's main class.
-
loadWith
@NotNull public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadWith(@NotNull @NotNull Class<T> plugin, @NotNull @NotNull File descriptionFile, Object... parameters) Loads and enables a plugin for mocking. It receives theplugin.ymlto use as an extraFileargument.- Type Parameters:
T- The plugin's main class to load.- Parameters:
plugin- The plugin to load for mocking.descriptionFile- The file to use instead ofplugin.yml.parameters- Extra parameters to pass on to the plugin constructor.- Returns:
- An instance of the plugin's main class.
-
loadWith
@NotNull public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadWith(@NotNull @NotNull Class<T> plugin, String descriptionFileName, Object... parameters) Loads and enables a plugin for mocking. It receives theplugin.ymlto use as a resource in the default package from an extraStringargument.- Type Parameters:
T- The plugin's main class to load.- Parameters:
plugin- The plugin to load for mocking.descriptionFileName- The name of theplugin.ymlfile as a system resource.parameters- Extra parameters to pass on to the plugin constructor.- Returns:
- An instance of the plugin's main class.
-
loadSimple
@NotNull public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadSimple(@NotNull @NotNull Class<T> plugin, Object @NotNull ... parameters) Loads and enables a plugin for mocking. It will not load theplugin.ymlfile, but rather it will use a mock one. This can be useful in certain multi-project plugins where one cannot always access theplugin.ymlfile easily during testing.- Type Parameters:
T- The plugin's main class to load.- Parameters:
plugin- The plugin to load for mocking.parameters- Extra parameters to pass on to the plugin constructor.- Returns:
- An instance of the plugin's main class.
-
unmock
public static void unmock()Unload all loaded plugins. -
createMockPlugin
Creates a mock instance of aJavaPluginimplementation. This plugin offers no functionality, but it does allow a plugin that might enable and disable other plugins to be tested.- Returns:
- An instance of a mock plugin.
-
createMockPlugin
Creates a mock instance of aJavaPluginimplementation and gives you a chance to name the plugin. This plugin offers no functionality, but it does allow a plugin that might enable and disable other plugins to be tested.- Parameters:
pluginName- A name of a new plugin.- Returns:
- An instance of a mock plugin.
-
createMockPlugin
@NotNull public static @NotNull MockPlugin createMockPlugin(@NotNull @NotNull String pluginName, @NotNull @NotNull String pluginVersion) Creates a mock instance of aJavaPluginimplementation and gives you a chance to name the plugin. This plugin offers no functionality, but it does allow a plugin that might enable and disable other plugins to be tested.- Parameters:
pluginName- A name of a new plugin.pluginVersion- The version of the new plugin.- Returns:
- An instance of a mock plugin.
-
ensureMocking
public static void ensureMocking()Throws an IllegalStateException when not mocked.
-