Skip to content

Commit

Permalink
Created GUITestUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Apr 12, 2024
1 parent 7dce789 commit efc4e74
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gui/bukkit/src/test/java/it/angrybear/yagl/utils/GUITestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package it.angrybear.yagl.utils;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.mockito.MockedStatic;

import java.util.function.Consumer;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

/**
* A collection of utilities used to test the module
*/
public class GUITestUtils {

/**
* Mocks the returned value of {@link JavaPlugin#getProvidingPlugin(Class)} and executes the given function.
*
* @param function the function
*/
public static void mockPlugin(final @NotNull Consumer<Plugin> function) {
try (MockedStatic<JavaPlugin> ignored = mockStatic(JavaPlugin.class)) {
JavaPlugin plugin = mock(JavaPlugin.class);
when(JavaPlugin.getProvidingPlugin(any())).thenAnswer(a -> plugin);
when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));

function.accept(plugin);
}
}
}

0 comments on commit efc4e74

Please sign in to comment.