From cfdabbb17650639f7f3c365b1bcfaef966f788b8 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 5 Aug 2018 20:00:23 -0700 Subject: [PATCH] Removed AboutCommand test to get a clean build. Please see my comment on the commit. Final classes can't be mocked (as far as I know) so it's kinda impossible to make a test for this one. --- .../bentobox/commands/AboutCommand.java | 6 +- .../bentobox/api/addons/AddonTest.java | 1 - .../bentobox/commands/AboutCommandTest.java | 72 ------------------- 3 files changed, 5 insertions(+), 74 deletions(-) delete mode 100644 src/test/java/world/bentobox/bentobox/commands/AboutCommandTest.java diff --git a/src/main/java/world/bentobox/bentobox/commands/AboutCommand.java b/src/main/java/world/bentobox/bentobox/commands/AboutCommand.java index 3dc87d4ad..fa9749c58 100644 --- a/src/main/java/world/bentobox/bentobox/commands/AboutCommand.java +++ b/src/main/java/world/bentobox/bentobox/commands/AboutCommand.java @@ -27,7 +27,11 @@ public class AboutCommand extends CompositeCommand { @Override public boolean execute(User user, String label, List args) { - user.sendRawMessage("About " + BentoBox.getInstance().getDescription().getName() + " v" + BentoBox.getInstance().getDescription().getVersion() + ":"); + user.sendRawMessage("About " + BentoBox + .getInstance() + .getDescription() + .getName() + " v" + + BentoBox.getInstance().getDescription().getVersion() + ":"); user.sendRawMessage("Copyright (c) 2017 - 2018 Tastybento, Poslovitch"); user.sendRawMessage("See https://www.eclipse.org/legal/epl-2.0/ for license information."); return true; diff --git a/src/test/java/world/bentobox/bentobox/api/addons/AddonTest.java b/src/test/java/world/bentobox/bentobox/api/addons/AddonTest.java index d03e22419..ab92aed2c 100644 --- a/src/test/java/world/bentobox/bentobox/api/addons/AddonTest.java +++ b/src/test/java/world/bentobox/bentobox/api/addons/AddonTest.java @@ -56,7 +56,6 @@ public class AddonTest { PluginManager pluginManager = mock(PluginManager.class); when(server.getPluginManager()).thenReturn(pluginManager); - //Bukkit.setServer(server); PowerMockito.mockStatic(Bukkit.class); when(Bukkit.getServer()).thenReturn(server); when(Bukkit.getPluginManager()).thenReturn(pluginManager); diff --git a/src/test/java/world/bentobox/bentobox/commands/AboutCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/AboutCommandTest.java deleted file mode 100644 index 37c2b6e5a..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/AboutCommandTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package world.bentobox.bentobox.commands; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginDescriptionFile; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.CommandsManager; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; - -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class}) -public class AboutCommandTest { - - private User user; - private CompositeCommand parent; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Player - Player player = mock(Player.class); - // Sometimes use: Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - UUID uuid = UUID.randomUUID(); - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(player); - User.setPlugin(plugin); - // Set up user already - User.getInstance(player); - - // Parent command has no aliases - parent = mock(CompositeCommand.class); - when(parent.getSubCommandAliases()).thenReturn(new HashMap<>()); - } - - // FIXME how to avoid NPE with getDescription() ? - /* @Test - public void testExecute() { - AboutCommand ac = new AboutCommand(parent); - assertTrue(ac.execute(user, ac.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendRawMessage("Copyright (c) 2017 - 2018 Tastybento, Poslovitch"); - Mockito.verify(user).sendRawMessage("See https://www.eclipse.org/legal/epl-2.0/ for license information."); - } */ -}