-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dce789
commit efc4e74
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
gui/bukkit/src/test/java/it/angrybear/yagl/utils/GUITestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |