diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestDebugMode.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestDebugMode.java index ac6d120f..107fd517 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestDebugMode.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestDebugMode.java @@ -9,15 +9,15 @@ package com.onarandombox.MultiverseCore.test; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.test.utils.MVCoreFactory; +import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; import com.onarandombox.MultiverseCore.utils.FileUtils; import junit.framework.Assert; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permission; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldImport.java b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldImport.java index f3eacd0d..47625ac9 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldImport.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/TestWorldImport.java @@ -1,6 +1,8 @@ package com.onarandombox.MultiverseCore.test; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.test.utils.MVCoreFactory; +import com.onarandombox.MultiverseCore.test.utils.TestInstanceCreator; import com.onarandombox.MultiverseCore.utils.FileUtils; import junit.framework.Assert; import org.bukkit.Bukkit; @@ -15,6 +17,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.internal.verification.VerificationModeFactory; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -55,6 +58,11 @@ public class TestWorldImport { Server mockServer = creator.setupDefaultServerInstance(); CommandSender mockCommandSender = creator.getCommandSender(); + // Make sure the world directory do NOT exist + if (new File(MVCoreFactory.serverDirectory, "world").exists()) { + new File(MVCoreFactory.serverDirectory, "world").delete(); + } + // Start actual testing. // Pull a core instance from the server. Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core"); @@ -90,13 +98,6 @@ public class TestWorldImport { // Pull a core instance from the server. Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core"); - // Make a fake server folder to fool MV into thinking a world folder exists. - File worldDirectory = new File(creator.getCore().getServerFolder(), "world"); - worldDirectory.mkdirs(); - File worldNetherDirectory = new File(creator.getCore().getServerFolder(), "world_nether"); - worldNetherDirectory.mkdirs(); - - // Make sure Core is not null Assert.assertNotNull(plugin); @@ -106,29 +107,33 @@ public class TestWorldImport { // Initialize a fake command Command mockCommand = mock(Command.class); when(mockCommand.getName()).thenReturn("mv"); - String[] normalArgs = new String[]{"import", "world", "normal"}; - String[] netherArgs = new String[]{"import", "world_nether", "nether"}; - - // Send the debug command. - String[] debugArgs = new String[]{"debug", "3"}; - plugin.onCommand(mockCommandSender, mockCommand, "", debugArgs); + // Ensure that there are no worlds imported. This is a fresh setup. Assert.assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size()); // Import the first world. + String[] normalArgs = new String[]{"import", "world", "normal"}; plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs); - verify(mockCommandSender).sendMessage(ChatColor.AQUA + "Starting world import..."); - verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Complete!"); // We should now have one world imported! Assert.assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size()); // Import the second world. + String[] netherArgs = new String[]{"import", "world_nether", "nether"}; plugin.onCommand(mockCommandSender, mockCommand, "", netherArgs); -// verify(mockCommandSender).sendMessage(ChatColor.AQUA + "Starting world import..."); -// verify(mockCommandSender).sendMessage(ChatColor.GREEN + "Complete!"); // We should now have 2 worlds imported! Assert.assertEquals(2, creator.getCore().getMVWorldManager().getMVWorlds().size()); + + // Import the third world. + String[] skyArgs = new String[]{"import", "world_skylands", "skylands"}; + plugin.onCommand(mockCommandSender, mockCommand, "", skyArgs); + + // We should now have 2 worlds imported! + Assert.assertEquals(3, creator.getCore().getMVWorldManager().getMVWorlds().size()); + + // Verify that the commandSender has been called 3 times. + verify(mockCommandSender, VerificationModeFactory.times(3)).sendMessage(ChatColor.AQUA + "Starting world import..."); + verify(mockCommandSender, VerificationModeFactory.times(3)).sendMessage(ChatColor.GREEN + "Complete!"); } } diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/MVCoreFactory.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MVCoreFactory.java similarity index 96% rename from src/test/java/com/onarandombox/MultiverseCore/test/MVCoreFactory.java rename to src/test/java/com/onarandombox/MultiverseCore/test/utils/MVCoreFactory.java index 65b58195..6e33ef4e 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/MVCoreFactory.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MVCoreFactory.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore.test.utils; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.plugin.PluginDescriptionFile; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/MockBlock.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java similarity index 99% rename from src/test/java/com/onarandombox/MultiverseCore/test/MockBlock.java rename to src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java index 92f96e84..3eb3b18d 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/MockBlock.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBlock.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore.test.utils; import org.bukkit.Chunk; import org.bukkit.Location; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/MockBukkitServer.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBukkitServer.java similarity index 91% rename from src/test/java/com/onarandombox/MultiverseCore/test/MockBukkitServer.java rename to src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBukkitServer.java index 9fda1a71..784fd0f1 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/MockBukkitServer.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockBukkitServer.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore.test.utils; /** * Multiverse 2 diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/MockServerFactory.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockServerFactory.java similarity index 95% rename from src/test/java/com/onarandombox/MultiverseCore/test/MockServerFactory.java rename to src/test/java/com/onarandombox/MultiverseCore/test/utils/MockServerFactory.java index 7467a3b7..a7410214 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/MockServerFactory.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockServerFactory.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore.test.utils; import org.bukkit.Server; import org.bukkit.WorldCreator; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/MockWorldFactory.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java similarity index 98% rename from src/test/java/com/onarandombox/MultiverseCore/test/MockWorldFactory.java rename to src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java index aefbaa91..667a16c0 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/MockWorldFactory.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/MockWorldFactory.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore.test.utils; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestCommandSender.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java similarity index 99% rename from src/test/java/com/onarandombox/MultiverseCore/test/TestCommandSender.java rename to src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java index 0a88d3e4..29a8007c 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestCommandSender.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestCommandSender.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore.test.utils; import org.bukkit.ChatColor; import org.bukkit.Server; diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/TestInstanceCreator.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java similarity index 92% rename from src/test/java/com/onarandombox/MultiverseCore/test/TestInstanceCreator.java rename to src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java index 9327a56e..3ab9da73 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/TestInstanceCreator.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/TestInstanceCreator.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore.test.utils; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.Bukkit; @@ -18,6 +18,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.mockito.Matchers; import org.powermock.api.mockito.PowerMockito; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -46,6 +47,11 @@ public class TestInstanceCreator { when(mockPluginManager.getPlugins()).thenReturn(plugins); when(mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core); + // Make some fake folders to fool the fake server into thinking these worlds exist + new File(core.getServerFolder(), "world").mkdirs(); + new File(core.getServerFolder(), "world_nether").mkdirs(); + new File(core.getServerFolder(), "world_skylands").mkdirs(); + // Initialize the Mock Worlds World mockWorld = worldFactory.makeNewMockWorld("world", World.Environment.NORMAL); World mockNetherWorld = worldFactory.makeNewMockWorld("world_nether", World.Environment.NETHER); diff --git a/src/test/java/com/onarandombox/MultiverseCore/test/WorldCreatorMatcher.java b/src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java similarity index 97% rename from src/test/java/com/onarandombox/MultiverseCore/test/WorldCreatorMatcher.java rename to src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java index 475ff38e..73a263aa 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/test/WorldCreatorMatcher.java +++ b/src/test/java/com/onarandombox/MultiverseCore/test/utils/WorldCreatorMatcher.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.test; +package com.onarandombox.MultiverseCore.test.utils; import org.bukkit.WorldCreator; import org.mockito.ArgumentMatcher;