Fixed Tests

This commit is contained in:
Rsl1122 2017-11-05 19:38:11 +02:00
parent e1c648fb9d
commit e129ac0990
13 changed files with 103 additions and 59 deletions

View File

@ -152,6 +152,8 @@ public class Plan extends BukkitPlugin implements IPlan {
Log.infoColor("§a----------------------------------------"); Log.infoColor("§a----------------------------------------");
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/"); Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
Log.infoColor("§a----------------------------------------"); Log.infoColor("§a----------------------------------------");
} else {
Log.info("You're using the latest version.");
} }
} catch (IOException e) { } catch (IOException e) {
Log.error("Failed to check newest version number"); Log.error("Failed to check newest version number");

View File

@ -74,6 +74,8 @@ public class PlanBungee extends BungeePlugin implements IPlan {
Log.infoColor("§a----------------------------------------"); Log.infoColor("§a----------------------------------------");
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/"); Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
Log.infoColor("§a----------------------------------------"); Log.infoColor("§a----------------------------------------");
} else {
Log.info("You're using the latest version.");
} }
} catch (IOException e) { } catch (IOException e) {
Log.error("Failed to check newest version number"); Log.error("Failed to check newest version number");

View File

@ -4,8 +4,9 @@
*/ */
package main.java.com.djrapitops.plan; package main.java.com.djrapitops.plan;
import org.bukkit.configuration.ConfigurationSection; import com.djrapitops.plugin.api.config.Config;
import org.bukkit.configuration.file.FileConfiguration; import com.djrapitops.plugin.api.config.ConfigNode;
import com.djrapitops.plugin.utilities.Verify;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -34,18 +35,18 @@ public class WorldAliasSettings {
* @return Map: Original name, Alias * @return Map: Original name, Alias
*/ */
public Map<String, String> getAliases() { public Map<String, String> getAliases() {
ConfigurationSection aliasSect = getAliasSection(); ConfigNode aliasSect = getAliasSection();
Map<String, String> aliasMap = new HashMap<>(); Map<String, String> aliasMap = new HashMap<>();
for (String world : aliasSect.getKeys(false)) { for (Map.Entry<String, ConfigNode> world : aliasSect.getChildren().entrySet()) {
aliasMap.put(world, aliasSect.getString(world)); aliasMap.put(world.getKey(), world.getValue().getString());
} }
return aliasMap; return aliasMap;
} }
private ConfigurationSection getAliasSection() { private ConfigNode getAliasSection() {
FileConfiguration config = plugin.getConfig(); Config config = plugin.getMainConfig();
return config.getConfigurationSection(Settings.WORLD_ALIASES.getPath()); return config.getConfigNode(Settings.WORLD_ALIASES.getPath());
} }
/** /**
@ -56,10 +57,10 @@ public class WorldAliasSettings {
* @param world World name * @param world World name
*/ */
public void addWorld(String world) { public void addWorld(String world) {
ConfigurationSection aliasSect = getAliasSection(); ConfigNode aliasSect = getAliasSection();
Object previousValue = aliasSect.get(world); String previousValue = aliasSect.getConfigNode(world).getValue();
if (previousValue == null) { if (Verify.isEmpty(previousValue)) {
aliasSect.set(world, world); aliasSect.set(world, world);
} }
plugin.saveConfig(); plugin.saveConfig();

View File

@ -29,6 +29,7 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
public PlanBungeeCommand(PlanBungee plugin) { public PlanBungeeCommand(PlanBungee plugin) {
super(plugin, "planbungee", CommandType.CONSOLE, "", "", "planbungee"); super(plugin, "planbungee", CommandType.CONSOLE, "", "", "planbungee");
super.setDefaultCommand("help"); super.setDefaultCommand("help");
super.setColorScheme(plugin.getColorScheme());
} }
@Override @Override
@ -38,13 +39,17 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
@Override @Override
public void addCommands() { public void addCommands() {
commands.add(new ReloadCommand(plugin)); add(
commands.add(new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme())); new ReloadCommand(plugin),
commands.add(new ListCommand()); new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
new ListCommand()
);
RegisterCommand registerCommand = new RegisterCommand(plugin); RegisterCommand registerCommand = new RegisterCommand(plugin);
commands.add(registerCommand); add(
commands.add(new WebUserCommand(plugin, registerCommand)); registerCommand,
commands.add(new NetworkCommand(plugin)); new WebUserCommand(plugin, registerCommand),
commands.add(new ListServersCommand(plugin)); new NetworkCommand(plugin),
new ListServersCommand(plugin)
);
} }
} }

View File

@ -30,6 +30,7 @@ public class PlanCommand extends TreeCommand<Plan> {
public PlanCommand(Plan plugin) { public PlanCommand(Plan plugin) {
super(plugin, "plan", CommandType.CONSOLE, "", "", "plan"); super(plugin, "plan", CommandType.CONSOLE, "", "", "plan");
super.setDefaultCommand("inspect"); super.setDefaultCommand("inspect");
super.setColorScheme(plugin.getColorScheme());
} }
@Override @Override
@ -39,22 +40,25 @@ public class PlanCommand extends TreeCommand<Plan> {
@Override @Override
public void addCommands() { public void addCommands() {
commands.add(new InspectCommand(plugin)); add(
commands.add(new AnalyzeCommand(plugin)); new InspectCommand(plugin),
commands.add(new SearchCommand(plugin)); new AnalyzeCommand(plugin),
commands.add(new InfoCommand(plugin)); new SearchCommand(plugin),
commands.add(new ReloadCommand(plugin)); new InfoCommand(plugin),
commands.add(new ManageCommand(plugin)); new ReloadCommand(plugin),
commands.add(new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme())); new ManageCommand(plugin),
commands.add(new ListCommand()); new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
new ListCommand()
);
RegisterCommand registerCommand = new RegisterCommand(plugin); RegisterCommand registerCommand = new RegisterCommand(plugin);
commands.add(registerCommand); add(
commands.add(new WebUserCommand(plugin, registerCommand)); registerCommand,
commands.add(new NetworkCommand(plugin)); new WebUserCommand(plugin, registerCommand),
commands.add(new ListServersCommand(plugin)); new NetworkCommand(plugin),
new ListServersCommand(plugin));
if (Settings.DEV_MODE.isTrue()) { if (Settings.DEV_MODE.isTrue()) {
commands.add(new DevCommand(plugin)); add(new DevCommand(plugin));
} }
} }
} }

View File

@ -25,7 +25,7 @@ public class ManageCommand extends TreeCommand<Plan> {
*/ */
public ManageCommand(Plan plugin) { public ManageCommand(Plan plugin) {
super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Locale.get(Msg.CMD_USG_MANAGE).toString(), "plan m"); super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Locale.get(Msg.CMD_USG_MANAGE).toString(), "plan m");
super.setColorScheme(plugin.getColorScheme());
} }
@Override @Override
@ -35,15 +35,17 @@ public class ManageCommand extends TreeCommand<Plan> {
@Override @Override
public void addCommands() { public void addCommands() {
commands.add(new ManageMoveCommand(plugin)); add(
commands.add(new ManageHotswapCommand(plugin)); new ManageMoveCommand(plugin),
commands.add(new ManageBackupCommand(plugin)); new ManageHotswapCommand(plugin),
commands.add(new ManageRestoreCommand(plugin)); new ManageBackupCommand(plugin),
commands.add(new ManageImportCommand(plugin)); new ManageRestoreCommand(plugin),
commands.add(new ManageRemoveCommand(plugin)); new ManageImportCommand(plugin),
commands.add(new ManageClearCommand(plugin)); new ManageRemoveCommand(plugin),
commands.add(new ManageDumpCommand(plugin)); new ManageClearCommand(plugin),
commands.add(new ManageSetupCommand(plugin)); new ManageDumpCommand(plugin),
commands.add(new ManageDisableCommand()); new ManageSetupCommand(plugin),
new ManageDisableCommand()
);
} }
} }

View File

@ -27,7 +27,8 @@ public class WebUserCommand extends TreeCommand<IPlan> {
Permissions.MANAGE_WEB.getPerm(), Permissions.MANAGE_WEB.getPerm(),
Locale.get(Msg.CMD_USG_WEB).toString(), Locale.get(Msg.CMD_USG_WEB).toString(),
"plan web"); "plan web");
commands.add(register); super.setColorScheme(plugin.getColorScheme());
add(register);
} }
public WebUserCommand(PlanBungee plugin, RegisterCommand register) { public WebUserCommand(PlanBungee plugin, RegisterCommand register) {
@ -36,7 +37,7 @@ public class WebUserCommand extends TreeCommand<IPlan> {
Permissions.MANAGE_WEB.getPerm(), Permissions.MANAGE_WEB.getPerm(),
Locale.get(Msg.CMD_USG_WEB).toString(), Locale.get(Msg.CMD_USG_WEB).toString(),
"planbungee web"); "planbungee web");
commands.add(register); add(register);
} }
@Override @Override
@ -46,9 +47,11 @@ public class WebUserCommand extends TreeCommand<IPlan> {
@Override @Override
public void addCommands() { public void addCommands() {
commands.add(new WebLevelCommand(plugin)); add(
commands.add(new WebListUsersCommand(plugin)); new WebLevelCommand(plugin),
commands.add(new WebCheckCommand(plugin)); new WebListUsersCommand(plugin),
commands.add(new WebDeleteCommand(plugin)); new WebCheckCommand(plugin),
new WebDeleteCommand(plugin)
);
} }
} }

View File

@ -208,7 +208,7 @@ public class Analysis {
Benchmark.stop("Analysis", "Source " + source.getPlaceholder()); Benchmark.stop("Analysis", "Source " + source.getPlaceholder());
} }
}); });
Benchmark.stop("Analysis", "3rd party"); Benchmark.stop("Analysis", "3rd party Analysis");
return replaceMap; return replaceMap;
} }

View File

@ -49,6 +49,7 @@ public class FileUtil {
lines.add(scanner.nextLine()); lines.add(scanner.nextLine());
} }
} catch (NullPointerException e) { } catch (NullPointerException e) {
e.printStackTrace();
throw new FileNotFoundException("File not found inside jar: " + resource); throw new FileNotFoundException("File not found inside jar: " + resource);
} finally { } finally {
MiscUtils.close(scanner); MiscUtils.close(scanner);

View File

@ -46,7 +46,7 @@ import static org.powermock.api.mockito.PowerMockito.when;
* @author Rsl1122 * @author Rsl1122
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest(JavaPlugin.class) @PrepareForTest({JavaPlugin.class})
public class DatabaseTest { public class DatabaseTest {
private final UUID uuid = MockUtils.getPlayerUUID(); private final UUID uuid = MockUtils.getPlayerUUID();

View File

@ -10,10 +10,15 @@ import main.java.com.djrapitops.plan.data.time.WorldTimes;
import main.java.com.djrapitops.plan.utilities.analysis.Point; import main.java.com.djrapitops.plan.utilities.analysis.Point;
import main.java.com.djrapitops.plan.utilities.html.graphs.*; import main.java.com.djrapitops.plan.utilities.html.graphs.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.plugin.java.JavaPlugin;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import test.java.utils.RandomData; import test.java.utils.RandomData;
import test.java.utils.TestInit;
import java.util.*; import java.util.*;
@ -22,6 +27,8 @@ import static junit.framework.TestCase.assertEquals;
/** /**
* @author Fuzzlemann * @author Fuzzlemann
*/ */
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class})
public class GraphTest { public class GraphTest {
private final List<TPS> tpsList = new ArrayList<>(); private final List<TPS> tpsList = new ArrayList<>();
@ -32,7 +39,8 @@ public class GraphTest {
private List<Point> points = new ArrayList<>(); private List<Point> points = new ArrayList<>();
@Before @Before
public void setUp() { public void setUp() throws Exception {
TestInit t = TestInit.init();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
tpsList.add(new TPS(i, i, i, i, i, i, i)); tpsList.add(new TPS(i, i, i, i, i, i, i));
sessionList.add(new Session(i, (long) i, (long) i, i, i)); sessionList.add(new Session(i, (long) i, (long) i, i, i));
@ -55,7 +63,8 @@ public class GraphTest {
assertEquals(expected, WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsList)); assertEquals(expected, WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsList));
assertEquals(expected, WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsList)); assertEquals(expected, WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsList));
assertEquals("[{'code':'1','value':1},{'code':'2','value':2},{'code':'3','value':3},{'code':'4','value':4},{'code':'5','value':5},{'code':'6','value':6},{'code':'7','value':7},{'code':'8','value':8},{'code':'9','value':9}]", WorldMapCreator.createDataSeries(geoList)); assertEquals("[{'code':'1','value':1},{'code':'2','value':2},{'code':'3','value':3},{'code':'4','value':4},{'code':'5','value':5},{'code':'6','value':6},{'code':'7','value':7},{'code':'8','value':8},{'code':'9','value':9}]", WorldMapCreator.createDataSeries(geoList));
assertEquals("[[{name:'WORLD',y:0,drilldown: 'WORLD'}], [{name:'WORLD', id:'WORLD',colors: gmPieColors,data: []}]]", Arrays.toString(WorldPieCreator.createSeriesData(worldTimes))); assertEquals("[[{name:'WORLD',y:0,drilldown: 'WORLD'}], [{name:'WORLD', id:'WORLD',colors: gmPieColors,data: [['SURVIVAL',0],['SPECTATOR',0],['CREATIVE',0],['ADVENTURE',0]]}]]",
Arrays.toString(WorldPieCreator.createSeriesData(worldTimes)));
} }
@Test @Test

View File

@ -134,7 +134,7 @@ public class FormatUtilsTest {
@Test @Test
public void testParseVersionNumber() { public void testParseVersionNumber() {
String versionString = "2.10.2"; String versionString = "2.10.2";
int expResult = 21002; long expResult = 21002000000000000L;
long result = FormatUtils.parseVersionNumber(versionString); long result = FormatUtils.parseVersionNumber(versionString);

View File

@ -1,8 +1,11 @@
package test.java.utils; package test.java.utils;
import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.config.Config; import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme; import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.RunnableFactory;
import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.ServerVariableHolder; import main.java.com.djrapitops.plan.ServerVariableHolder;
import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.Settings;
@ -22,6 +25,7 @@ import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -78,21 +82,31 @@ public class TestInit {
private void setUp() throws Exception { private void setUp() throws Exception {
planMock = PowerMockito.mock(Plan.class); planMock = PowerMockito.mock(Plan.class);
StaticHolder.register(Plan.class, planMock);
StaticHolder.register(planMock); StaticHolder.register(planMock);
StaticHolder.register(planMock);
// Hacks to make APF find classes
StaticHolder.register(IPlugin.class, planMock);
StaticHolder.saveInstance(this.getClass(), Plan.class);
StaticHolder.saveInstance(PowerMockRunner.class, Plan.class);
Log.setDebugMode("console");
File testFolder = getTestFolder(); File testFolder = getTestFolder();
when(planMock.getDataFolder()).thenReturn(testFolder); when(planMock.getDataFolder()).thenReturn(testFolder);
Config iConfig = new Config(new File(planMock.getDataFolder(), "config.yml"), FileUtil.lines(planMock, "config.yml")); // Files
when(planMock.getMainConfig()).thenReturn(iConfig); File config = new File(getClass().getResource("/config.yml").getPath());
when(planMock.getResource("config.yml")).thenReturn(new FileInputStream(config));
// Html Files
File analysis = new File(getClass().getResource("/server.html").getPath()); File analysis = new File(getClass().getResource("/server.html").getPath());
when(planMock.getResource("server.html")).thenReturn(new FileInputStream(analysis)); when(planMock.getResource("server.html")).thenReturn(new FileInputStream(analysis));
File player = new File(getClass().getResource("/player.html").getPath()); File player = new File(getClass().getResource("/player.html").getPath());
when(planMock.getResource("player.html")).thenReturn(new FileInputStream(player)); when(planMock.getResource("player.html")).thenReturn(new FileInputStream(player));
Config iConfig = new Config(new File(planMock.getDataFolder(), "config.yml"), FileUtil.lines(planMock, "config.yml"));
when(planMock.getMainConfig()).thenReturn(iConfig);
Server mockServer = mockServer(); Server mockServer = mockServer();
when(planMock.getServer()).thenReturn(mockServer); when(planMock.getServer()).thenReturn(mockServer);
@ -112,6 +126,8 @@ public class TestInit {
ColorScheme cs = new ColorScheme(ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK); ColorScheme cs = new ColorScheme(ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK);
when(planMock.getColorScheme()).thenReturn(cs); when(planMock.getColorScheme()).thenReturn(cs);
initLocale(planMock); initLocale(planMock);
RunnableFactory.activateTestMode();
} }
private Server mockServer() { private Server mockServer() {
@ -140,7 +156,6 @@ public class TestInit {
for (String string : strings) { for (String string : strings) {
sendMessage(string); sendMessage(string);
} }
} }
@Override @Override