Multiverse-Core/src/test/java/com/onarandombox/MultiverseCore/TestDebugMode.java

76 lines
2.5 KiB
Java
Raw Normal View History

2011-10-21 02:36:33 +02:00
/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
package com.onarandombox.MultiverseCore;
2011-10-21 02:36:33 +02:00
import com.onarandombox.MultiverseCore.api.Core;
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
2011-10-21 02:36:33 +02:00
import junit.framework.Assert;
2011-10-22 01:48:28 +02:00
import org.bukkit.Server;
2011-10-21 02:36:33 +02:00
import org.bukkit.command.Command;
2011-10-22 01:48:28 +02:00
import org.bukkit.command.CommandSender;
2011-10-21 02:36:33 +02:00
import org.bukkit.plugin.Plugin;
2011-10-22 01:48:28 +02:00
import org.junit.After;
import org.junit.Before;
2011-10-21 02:36:33 +02:00
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
2011-10-21 02:36:33 +02:00
public class TestDebugMode {
2011-11-25 18:02:41 +01:00
TestInstanceCreator creator;
Server mockServer;
CommandSender mockCommandSender;
2011-10-22 01:48:28 +02:00
@Before
public void setUp() throws Exception {
2011-11-25 18:02:41 +01:00
creator = new TestInstanceCreator();
assertTrue(creator.setUp());
mockServer = creator.getServer();
mockCommandSender = creator.getCommandSender();
}
@After
public void tearDown() throws Exception {
creator.tearDown();
2011-10-22 01:48:28 +02:00
}
@Test
2011-10-21 02:36:33 +02:00
public void testEnableDebugMode() {
2011-10-22 01:48:28 +02:00
// Pull a core instance from the server.
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
2012-02-04 14:22:55 +01:00
Core core = (Core) plugin;
2011-10-22 01:48:28 +02:00
// Make sure Core is not null
2011-11-25 18:02:41 +01:00
assertNotNull(plugin);
2011-10-22 01:48:28 +02:00
// Make sure Core is enabled
2011-11-25 18:02:41 +01:00
assertTrue(plugin.isEnabled());
2011-10-22 01:48:28 +02:00
// Make a fake server folder to fool MV into thinking a world folder exists.
File serverDirectory = new File(creator.getCore().getServerFolder(), "world");
serverDirectory.mkdirs();
// Initialize a fake command
Command mockCommand = mock(Command.class);
when(mockCommand.getName()).thenReturn("mv");
// Assert debug mode is off
2012-02-04 14:22:55 +01:00
Assert.assertEquals(0, core.getMVConfig().getGlobalDebug());
2011-10-22 01:48:28 +02:00
// Send the debug command.
2011-11-25 18:02:41 +01:00
String[] debugArgs = new String[] { "debug", "3" };
2011-10-22 01:48:28 +02:00
plugin.onCommand(mockCommandSender, mockCommand, "", debugArgs);
2012-02-04 14:22:55 +01:00
Assert.assertEquals(3, core.getMVConfig().getGlobalDebug());
2011-10-21 02:36:33 +02:00
}
}