Archiviert
13
0

Add the test plugin to the plugin manager, just in case.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-10-07 21:50:07 +02:00
Ursprung c058498267
Commit 8a4982e169

Datei anzeigen

@ -6,6 +6,8 @@ import static org.mockito.Mockito.when;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -14,6 +16,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoadOrder; import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.plugin.PluginManager;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -63,6 +66,7 @@ public class SimpleCraftBukkitITCase {
Bukkit.getScheduler().callSyncMethod(FAKE_PLUGIN, new Callable<Object>() { Bukkit.getScheduler().callSyncMethod(FAKE_PLUGIN, new Callable<Object>() {
@Override @Override
public Object call() throws Exception { public Object call() throws Exception {
initializePlugin(FAKE_PLUGIN);
return null; return null;
} }
}).get(TIMEOUT_MS, TimeUnit.MILLISECONDS); }).get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
@ -106,6 +110,27 @@ public class SimpleCraftBukkitITCase {
FileUtils.copyFile(bestFile, new File(pluginDirectory, bestFile.getName())); FileUtils.copyFile(bestFile, new File(pluginDirectory, bestFile.getName()));
} }
/**
* Load a specific fake plugin.
* @param plugin - the plugin to load.
*/
@SuppressWarnings("unchecked")
private static void initializePlugin(Plugin plugin) {
PluginManager manager = Bukkit.getPluginManager();
try {
List<Plugin> plugins = (List<Plugin>) FieldUtils.readField(manager, "plugins", true);
Map<String, Plugin> lookupNames = (Map<String, Plugin>) FieldUtils.readField(manager, "lookupNames", true);
/// Associate this plugin
plugins.add(plugin);
lookupNames.put(plugin.getName(), plugin);
} catch (Exception e) {
throw new RuntimeException("Unable to access the fields of " + manager, e);
}
}
/** /**
* Create a mockable plugin for all the tests. * Create a mockable plugin for all the tests.
* @param fakePluginName - the fake plugin name. * @param fakePluginName - the fake plugin name.