mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 20:41:59 +01:00
Improved (or broke) tests.
This commit is contained in:
parent
459aad2d2b
commit
fa0c843f39
@ -266,7 +266,7 @@ public class WorldManager implements MVWorldManager {
|
|||||||
this.plugin.log(Level.SEVERE, "You can go politely explain your situation in #multiverse on esper.net");
|
this.plugin.log(Level.SEVERE, "You can go politely explain your situation in #multiverse on esper.net");
|
||||||
this.plugin.log(Level.SEVERE, "But from here, it looks like your folder is oddly named.");
|
this.plugin.log(Level.SEVERE, "But from here, it looks like your folder is oddly named.");
|
||||||
this.plugin.log(Level.SEVERE, "This world has been removed from Multiverse-Core so your best bet is to go delete the folder by hand. Sorry.");
|
this.plugin.log(Level.SEVERE, "This world has been removed from Multiverse-Core so your best bet is to go delete the folder by hand. Sorry.");
|
||||||
System.out.print(e);
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,16 +151,15 @@ public class TestWorldStuff {
|
|||||||
Command mockCommand = mock(Command.class);
|
Command mockCommand = mock(Command.class);
|
||||||
when(mockCommand.getName()).thenReturn("mv");
|
when(mockCommand.getName()).thenReturn("mv");
|
||||||
|
|
||||||
// Ensure that there are 3 imported. This is a fresh setup.
|
// Ensure that there are no worlds imported. This is a fresh setup.
|
||||||
// As of 11/26/11, MV autodetects all default worlds.
|
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||||
assertEquals(3, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
|
||||||
|
|
||||||
// Create the world
|
// Create the world
|
||||||
String[] normalArgs = new String[] { "create", "newworld", "normal" };
|
String[] normalArgs = new String[] { "create", "newworld", "normal" };
|
||||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||||
|
|
||||||
// We should now have one world!
|
// We should now have one world!
|
||||||
assertEquals(4, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
verify(mockCommandSender).sendMessage("Starting creation of world 'newworld'...");
|
verify(mockCommandSender).sendMessage("Starting creation of world 'newworld'...");
|
||||||
|
@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.test.utils;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -21,6 +22,8 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.mockito.ArgumentMatcher;
|
import org.mockito.ArgumentMatcher;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.Matchers;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
public class MockWorldFactory {
|
public class MockWorldFactory {
|
||||||
|
|
||||||
@ -83,6 +86,14 @@ public class MockWorldFactory {
|
|||||||
when(mockWorld.getName()).thenReturn(world);
|
when(mockWorld.getName()).thenReturn(world);
|
||||||
when(mockWorld.getEnvironment()).thenReturn(env);
|
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 0, 0));
|
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 0, 0));
|
||||||
|
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||||
|
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
if (!(invocation.getMock() instanceof World))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
World thiss = (World) invocation.getMock();
|
||||||
|
return new File(TestInstanceCreator.serverDirectory, thiss.getName());
|
||||||
|
}});
|
||||||
LocationMatcherAbove matchWorldAbove = new LocationMatcherAbove(new Location(mockWorld, 0, 0, 0));
|
LocationMatcherAbove matchWorldAbove = new LocationMatcherAbove(new Location(mockWorld, 0, 0, 0));
|
||||||
LocationMatcherBelow matchWorldBelow = new LocationMatcherBelow(new Location(mockWorld, 0, 0, 0));
|
LocationMatcherBelow matchWorldBelow = new LocationMatcherBelow(new Location(mockWorld, 0, 0, 0));
|
||||||
when(mockWorld.getBlockAt(Matchers.argThat(matchWorldAbove))).thenReturn(new MockBlock(new Location(mockWorld, 0, 0, 0), Material.AIR));
|
when(mockWorld.getBlockAt(Matchers.argThat(matchWorldAbove))).thenReturn(new MockBlock(new Location(mockWorld, 0, 0, 0), Material.AIR));
|
||||||
@ -112,4 +123,8 @@ public class MockWorldFactory {
|
|||||||
public static List<World> getWorlds() {
|
public static List<World> getWorlds() {
|
||||||
return new ArrayList<World>(createdWorlds.values());
|
return new ArrayList<World>(createdWorlds.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void clearWorlds() {
|
||||||
|
createdWorlds.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,8 @@ public class TestInstanceCreator {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
when(mockServer.unloadWorld(anyString(), anyBoolean())).thenReturn(true);
|
||||||
|
|
||||||
// Set server
|
// Set server
|
||||||
Field serverfield = JavaPlugin.class.getDeclaredField("server");
|
Field serverfield = JavaPlugin.class.getDeclaredField("server");
|
||||||
serverfield.setAccessible(true);
|
serverfield.setAccessible(true);
|
||||||
@ -171,6 +173,8 @@ public class TestInstanceCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileUtils.deleteFolder(serverDirectory);
|
FileUtils.deleteFolder(serverDirectory);
|
||||||
|
MockWorldFactory.clearWorlds();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user