diff --git a/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java b/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java index 76222e5f..e363cf97 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/TestInstanceCreator.java @@ -41,6 +41,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyBoolean; +import static org.mockito.Mockito.anyLong; import static org.mockito.Mockito.*; public class TestInstanceCreator { @@ -59,7 +62,21 @@ public class TestInstanceCreator { MockGateway.MOCK_STANDARD_METHODS = false; - core = PowerMockito.spy(new MultiverseCore()); + TestPluginLoader pluginLoader = new TestPluginLoader(); + + // Initialize the Mock server. + mockServer = mock(Server.class); + when(mockServer.getName()).thenReturn("TestBukkit"); + Logger.getLogger("Minecraft").setParent(Util.logger); + when(mockServer.getLogger()).thenReturn(Util.logger); + when(mockServer.getWorldContainer()).thenReturn(worldsDirectory); + + // Return a fake PDF file. + PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Multiverse-Core", "2.2-Test", + "com.onarandombox.MultiverseCore.MultiverseCore")); + when(pdf.getAuthors()).thenReturn(new ArrayList()); + + core = PowerMockito.spy(new MultiverseCore(pluginLoader, mockServer, pdf, pluginDirectory, new File(pluginDirectory, "testPluginFile"))); PowerMockito.doAnswer(new Answer() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { @@ -70,11 +87,6 @@ public class TestInstanceCreator { // Let's let all MV files go to bin/test doReturn(pluginDirectory).when(core).getDataFolder(); - // Return a fake PDF file. - PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Multiverse-Core", "2.2-Test", - "com.onarandombox.MultiverseCore.MultiverseCore")); - when(pdf.getAuthors()).thenReturn(new ArrayList()); - doReturn(pdf).when(core).getDescription(); doReturn(true).when(core).isEnabled(); doReturn(Util.logger).when(core).getLogger(); core.setServerFolder(serverDirectory); @@ -101,12 +113,7 @@ public class TestInstanceCreator { Util.log("Creating world-folder: " + worldSkylandsFile.getAbsolutePath()); worldSkylandsFile.mkdirs(); - // Initialize the Mock server. - mockServer = mock(Server.class); - when(mockServer.getName()).thenReturn("TestBukkit"); - Logger.getLogger("Minecraft").setParent(Util.logger); - when(mockServer.getLogger()).thenReturn(Util.logger); - when(mockServer.getWorldContainer()).thenReturn(worldsDirectory); + // Give the server some worlds when(mockServer.getWorld(anyString())).thenAnswer(new Answer() { diff --git a/src/test/java/com/onarandombox/MultiverseCore/utils/TestPluginLoader.java b/src/test/java/com/onarandombox/MultiverseCore/utils/TestPluginLoader.java new file mode 100644 index 00000000..7c96a456 --- /dev/null +++ b/src/test/java/com/onarandombox/MultiverseCore/utils/TestPluginLoader.java @@ -0,0 +1,49 @@ +package com.onarandombox.MultiverseCore.utils; + +import org.bukkit.event.Event; +import org.bukkit.event.Listener; +import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginLoader; +import org.bukkit.plugin.RegisteredListener; +import org.bukkit.plugin.UnknownDependencyException; + +import java.io.File; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +public class TestPluginLoader implements PluginLoader { + + @Override + public Plugin loadPlugin(File file) throws InvalidPluginException, UnknownDependencyException { + return null; + } + + @Override + public PluginDescriptionFile getPluginDescription(File file) throws InvalidDescriptionException { + return null; + } + + @Override + public Pattern[] getPluginFileFilters() { + return new Pattern[0]; + } + + @Override + public Map, Set> createRegisteredListeners(Listener listener, Plugin plugin) { + return null; + } + + @Override + public void enablePlugin(Plugin plugin) { + + } + + @Override + public void disablePlugin(Plugin plugin) { + + } +}