-
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.
Add MainTest and update pom.xml for testing
Created a new MainTest class in the test directory and added configurations for JUnit and Mockito to pom.xml for testing purposes. Also made slight adjustments to the Main class in the src/main directory to ensure compatibility with the testing environment.
- Loading branch information
1 parent
a65967e
commit f60f019
Showing
3 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
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
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
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,71 @@ | ||
package org.gecko.wauh; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Server; | ||
import org.bukkit.command.ConsoleCommandSender; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.gecko.wauh.data.ConfigurationManager; | ||
import org.gecko.wauh.listeners.*; | ||
import org.gecko.wauh.commands.SetRadiusLimitCommand; | ||
import org.gecko.wauh.commands.StopWauh; | ||
import org.gecko.wauh.commands.ToggleRemovalView; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
public class MainTest { | ||
|
||
private Main plugin; | ||
private FileConfiguration config; | ||
private ConfigurationManager configManager; | ||
private Server server; | ||
private PluginManager pluginManager; | ||
private ConsoleCommandSender sender; | ||
|
||
@Test | ||
public void testOnEnable() { | ||
|
||
plugin = Mockito.spy(Main.class); | ||
server = mock(Server.class); | ||
pluginManager = mock(PluginManager.class); | ||
sender = mock(ConsoleCommandSender.class); | ||
config = mock(FileConfiguration.class); | ||
configManager = new ConfigurationManager(plugin); | ||
|
||
// Mock Plugin methods | ||
when(plugin.getServer()).thenReturn(server); | ||
when(server.getPluginManager()).thenReturn(pluginManager); | ||
when(server.getConsoleSender()).thenReturn(sender); | ||
|
||
when(plugin.getCommand(anyString())).thenReturn(null); | ||
|
||
// Mock ConfigurationManager methods | ||
when(config.getInt(anyString(), anyInt())).thenReturn(10); | ||
|
||
// Mock Main methods | ||
when(plugin.getConfigManager()).thenReturn(configManager); | ||
when(configManager.getConfig()).thenReturn(config); | ||
|
||
plugin.onEnable(); | ||
|
||
// Verify methods called | ||
verify(plugin, times(6)).getServer(); | ||
verify(server, times(6)).getPluginManager(); | ||
verify(server, times(2)).getConsoleSender(); | ||
verify(sender, times(2)).sendMessage(anyString()); | ||
verify(plugin, times(3)).getCommand(anyString()); | ||
|
||
// Verify listeners registration | ||
verify(pluginManager).registerEvents(any(BucketListener.class), eq(plugin)); | ||
verify(pluginManager).registerEvents(any(BarrierListener.class), eq(plugin)); | ||
verify(pluginManager).registerEvents(any(BedrockListener.class), eq(plugin)); | ||
verify(pluginManager).registerEvents(any(WaterBucketListener.class), eq(plugin)); | ||
verify(pluginManager).registerEvents(any(TNTListener.class), eq(plugin)); | ||
verify(pluginManager).registerEvents(any(CreeperListener.class), eq(plugin)); | ||
} | ||
} |