mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Fixed Tests
This commit is contained in:
parent
e1c648fb9d
commit
e129ac0990
@ -152,6 +152,8 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
} else {
|
||||
Log.info("You're using the latest version.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to check newest version number");
|
||||
|
@ -74,6 +74,8 @@ public class PlanBungee extends BungeePlugin implements IPlan {
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
Log.infoColor("§aNew version is available at https://www.spigotmc.org/resources/plan-player-analytics.32536/");
|
||||
Log.infoColor("§a----------------------------------------");
|
||||
} else {
|
||||
Log.info("You're using the latest version.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to check newest version number");
|
||||
|
@ -4,8 +4,9 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import com.djrapitops.plugin.api.config.Config;
|
||||
import com.djrapitops.plugin.api.config.ConfigNode;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -34,18 +35,18 @@ public class WorldAliasSettings {
|
||||
* @return Map: Original name, Alias
|
||||
*/
|
||||
public Map<String, String> getAliases() {
|
||||
ConfigurationSection aliasSect = getAliasSection();
|
||||
ConfigNode aliasSect = getAliasSection();
|
||||
|
||||
Map<String, String> aliasMap = new HashMap<>();
|
||||
for (String world : aliasSect.getKeys(false)) {
|
||||
aliasMap.put(world, aliasSect.getString(world));
|
||||
for (Map.Entry<String, ConfigNode> world : aliasSect.getChildren().entrySet()) {
|
||||
aliasMap.put(world.getKey(), world.getValue().getString());
|
||||
}
|
||||
return aliasMap;
|
||||
}
|
||||
|
||||
private ConfigurationSection getAliasSection() {
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
return config.getConfigurationSection(Settings.WORLD_ALIASES.getPath());
|
||||
private ConfigNode getAliasSection() {
|
||||
Config config = plugin.getMainConfig();
|
||||
return config.getConfigNode(Settings.WORLD_ALIASES.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,10 +57,10 @@ public class WorldAliasSettings {
|
||||
* @param world World name
|
||||
*/
|
||||
public void addWorld(String world) {
|
||||
ConfigurationSection aliasSect = getAliasSection();
|
||||
ConfigNode aliasSect = getAliasSection();
|
||||
|
||||
Object previousValue = aliasSect.get(world);
|
||||
if (previousValue == null) {
|
||||
String previousValue = aliasSect.getConfigNode(world).getValue();
|
||||
if (Verify.isEmpty(previousValue)) {
|
||||
aliasSect.set(world, world);
|
||||
}
|
||||
plugin.saveConfig();
|
||||
|
@ -29,6 +29,7 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
|
||||
public PlanBungeeCommand(PlanBungee plugin) {
|
||||
super(plugin, "planbungee", CommandType.CONSOLE, "", "", "planbungee");
|
||||
super.setDefaultCommand("help");
|
||||
super.setColorScheme(plugin.getColorScheme());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,13 +39,17 @@ public class PlanBungeeCommand extends TreeCommand<PlanBungee> {
|
||||
|
||||
@Override
|
||||
public void addCommands() {
|
||||
commands.add(new ReloadCommand(plugin));
|
||||
commands.add(new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()));
|
||||
commands.add(new ListCommand());
|
||||
add(
|
||||
new ReloadCommand(plugin),
|
||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
||||
new ListCommand()
|
||||
);
|
||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
||||
commands.add(registerCommand);
|
||||
commands.add(new WebUserCommand(plugin, registerCommand));
|
||||
commands.add(new NetworkCommand(plugin));
|
||||
commands.add(new ListServersCommand(plugin));
|
||||
add(
|
||||
registerCommand,
|
||||
new WebUserCommand(plugin, registerCommand),
|
||||
new NetworkCommand(plugin),
|
||||
new ListServersCommand(plugin)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public class PlanCommand extends TreeCommand<Plan> {
|
||||
public PlanCommand(Plan plugin) {
|
||||
super(plugin, "plan", CommandType.CONSOLE, "", "", "plan");
|
||||
super.setDefaultCommand("inspect");
|
||||
super.setColorScheme(plugin.getColorScheme());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,22 +40,25 @@ public class PlanCommand extends TreeCommand<Plan> {
|
||||
|
||||
@Override
|
||||
public void addCommands() {
|
||||
commands.add(new InspectCommand(plugin));
|
||||
commands.add(new AnalyzeCommand(plugin));
|
||||
commands.add(new SearchCommand(plugin));
|
||||
commands.add(new InfoCommand(plugin));
|
||||
commands.add(new ReloadCommand(plugin));
|
||||
commands.add(new ManageCommand(plugin));
|
||||
commands.add(new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()));
|
||||
commands.add(new ListCommand());
|
||||
add(
|
||||
new InspectCommand(plugin),
|
||||
new AnalyzeCommand(plugin),
|
||||
new SearchCommand(plugin),
|
||||
new InfoCommand(plugin),
|
||||
new ReloadCommand(plugin),
|
||||
new ManageCommand(plugin),
|
||||
new StatusCommand<>(plugin, Permissions.MANAGE.getPermission(), plugin.getColorScheme()),
|
||||
new ListCommand()
|
||||
);
|
||||
RegisterCommand registerCommand = new RegisterCommand(plugin);
|
||||
commands.add(registerCommand);
|
||||
commands.add(new WebUserCommand(plugin, registerCommand));
|
||||
commands.add(new NetworkCommand(plugin));
|
||||
commands.add(new ListServersCommand(plugin));
|
||||
add(
|
||||
registerCommand,
|
||||
new WebUserCommand(plugin, registerCommand),
|
||||
new NetworkCommand(plugin),
|
||||
new ListServersCommand(plugin));
|
||||
|
||||
if (Settings.DEV_MODE.isTrue()) {
|
||||
commands.add(new DevCommand(plugin));
|
||||
add(new DevCommand(plugin));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class ManageCommand extends TreeCommand<Plan> {
|
||||
*/
|
||||
public ManageCommand(Plan plugin) {
|
||||
super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Locale.get(Msg.CMD_USG_MANAGE).toString(), "plan m");
|
||||
|
||||
super.setColorScheme(plugin.getColorScheme());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,15 +35,17 @@ public class ManageCommand extends TreeCommand<Plan> {
|
||||
|
||||
@Override
|
||||
public void addCommands() {
|
||||
commands.add(new ManageMoveCommand(plugin));
|
||||
commands.add(new ManageHotswapCommand(plugin));
|
||||
commands.add(new ManageBackupCommand(plugin));
|
||||
commands.add(new ManageRestoreCommand(plugin));
|
||||
commands.add(new ManageImportCommand(plugin));
|
||||
commands.add(new ManageRemoveCommand(plugin));
|
||||
commands.add(new ManageClearCommand(plugin));
|
||||
commands.add(new ManageDumpCommand(plugin));
|
||||
commands.add(new ManageSetupCommand(plugin));
|
||||
commands.add(new ManageDisableCommand());
|
||||
add(
|
||||
new ManageMoveCommand(plugin),
|
||||
new ManageHotswapCommand(plugin),
|
||||
new ManageBackupCommand(plugin),
|
||||
new ManageRestoreCommand(plugin),
|
||||
new ManageImportCommand(plugin),
|
||||
new ManageRemoveCommand(plugin),
|
||||
new ManageClearCommand(plugin),
|
||||
new ManageDumpCommand(plugin),
|
||||
new ManageSetupCommand(plugin),
|
||||
new ManageDisableCommand()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,8 @@ public class WebUserCommand extends TreeCommand<IPlan> {
|
||||
Permissions.MANAGE_WEB.getPerm(),
|
||||
Locale.get(Msg.CMD_USG_WEB).toString(),
|
||||
"plan web");
|
||||
commands.add(register);
|
||||
super.setColorScheme(plugin.getColorScheme());
|
||||
add(register);
|
||||
}
|
||||
|
||||
public WebUserCommand(PlanBungee plugin, RegisterCommand register) {
|
||||
@ -36,7 +37,7 @@ public class WebUserCommand extends TreeCommand<IPlan> {
|
||||
Permissions.MANAGE_WEB.getPerm(),
|
||||
Locale.get(Msg.CMD_USG_WEB).toString(),
|
||||
"planbungee web");
|
||||
commands.add(register);
|
||||
add(register);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,9 +47,11 @@ public class WebUserCommand extends TreeCommand<IPlan> {
|
||||
|
||||
@Override
|
||||
public void addCommands() {
|
||||
commands.add(new WebLevelCommand(plugin));
|
||||
commands.add(new WebListUsersCommand(plugin));
|
||||
commands.add(new WebCheckCommand(plugin));
|
||||
commands.add(new WebDeleteCommand(plugin));
|
||||
add(
|
||||
new WebLevelCommand(plugin),
|
||||
new WebListUsersCommand(plugin),
|
||||
new WebCheckCommand(plugin),
|
||||
new WebDeleteCommand(plugin)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public class Analysis {
|
||||
Benchmark.stop("Analysis", "Source " + source.getPlaceholder());
|
||||
}
|
||||
});
|
||||
Benchmark.stop("Analysis", "3rd party");
|
||||
Benchmark.stop("Analysis", "3rd party Analysis");
|
||||
return replaceMap;
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ public class FileUtil {
|
||||
lines.add(scanner.nextLine());
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
throw new FileNotFoundException("File not found inside jar: " + resource);
|
||||
} finally {
|
||||
MiscUtils.close(scanner);
|
||||
|
@ -46,7 +46,7 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
@PrepareForTest({JavaPlugin.class})
|
||||
public class DatabaseTest {
|
||||
|
||||
private final UUID uuid = MockUtils.getPlayerUUID();
|
||||
|
@ -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.html.graphs.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
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.TestInit;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -22,6 +27,8 @@ import static junit.framework.TestCase.assertEquals;
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({JavaPlugin.class})
|
||||
public class GraphTest {
|
||||
|
||||
private final List<TPS> tpsList = new ArrayList<>();
|
||||
@ -32,7 +39,8 @@ public class GraphTest {
|
||||
private List<Point> points = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setUp() throws Exception {
|
||||
TestInit t = TestInit.init();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tpsList.add(new TPS(i, i, i, i, 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.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("[[{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
|
||||
|
@ -134,7 +134,7 @@ public class FormatUtilsTest {
|
||||
@Test
|
||||
public void testParseVersionNumber() {
|
||||
String versionString = "2.10.2";
|
||||
int expResult = 21002;
|
||||
long expResult = 21002000000000000L;
|
||||
|
||||
long result = FormatUtils.parseVersionNumber(versionString);
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
package test.java.utils;
|
||||
|
||||
import com.djrapitops.plugin.IPlugin;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
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.task.RunnableFactory;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.ServerVariableHolder;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
@ -22,6 +25,7 @@ import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -78,21 +82,31 @@ public class TestInit {
|
||||
|
||||
private void setUp() throws Exception {
|
||||
planMock = PowerMockito.mock(Plan.class);
|
||||
|
||||
StaticHolder.register(Plan.class, 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();
|
||||
when(planMock.getDataFolder()).thenReturn(testFolder);
|
||||
|
||||
Config iConfig = new Config(new File(planMock.getDataFolder(), "config.yml"), FileUtil.lines(planMock, "config.yml"));
|
||||
when(planMock.getMainConfig()).thenReturn(iConfig);
|
||||
|
||||
// Html Files
|
||||
// Files
|
||||
File config = new File(getClass().getResource("/config.yml").getPath());
|
||||
when(planMock.getResource("config.yml")).thenReturn(new FileInputStream(config));
|
||||
File analysis = new File(getClass().getResource("/server.html").getPath());
|
||||
when(planMock.getResource("server.html")).thenReturn(new FileInputStream(analysis));
|
||||
File player = new File(getClass().getResource("/player.html").getPath());
|
||||
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();
|
||||
|
||||
when(planMock.getServer()).thenReturn(mockServer);
|
||||
@ -112,6 +126,8 @@ public class TestInit {
|
||||
ColorScheme cs = new ColorScheme(ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK);
|
||||
when(planMock.getColorScheme()).thenReturn(cs);
|
||||
initLocale(planMock);
|
||||
|
||||
RunnableFactory.activateTestMode();
|
||||
}
|
||||
|
||||
private Server mockServer() {
|
||||
@ -140,7 +156,6 @@ public class TestInit {
|
||||
for (String string : strings) {
|
||||
sendMessage(string);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user