76 lines
2.5 KiB
Java
76 lines
2.5 KiB
Java
/******************************************************************************
|
|
* 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;
|
|
|
|
import com.onarandombox.MultiverseCore.api.MVCore;
|
|
import com.onarandombox.MultiverseCore.utils.TestInstanceCreator;
|
|
import junit.framework.Assert;
|
|
import org.bukkit.Server;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.plugin.Plugin;
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
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;
|
|
|
|
public class TestDebugMode {
|
|
TestInstanceCreator creator;
|
|
Server mockServer;
|
|
CommandSender mockCommandSender;
|
|
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
creator = new TestInstanceCreator();
|
|
assertTrue(creator.setUp());
|
|
mockServer = creator.getServer();
|
|
mockCommandSender = creator.getCommandSender();
|
|
}
|
|
|
|
@After
|
|
public void tearDown() throws Exception {
|
|
creator.tearDown();
|
|
}
|
|
|
|
@Test
|
|
public void testEnableDebugMode() {
|
|
// Pull a core instance from the server.
|
|
Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");
|
|
MVCore core = (MVCore) plugin;
|
|
|
|
// Make sure Core is not null
|
|
assertNotNull(plugin);
|
|
|
|
// Make sure Core is enabled
|
|
assertTrue(plugin.isEnabled());
|
|
|
|
// 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
|
|
Assert.assertEquals(0, core.getMVConfig().getGlobalDebug());
|
|
|
|
// Send the debug command.
|
|
String[] debugArgs = new String[] { "debug", "3" };
|
|
plugin.onCommand(mockCommandSender, mockCommand, "", debugArgs);
|
|
|
|
Assert.assertEquals(3, core.getMVConfig().getGlobalDebug());
|
|
}
|
|
}
|