mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-12-28 11:58:36 +01:00
Add Broken tests
This commit is contained in:
parent
b867df7315
commit
d1f51acb1c
4
.gitignore
vendored
4
.gitignore
vendored
@ -34,3 +34,7 @@
|
||||
|
||||
# Fern's utils
|
||||
uploadtoserver.sh
|
||||
|
||||
# Testing files:
|
||||
debug.log
|
||||
|
||||
|
32
pom.xml
32
pom.xml
@ -193,12 +193,40 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- End of Economy Dependencies -->
|
||||
<!-- Start of JUnit Dependencies -->
|
||||
<!-- Start of Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- End of JUnit Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-easymock</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.4.9</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- End of Test Dependencies -->
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -33,6 +33,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -52,6 +53,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
public static boolean EnforceGameModes;
|
||||
public static boolean PrefixChat;
|
||||
public static boolean BedRespawn;
|
||||
private File testConfigDirectory;
|
||||
private PluginDescriptionFile testDescriptionFile;
|
||||
|
||||
|
||||
@Override
|
||||
@ -124,6 +127,28 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
if (this.testConfigDirectory != null) {
|
||||
return this.testConfigDirectory;
|
||||
}
|
||||
return super.getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginDescriptionFile getDescription() {
|
||||
if (this.testDescriptionFile != null) {
|
||||
return this.testDescriptionFile;
|
||||
}
|
||||
return super.getDescription(); //To change body of overridden methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
public void setTestMode(File configDir, PluginDescriptionFile descriptionFile) {
|
||||
this.testConfigDirectory = configDir;
|
||||
this.testDescriptionFile = descriptionFile;
|
||||
}
|
||||
|
||||
public FileConfiguration getMVConfiguration() {
|
||||
return this.multiverseConfig;
|
||||
}
|
||||
@ -230,6 +255,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
|
||||
/** Function to Register all the Events needed. */
|
||||
private void registerEvents() {
|
||||
System.out.print(getServer().getName());
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
// pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Highest, this); // Low so it acts above any other.
|
||||
pm.registerEvent(Event.Type.PLAYER_TELEPORT, this.playerListener, Priority.Highest, this); // Cancel Teleports if needed.
|
||||
@ -451,6 +477,9 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private String getAuthors() {
|
||||
String authors = "";
|
||||
ArrayList<String> auths = this.getDescription().getAuthors();
|
||||
if(auths.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (auths.size() == 1) {
|
||||
return auths.get(0);
|
||||
|
@ -141,4 +141,12 @@ public interface MVWorldManager {
|
||||
* @return A valid {@link PurgeWorlds}.
|
||||
*/
|
||||
public PurgeWorlds getWorldPurger();
|
||||
|
||||
/**
|
||||
* Gets the world players will spawn in on first join.
|
||||
* Currently this always returns worlds.get(0) from Bukkit.
|
||||
*
|
||||
* @return A Multiverse world that players will spawn in or null if no MV world has been set.
|
||||
*/
|
||||
public MultiverseWorld getSpawnWorld();
|
||||
}
|
||||
|
@ -438,4 +438,8 @@ public class WorldManager implements MVWorldManager {
|
||||
this.plugin.log(Level.SEVERE, "Could not save worlds.yml. Please check your settings.");
|
||||
}
|
||||
}
|
||||
|
||||
public MultiverseWorld getSpawnWorld() {
|
||||
return this.getMVWorld(this.plugin.getServer().getWorlds().get(0));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.bukkit.World;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class TestMockWorld {
|
||||
private World mockWorld;
|
||||
private World mockNetherWorld;
|
||||
@Test
|
||||
public void testWorldInit() {
|
||||
// Initialize a fake world and world_nether.
|
||||
this.mockWorld = PowerMockito.mock(World.class);
|
||||
when(this.mockWorld.getName()).thenReturn("world");
|
||||
when(this.mockWorld.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
|
||||
this.mockNetherWorld = PowerMockito.mock(World.class);
|
||||
when(this.mockNetherWorld.getName()).thenReturn("world_nether");
|
||||
when(this.mockNetherWorld.getEnvironment()).thenReturn(World.Environment.NETHER);
|
||||
|
||||
// Test the mock world objects
|
||||
Assert.assertEquals(this.mockWorld.getName(), "world");
|
||||
Assert.assertEquals(this.mockNetherWorld.getName(), "world_nether");
|
||||
verify(this.mockWorld).getName();
|
||||
verify(this.mockNetherWorld).getName();
|
||||
|
||||
// Test the environments
|
||||
Assert.assertEquals(this.mockWorld.getEnvironment(), World.Environment.NORMAL);
|
||||
Assert.assertEquals(this.mockNetherWorld.getEnvironment(), World.Environment.NETHER);
|
||||
verify(this.mockWorld).getEnvironment();
|
||||
verify(this.mockNetherWorld).getEnvironment();
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.onarandombox.MultiverseCore.test;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import junit.framework.Assert;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({PluginManager.class, MultiverseCore.class, Permission.class})
|
||||
public class TestWorldImport {
|
||||
ConsoleCommandSender mockCommandSender;
|
||||
private World mockWorld;
|
||||
private World mockNetherWorld;
|
||||
private List<World> worldList;
|
||||
private Server mockServer;
|
||||
private PluginManager mockPluginManager;
|
||||
private PluginLoader pluginLoader;
|
||||
MultiverseCore core;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Initialize a fake console.
|
||||
this.mockCommandSender = mock(ConsoleCommandSender.class);
|
||||
|
||||
// Initialize a fake world and world_nether.
|
||||
this.mockWorld = mock(World.class);
|
||||
when(this.mockWorld.getName()).thenReturn("world");
|
||||
when(this.mockWorld.getEnvironment()).thenReturn(World.Environment.NORMAL);
|
||||
|
||||
this.mockNetherWorld = mock(World.class);
|
||||
when(this.mockNetherWorld.getName()).thenReturn("world_nether");
|
||||
when(this.mockNetherWorld.getEnvironment()).thenReturn(World.Environment.NETHER);
|
||||
|
||||
// Initialize our fake worldlist.
|
||||
this.worldList = new ArrayList<World>();
|
||||
this.worldList.add(mockWorld);
|
||||
|
||||
|
||||
JavaPlugin[] plugins = new JavaPlugin[]{core};
|
||||
|
||||
PowerMockito.whenNew(Permission.class).withArguments("Test").thenThrow(new Exception("Permission created exception"));
|
||||
Method addPermissionMethod = PowerMockito.method(PluginManager.class, "addPermission", Permission.class);
|
||||
Constructor permissionConst = PowerMockito.constructor(Permission.class, String.class, String.class, PermissionDefault.class);
|
||||
PowerMockito.suppress(permissionConst);
|
||||
Permission p = new Permission("Test", "test", PermissionDefault.OP);
|
||||
|
||||
|
||||
// Mock the Plugin Manager
|
||||
this.mockPluginManager = PowerMockito.mock(PluginManager.class);
|
||||
when(this.mockPluginManager.getPlugins()).thenReturn(plugins);
|
||||
when(this.mockPluginManager.getPlugin("Multiverse-Core")).thenReturn(core);
|
||||
|
||||
mockPluginManager.addPermission(new Permission(""));
|
||||
|
||||
|
||||
// Initialize our server.
|
||||
this.mockServer = mock(Server.class);
|
||||
when(this.mockServer.getWorld("world")).thenReturn(mockWorld);
|
||||
when(this.mockServer.getWorlds()).thenReturn(worldList);
|
||||
when(this.mockServer.getPluginManager()).thenReturn(this.mockPluginManager);
|
||||
when(this.mockServer.getName()).thenReturn("FernCraft");
|
||||
|
||||
|
||||
PluginDescriptionFile pdf = new PluginDescriptionFile("Multiverse-Core", "2.1-Test", "com.onarandombox.MultiverseCore.MultiverseCore");
|
||||
this.core = PowerMockito.spy(new MultiverseCore());
|
||||
doReturn(this.mockServer).when(core).getServer();
|
||||
doReturn(new File(".")).when(core).getDataFolder();
|
||||
doReturn(pdf).when(core).getDescription();
|
||||
core.onLoad();
|
||||
// Enable it.
|
||||
core.onEnable();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestWorldImport() {
|
||||
|
||||
|
||||
// Start actual testing.
|
||||
// Create a core instance.
|
||||
Plugin plugin = this.mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
||||
// Make sure Core is not null
|
||||
Assert.assertNotNull(plugin);
|
||||
// Make sure core is actually a multiverse core
|
||||
|
||||
// Initialize a fake command
|
||||
Command mockCommand = mock(Command.class);
|
||||
when(mockCommand.getName()).thenReturn("mv");
|
||||
String[] normalArgs = new String[]{"import", "world", "normal"};
|
||||
String[] netherArgs = new String[]{"import", "world_nether", "nether"};
|
||||
|
||||
Assert.assertEquals(0, this.core.getMVWorldManager().getMVWorlds().size());
|
||||
|
||||
// Import the first world.
|
||||
plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);
|
||||
|
||||
Assert.assertEquals(1, this.core.getMVWorldManager().getMVWorlds().size());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user