Class MockBukkit

java.lang.Object
be.seeseemelk.mockbukkit.MockBukkit

public class MockBukkit extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull MockPlugin
    Creates a mock instance of a JavaPlugin implementation.
    static @NotNull MockPlugin
    createMockPlugin(@NotNull String pluginName)
    Creates a mock instance of a JavaPlugin implementation and gives you a chance to name the plugin.
    static void
    Throws an IllegalStateException when not mocked.
    static ServerMock
    Get the mock server instance.
    static ServerMock
    Get the mock server instance.
    static boolean
    Checks if Bukkit is being mocked.
    static <T extends org.bukkit.plugin.java.JavaPlugin>
    T
    load(Class<T> plugin)
    Loads and enables a plugin for mocking.
    static <T extends org.bukkit.plugin.java.JavaPlugin>
    T
    load(Class<T> plugin, Object... parameters)
    Loads and enables a plugin for mocking.
    static void
    loadJar(File jarFile)
    Loads a plugin from a jar.
    static void
    Loads a plugin from a jar.
    static <T extends org.bukkit.plugin.java.JavaPlugin>
    T
    loadSimple(Class<T> plugin, Object... parameters)
    Loads and enables a plugin for mocking.
    static <T extends org.bukkit.plugin.java.JavaPlugin>
    T
    loadWith(Class<T> plugin, File descriptionFile, Object... parameters)
    Loads and enables a plugin for mocking.
    static <T extends org.bukkit.plugin.java.JavaPlugin>
    T
    loadWith(Class<T> plugin, InputStream descriptionInput, Object... parameters)
    Loads and enables a plugin for mocking.
    static <T extends org.bukkit.plugin.java.JavaPlugin>
    T
    loadWith(Class<T> plugin, String descriptionFileName, Object... parameters)
    Loads and enables a plugin for mocking.
    static <T extends org.bukkit.plugin.java.JavaPlugin>
    T
    loadWith(Class<T> plugin, org.bukkit.plugin.PluginDescriptionFile descriptionFile, Object... parameters)
    Loads and enables a plugin for mocking.
    static ServerMock
    Start mocking the Bukkit singleton.
    static <T extends ServerMock>
    T
    mock(T serverMockImplementation)
    Start mocking the Bukkit singleton.
    protected static void
    Sets the global server singleton in Bukkit back to zero.
    static void
    Unload all loaded plugins.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setServerInstanceToNull

      protected static void setServerInstanceToNull()
      Sets the global server singleton in Bukkit back to zero.
    • mock

      public static ServerMock mock()
      Start mocking the Bukkit singleton. Also returns the ServerMock that was created for ease of use.
      Returns:
      The created ServerMock.
    • mock

      public static <T extends ServerMock> T mock(T serverMockImplementation)
      Start mocking the Bukkit singleton. You can pass your own implementation of the ServerMock instance. The instance you passed is returned.
      Type Parameters:
      T - The mock implementation to use.
      Parameters:
      serverMockImplementation - your custom ServerMock implementation.
      Returns:
      The provided ServerMock.
    • getOrCreateMock

      public static ServerMock getOrCreateMock()
      Get the mock server instance. If no instance exists one will be created. Otherwise existing one is returned
      Returns:
      The ServerMock instance.
    • getMock

      public static ServerMock getMock()
      Get the mock server instance.
      Returns:
      The ServerMock instance or null if none is set up yet.
    • isMocked

      public static boolean isMocked()
      Checks if Bukkit is being mocked.
      Returns:
      true if Bukkit is being mocked, false if it is not.
    • loadJar

      public static void loadJar(String path)
      Loads a plugin from a jar.
      Parameters:
      path - Path to the jar.
    • loadJar

      public static void loadJar(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

      public static <T extends org.bukkit.plugin.java.JavaPlugin> T load(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

      public static <T extends org.bukkit.plugin.java.JavaPlugin> T load(Class<T> plugin, Object... 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

      public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadWith(Class<T> plugin, org.bukkit.plugin.PluginDescriptionFile descriptionFile, Object... parameters)
      Loads and enables a plugin for mocking. It receives the plugin.yml to use as an extra InputStream argument.
      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 of plugin.yml.
      parameters - Extra parameters to pass on to the plugin constructor.
      Returns:
      An instance of the plugin's main class.
    • loadWith

      public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadWith(Class<T> plugin, InputStream descriptionInput, Object... parameters)
      Loads and enables a plugin for mocking. It receives the plugin.yml to use as an extra File argument.
      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 of plugin.yml.
      parameters - Extra parameters to pass on to the plugin constructor.
      Returns:
      An instance of the plugin's main class.
    • loadWith

      public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadWith(Class<T> plugin, File descriptionFile, Object... parameters)
      Loads and enables a plugin for mocking. It receives the plugin.yml to use as an extra File argument.
      Type Parameters:
      T - The plugin's main class to load.
      Parameters:
      plugin - The plugin to load for mocking.
      descriptionFile - The file to use instead of plugin.yml.
      parameters - Extra parameters to pass on to the plugin constructor.
      Returns:
      An instance of the plugin's main class.
    • loadWith

      public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadWith(Class<T> plugin, String descriptionFileName, Object... parameters)
      Loads and enables a plugin for mocking. It receives the plugin.yml to use as a resource in the default package from an extra String argument.
      Type Parameters:
      T - The plugin's main class to load.
      Parameters:
      plugin - The plugin to load for mocking.
      descriptionFileName - The name of the plugin.yml file as a system resource.
      parameters - Extra parameters to pass on to the plugin constructor.
      Returns:
      An instance of the plugin's main class.
    • loadSimple

      public static <T extends org.bukkit.plugin.java.JavaPlugin> T loadSimple(Class<T> plugin, Object... parameters)
      Loads and enables a plugin for mocking. It will not load the plugin.yml file, but rather it will use a mock one. This can be useful in certain multi-project plugins where one cannot always access the plugin.yml file 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

      @NotNull public static @NotNull MockPlugin createMockPlugin()
      Creates a mock instance of a JavaPlugin implementation. 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

      @NotNull public static @NotNull MockPlugin createMockPlugin(@NotNull @NotNull String pluginName)
      Creates a mock instance of a JavaPlugin implementation 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.
    • ensureMocking

      public static void ensureMocking()
      Throws an IllegalStateException when not mocked.