mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-27 18:02:37 +01:00
Add new test stuff
This commit is contained in:
parent
0e708a1f51
commit
46db76a6cc
@ -3,11 +3,10 @@ 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.test.utils.WorldCreatorMatcher;
|
||||
import com.onarandombox.MultiverseCore.utils.FileUtils;
|
||||
import junit.framework.Assert;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@ -136,4 +135,48 @@ public class TestWorldImport {
|
||||
verify(mockCommandSender, VerificationModeFactory.times(3)).sendMessage(ChatColor.AQUA + "Starting world import...");
|
||||
verify(mockCommandSender, VerificationModeFactory.times(3)).sendMessage(ChatColor.GREEN + "Complete!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWorldImportWithSeed() {
|
||||
TestInstanceCreator creator = new TestInstanceCreator();
|
||||
Server mockServer = creator.setupDefaultServerInstance();
|
||||
CommandSender mockCommandSender = creator.getCommandSender();
|
||||
// Start actual testing.
|
||||
// Pull a core instance from the server.
|
||||
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
|
||||
// Make sure Core is not null
|
||||
Assert.assertNotNull(plugin);
|
||||
|
||||
// Make sure Core is enabled
|
||||
Assert.assertTrue(plugin.isEnabled());
|
||||
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
|
||||
// Ensure that there are no worlds imported. This is a fresh setup.
|
||||
Assert.assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Init a new WorldCreatorMatcher to match our seeded world
|
||||
WorldCreator seedCreator = new WorldCreator("world");
|
||||
seedCreator.environment(World.Environment.NORMAL);
|
||||
WorldCreatorMatcher seedMatcher = new WorldCreatorMatcher(seedCreator);
|
||||
|
||||
// For this case, we're testing a seeded import, so we care about the world seed
|
||||
seedMatcher.careAboutSeeds(true);
|
||||
|
||||
|
||||
|
||||
// Import the first world.
|
||||
String[] normalArgs = new String[]{"import", "world", "normal", "-s", "gargamel"};
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
|
||||
// We should now have one world imported!
|
||||
Assert.assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Verify that the commandSender has been called 1 time.
|
||||
verify(mockCommandSender, VerificationModeFactory.times(1)).sendMessage(ChatColor.AQUA + "Starting world import...");
|
||||
verify(mockCommandSender, VerificationModeFactory.times(1)).sendMessage(ChatColor.GREEN + "Complete!");
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ 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
|
||||
// Make some fake folders to fool the fake MV 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();
|
||||
|
@ -10,19 +10,23 @@ package com.onarandombox.MultiverseCore.test.utils;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
|
||||
/**
|
||||
* Multiverse 2
|
||||
*
|
||||
* @author fernferret
|
||||
*/
|
||||
public class WorldCreatorMatcher extends ArgumentMatcher<WorldCreator> {
|
||||
private WorldCreator worldCreator;
|
||||
private boolean careAboutSeeds = false;
|
||||
private boolean careAboutGenerators = false;
|
||||
|
||||
public WorldCreatorMatcher(WorldCreator creator) {
|
||||
System.out.println("Creating NEW world matcher.(" + creator.name() + ")");
|
||||
this.worldCreator = creator;
|
||||
}
|
||||
|
||||
public void careAboutSeeds(boolean doICare) {
|
||||
this.careAboutSeeds = doICare;
|
||||
}
|
||||
|
||||
public void careAboutGenerators(boolean doICare) {
|
||||
this.careAboutGenerators = doICare;
|
||||
}
|
||||
|
||||
public boolean matches(Object creator) {
|
||||
System.out.println("Checking world creators.");
|
||||
@ -37,16 +41,13 @@ public class WorldCreatorMatcher extends ArgumentMatcher<WorldCreator> {
|
||||
} else if (!((WorldCreator) creator).environment().equals(this.worldCreator.environment())) {
|
||||
System.out.println("Checking Environments...");
|
||||
return false;
|
||||
} else if (careAboutSeeds && ((WorldCreator) creator).seed() != this.worldCreator.seed()) {
|
||||
System.out.print("Checking Seeds...");
|
||||
return false;
|
||||
} else if (careAboutGenerators && !((WorldCreator) creator).generator().equals(this.worldCreator.generator())) {
|
||||
System.out.print("Checking Gens...");
|
||||
return false;
|
||||
}
|
||||
// Don't check the seed by default, as it's randomized.
|
||||
// else if (((WorldCreator) creator).seed() != this.worldCreator.seed()) {
|
||||
// System.out.print("Checking Seeds...");
|
||||
// return false;
|
||||
// }
|
||||
// else if (!((WorldCreator) creator).generator().equals(this.worldCreator.generator())) {
|
||||
// System.out.print("Checking Gens...");
|
||||
// return false;
|
||||
// }
|
||||
System.out.println("Creators matched!!!");
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user