From b3cda21fe50e50f7046351a59d694496a9712153 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Wed, 30 Jul 2014 03:49:37 +0200 Subject: [PATCH] Correct the WrappedGameProfile unit test. --- .../comphenix/protocol/error/PluginContext.java | 15 +++++++++------ .../protocol/wrappers/WrappedGameProfileTest.java | 12 ++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/error/PluginContext.java b/ProtocolLib/src/main/java/com/comphenix/protocol/error/PluginContext.java index 3b0cba40..2727c75b 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/error/PluginContext.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/error/PluginContext.java @@ -40,18 +40,21 @@ public final class PluginContext { /** * Lookup the plugin that this method invocation belongs to, and return its file name. * @param element - the method invocation. - * @return Pluing name, or NULL if not found. + * @return Plugin name, or NULL if not found. * */ public static String getPluginName(StackTraceElement element) { try { + if (Bukkit.getServer() == null) + return null; CodeSource codeSource = Class.forName(element.getClassName()).getProtectionDomain().getCodeSource(); - + if (codeSource != null) { String encoding = codeSource.getLocation().getPath(); File path = new File(URLDecoder.decode(encoding, "UTF-8")); - - if (folderContains(getPluginFolder(), path)) { + File plugins = getPluginFolder(); + + if (plugins != null && folderContains(plugins, path)) { return path.getName(); } } @@ -88,12 +91,12 @@ public final class PluginContext { /** * Retrieve the folder that contains every plugin on the server. - * @return Folder with every plugin. + * @return Folder with every plugin, or NULL if Bukkit has not been initialized yet. */ private static File getPluginFolder() { File folder = pluginFolder; - if (folder == null) { + if (folder == null && Bukkit.getServer() != null) { Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); if (plugins.length > 0) { diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java index 20af71f0..29633383 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/wrappers/WrappedGameProfileTest.java @@ -2,10 +2,13 @@ package com.comphenix.protocol.wrappers; import static org.junit.Assert.*; +import java.util.UUID; + import org.junit.BeforeClass; import org.junit.Test; import com.comphenix.protocol.BukkitInitialization; +import com.google.common.base.Charsets; public class WrappedGameProfileTest { @BeforeClass @@ -13,15 +16,16 @@ public class WrappedGameProfileTest { BukkitInitialization.initializePackage(); } + @SuppressWarnings("deprecation") @Test public void testSkinUpdate() { - final String nullUUID = "00000000-0000-0000-0000-000000000000"; + final UUID uuid = UUID.nameUUIDFromBytes("123".getBytes(Charsets.UTF_8)); + assertEquals(null, new WrappedGameProfile((String)null, "Test").getId()); - assertEquals(nullUUID, new WrappedGameProfile("", "Test").getId()); - assertEquals(nullUUID, new WrappedGameProfile("0", "Test").getId()); - assertEquals(nullUUID, new WrappedGameProfile("00-0", "Test").getId()); + assertEquals(uuid, new WrappedGameProfile("123", "Test").getUUID()); } + @SuppressWarnings("deprecation") @Test(expected = IllegalArgumentException.class) public void testNullFailure() { new WrappedGameProfile((String)null, null);