Fix compatibility with new tests.

Note: @main-- the new tests are balls slow for doing location generation. Like, they take 1s per check, which made the old one run for 16x16x9 seconds (making the test run take about 38.4 minutes)

For now, I've added a special case for nullterrains, which uses the new -n param to skip checking.
This commit is contained in:
Eric Stokes 2012-01-24 20:32:39 -07:00
parent 33afa4d0d7
commit 7b74384a8e
5 changed files with 100 additions and 5 deletions

View File

@ -1011,7 +1011,7 @@ public class MVWorld implements MultiverseWorld {
this.plugin.log(Level.INFO, "New Spawn for '" + this.getName() + "' is Located at: " + LocationManipulation.locationToString(configLocation));
} else {
// If it's a standard end world, let's check in a better place:
Location newerSpawn = null;
Location newerSpawn;
newerSpawn = bs.getTopBlock(new Location(w, 0, 0, 0));
if (newerSpawn != null) {
this.setSpawnLocation(newerSpawn);

View File

@ -1,3 +1,10 @@
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2012. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore.test;
import static org.junit.Assert.*;
@ -99,7 +106,7 @@ public class TestWorldProperties {
assertTrue(mvWorld.canAnimalsSpawn());
assertTrue(mvWorld.canMonstersSpawn());
assertEquals(-1, mvWorld.getCurrency());
assertEquals((Object) 0D, (Object) mvWorld.getPrice());
assertEquals(0, mvWorld.getPrice(), 0);
assertTrue(mvWorld.getHunger());
assertTrue(mvWorld.getAutoHeal());
assertTrue(mvWorld.getAdjustSpawn());
@ -107,7 +114,7 @@ public class TestWorldProperties {
assertTrue(mvWorld.isKeepingSpawnInMemory());
assertTrue(mvWorld.getBedRespawn());
assertTrue(mvWorld.getAutoLoad());
assertEquals(new Location(mvWorld.getCBWorld(), 0, 0, 0), mvWorld.getSpawnLocation());
assertEquals(new Location(mvWorld.getCBWorld(), 0, 64, 0), mvWorld.getSpawnLocation());
/* ****************************************** *
* Call some events and verify behavior

View File

@ -167,6 +167,40 @@ public class TestWorldStuff {
verify(mockServer).createWorld(Matchers.argThat(matcher));
}
@Test
public void testNullWorld() {
// Pull a core instance from the server.
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
// Make sure Core is not null
assertNotNull(plugin);
// Make sure Core is enabled
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.
assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Create the NULL world
// The safe check is now BALLS SLOW. Use the -n to skip checking.
String[] normalArgs = new String[]{ "create", "nullworld", "normal", "-n" };
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
// We should now have one world!
assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());
// Verify
verify(mockCommandSender).sendMessage("Starting creation of world 'nullworld'...");
verify(mockCommandSender).sendMessage("Complete!");
WorldCreatorMatcher matcher = new WorldCreatorMatcher(new WorldCreator("nullworld"));
verify(mockServer).createWorld(Matchers.argThat(matcher));
}
@Test
public void testModifyGameMode() {
// Pull a core instance from the server.

View File

@ -40,7 +40,50 @@ public class MockWorldFactory {
when(mockWorld.getName()).thenReturn(world);
when(mockWorld.getEnvironment()).thenReturn(env);
when(mockWorld.getWorldType()).thenReturn(type);
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 0, 0));
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 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());
}
});
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
public Block answer(InvocationOnMock invocation) throws Throwable {
Location loc;
try {
loc = (Location) invocation.getArguments()[0];
} catch (Exception e) {
return null;
}
Material blockType = Material.AIR;
Block mockBlock = mock(Block.class);
if (loc.getBlockY() < 64) {
blockType = Material.DIRT;
}
when(mockBlock.getType()).thenReturn(blockType);
when(mockBlock.getTypeId()).thenReturn(blockType.getId());
when(mockBlock.getWorld()).thenReturn(loc.getWorld());
when(mockBlock.getX()).thenReturn(loc.getBlockX());
when(mockBlock.getY()).thenReturn(loc.getBlockY());
when(mockBlock.getZ()).thenReturn(loc.getBlockZ());
when(mockBlock.getLocation()).thenReturn(loc);
when(mockBlock.isEmpty()).thenReturn(blockType == Material.AIR);
return mockBlock;
}
});
return mockWorld;
}
private static World nullWorld(String world, World.Environment env, WorldType type) {
World mockWorld = mock(World.class);
when(mockWorld.getName()).thenReturn(world);
when(mockWorld.getEnvironment()).thenReturn(env);
when(mockWorld.getWorldType()).thenReturn(type);
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
public File answer(InvocationOnMock invocation) throws Throwable {
if (!(invocation.getMock() instanceof World))
@ -60,7 +103,7 @@ public class MockWorldFactory {
}
Block mockBlock = mock(Block.class);
Material blockType = Material.AIR; // TODO we might use other materials, too
Material blockType = Material.AIR;
when(mockBlock.getType()).thenReturn(blockType);
when(mockBlock.getTypeId()).thenReturn(blockType.getId());
@ -82,6 +125,12 @@ public class MockWorldFactory {
return w;
}
public static World makeNewNullMockWorld(String world, World.Environment env, WorldType type) {
World w = nullWorld(world, env, type);
registerWorld(w);
return w;
}
public static World makeNewMockWorld(String world, World.Environment env, WorldType type, long seed,
ChunkGenerator generator) {
World mockWorld = basics(world, env, type);

View File

@ -127,6 +127,11 @@ public class TestInstanceCreator {
} catch (Exception e) {
return null;
}
// Add special case for creating null worlds.
// Not sure I like doing it this way, but this is a special case
if (arg.name().equalsIgnoreCase("nullworld")) {
return MockWorldFactory.makeNewNullMockWorld(arg.name(), arg.environment(), arg.type());
}
return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment(), arg.type());
}
});