when(mockServer.createWorld(Matchers.isA(WorldCreator.class))).thenAnswer(
new Answer<World>() {
@Override
public World answer(InvocationOnMock invocation) throws Throwable {
WorldCreator arg;
try {
arg = (WorldCreator) invocation.getArguments()[0];
} 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());
}
});
when(mockServer.unloadWorld(anyString(), anyBoolean())).thenReturn(true);
// add mock scheduler
BukkitScheduler mockScheduler = mock(BukkitScheduler.class);
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class), anyLong())).
thenAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
Runnable arg;
try {
arg = (Runnable) invocation.getArguments()[1];
} catch (Exception e) {
return null;
}
arg.run();
return null;
}});
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class))).
thenAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
Runnable arg;
try {
arg = (Runnable) invocation.getArguments()[1];
} catch (Exception e) {
return null;
}
arg.run();
return null;
}});
when(mockServer.getScheduler()).thenReturn(mockScheduler);
// Set server