Improved (or broke) tests.

This commit is contained in:
main() 2011-11-26 12:05:45 +01:00
parent 459aad2d2b
commit fa0c843f39
4 changed files with 23 additions and 5 deletions

View File

@ -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, "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.");
System.out.print(e);
e.printStackTrace();
return false;
}
}

View File

@ -151,16 +151,15 @@ public class TestWorldStuff {
Command mockCommand = mock(Command.class);
when(mockCommand.getName()).thenReturn("mv");
// Ensure that there are 3 imported. This is a fresh setup.
// As of 11/26/11, MV autodetects all default worlds.
assertEquals(3, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Ensure that there are no worlds imported. This is a fresh setup.
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Create the world
String[] normalArgs = new String[] { "create", "newworld", "normal" };
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
// We should now have one world!
assertEquals(4, creator.getCore().getMVWorldManager().getMVWorlds().size());
assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Verify
verify(mockCommandSender).sendMessage("Starting creation of world 'newworld'...");

View File

@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.test.utils;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -21,6 +22,8 @@ import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
import org.mockito.ArgumentMatcher;
import org.mockito.Matchers;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
public class MockWorldFactory {
@ -83,6 +86,14 @@ public class MockWorldFactory {
when(mockWorld.getName()).thenReturn(world);
when(mockWorld.getEnvironment()).thenReturn(env);
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));
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));
@ -112,4 +123,8 @@ public class MockWorldFactory {
public static List<World> getWorlds() {
return new ArrayList<World>(createdWorlds.values());
}
public static void clearWorlds() {
createdWorlds.clear();
}
}

View File

@ -122,6 +122,8 @@ public class TestInstanceCreator {
}
});
when(mockServer.unloadWorld(anyString(), anyBoolean())).thenReturn(true);
// Set server
Field serverfield = JavaPlugin.class.getDeclaredField("server");
serverfield.setAccessible(true);
@ -171,6 +173,8 @@ public class TestInstanceCreator {
}
FileUtils.deleteFolder(serverDirectory);
MockWorldFactory.clearWorlds();
return true;
}