mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-29 22:13:46 +01:00
Fixed deprecated use (since it's going away in 1.11)
* MultiverseCore constructor shouldn't be deprecated, it just needed a fix.
* Removed TestPluginLoader, it should have been mocked anyway.
* New constructor takes a JavaPluginLoader instad of a PluginLoader, so
we'll have to mock.
You can't win, Java. If you make it `final`, I shall become more powerful
than you can possibly imagine.
(cherry picked from commit 3364709e53
)
This commit is contained in:
parent
43309dc841
commit
727a064a3b
@ -104,6 +104,7 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||||||
import org.bukkit.plugin.PluginLoader;
|
import org.bukkit.plugin.PluginLoader;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.mcstats.Metrics;
|
import org.mcstats.Metrics;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -137,16 +138,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This is for unit testing.
|
* This is for unit testing.
|
||||||
* @deprecated
|
* @param loader The PluginLoader to use.
|
||||||
* @param loader deprecated
|
* @param description The Description file to use.
|
||||||
* @param server deprecated
|
* @param dataFolder The folder that other datafiles can be found in.
|
||||||
* @param description deprecated
|
* @param file The location of the plugin.
|
||||||
* @param dataFolder deprecated
|
|
||||||
* @param file deprecated
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public MultiverseCore(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
|
||||||
public MultiverseCore(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file) {
|
super(loader, description, dataFolder, file);
|
||||||
super(loader, server, description, dataFolder, file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -30,7 +31,7 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class, JavaPluginLoader.class})
|
||||||
public class TestDebugMode {
|
public class TestDebugMode {
|
||||||
TestInstanceCreator creator;
|
TestInstanceCreator creator;
|
||||||
Server mockServer;
|
Server mockServer;
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.entity.Zombie;
|
|||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -29,7 +30,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class, JavaPluginLoader.class})
|
||||||
public class TestEntitySpawnRules {
|
public class TestEntitySpawnRules {
|
||||||
TestInstanceCreator creator;
|
TestInstanceCreator creator;
|
||||||
MultiverseCore core;
|
MultiverseCore core;
|
||||||
|
@ -7,6 +7,7 @@ import org.bukkit.World.Environment;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -20,7 +21,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class, JavaPluginLoader.class })
|
||||||
public class TestModifyCommand {
|
public class TestModifyCommand {
|
||||||
TestInstanceCreator creator;
|
TestInstanceCreator creator;
|
||||||
Server mockServer;
|
Server mockServer;
|
||||||
|
@ -37,6 +37,7 @@ import org.bukkit.event.weather.WeatherChangeEvent;
|
|||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -57,7 +58,7 @@ import static org.mockito.Mockito.*;
|
|||||||
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class,
|
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class,
|
||||||
WeatherChangeEvent.class, ThunderChangeEvent.class, AsyncPlayerChatEvent.class,
|
WeatherChangeEvent.class, ThunderChangeEvent.class, AsyncPlayerChatEvent.class,
|
||||||
PlayerJoinEvent.class, PlayerRespawnEvent.class, EntityRegainHealthEvent.class,
|
PlayerJoinEvent.class, PlayerRespawnEvent.class, EntityRegainHealthEvent.class,
|
||||||
FoodLevelChangeEvent.class, WorldManager.class, PluginDescriptionFile.class })
|
FoodLevelChangeEvent.class, WorldManager.class, PluginDescriptionFile.class, JavaPluginLoader.class })
|
||||||
public class TestWorldProperties {
|
public class TestWorldProperties {
|
||||||
private TestInstanceCreator creator;
|
private TestInstanceCreator creator;
|
||||||
private MultiverseCore core;
|
private MultiverseCore core;
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.entity.Sheep;
|
import org.bukkit.entity.Sheep;
|
||||||
import org.bukkit.entity.Zombie;
|
import org.bukkit.entity.Zombie;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -22,7 +23,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class })
|
@PrepareForTest({ MultiverseCore.class, PluginDescriptionFile.class, JavaPluginLoader.class })
|
||||||
public class TestWorldPurger {
|
public class TestWorldPurger {
|
||||||
TestInstanceCreator creator;
|
TestInstanceCreator creator;
|
||||||
MultiverseCore core;
|
MultiverseCore core;
|
||||||
|
@ -23,6 +23,7 @@ import org.bukkit.permissions.Permission;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -38,7 +39,8 @@ import static junit.framework.Assert.*;
|
|||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class, PluginDescriptionFile.class })
|
@PrepareForTest({ PluginManager.class, MultiverseCore.class, Permission.class, Bukkit.class, WorldManager.class,
|
||||||
|
PluginDescriptionFile.class, JavaPluginLoader.class })
|
||||||
public class TestWorldStuff {
|
public class TestWorldStuff {
|
||||||
|
|
||||||
private TestInstanceCreator creator;
|
private TestInstanceCreator creator;
|
||||||
|
@ -25,12 +25,15 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.Matchers;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.powermock.api.easymock.PowerMock;
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.MockGateway;
|
import org.powermock.core.MockGateway;
|
||||||
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -62,10 +65,10 @@ public class TestInstanceCreator {
|
|||||||
|
|
||||||
MockGateway.MOCK_STANDARD_METHODS = false;
|
MockGateway.MOCK_STANDARD_METHODS = false;
|
||||||
|
|
||||||
TestPluginLoader pluginLoader = new TestPluginLoader();
|
|
||||||
|
|
||||||
// Initialize the Mock server.
|
// Initialize the Mock server.
|
||||||
mockServer = mock(Server.class);
|
mockServer = mock(Server.class);
|
||||||
|
JavaPluginLoader mockPluginLoader = PowerMock.createMock(JavaPluginLoader.class);
|
||||||
|
Whitebox.setInternalState(mockPluginLoader, "server", mockServer);
|
||||||
when(mockServer.getName()).thenReturn("TestBukkit");
|
when(mockServer.getName()).thenReturn("TestBukkit");
|
||||||
Logger.getLogger("Minecraft").setParent(Util.logger);
|
Logger.getLogger("Minecraft").setParent(Util.logger);
|
||||||
when(mockServer.getLogger()).thenReturn(Util.logger);
|
when(mockServer.getLogger()).thenReturn(Util.logger);
|
||||||
@ -75,8 +78,7 @@ public class TestInstanceCreator {
|
|||||||
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Multiverse-Core", "2.2-Test",
|
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Multiverse-Core", "2.2-Test",
|
||||||
"com.onarandombox.MultiverseCore.MultiverseCore"));
|
"com.onarandombox.MultiverseCore.MultiverseCore"));
|
||||||
when(pdf.getAuthors()).thenReturn(new ArrayList<String>());
|
when(pdf.getAuthors()).thenReturn(new ArrayList<String>());
|
||||||
|
core = PowerMockito.spy(new MultiverseCore(mockPluginLoader, pdf, pluginDirectory, new File(pluginDirectory, "testPluginFile")));
|
||||||
core = PowerMockito.spy(new MultiverseCore(pluginLoader, mockServer, pdf, pluginDirectory, new File(pluginDirectory, "testPluginFile")));
|
|
||||||
PowerMockito.doAnswer(new Answer<Void>() {
|
PowerMockito.doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
package com.onarandombox.MultiverseCore.utils;
|
|
||||||
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.plugin.InvalidDescriptionException;
|
|
||||||
import org.bukkit.plugin.InvalidPluginException;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
|
||||||
import org.bukkit.plugin.PluginLoader;
|
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
|
||||||
import org.bukkit.plugin.UnknownDependencyException;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class TestPluginLoader implements PluginLoader {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Plugin loadPlugin(File file) throws InvalidPluginException, UnknownDependencyException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PluginDescriptionFile getPluginDescription(File file) throws InvalidDescriptionException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pattern[] getPluginFileFilters() {
|
|
||||||
return new Pattern[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<Class<? extends Event>, Set<RegisteredListener>> createRegisteredListeners(Listener listener, Plugin plugin) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enablePlugin(Plugin plugin) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disablePlugin(Plugin plugin) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user