mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 05:39:19 +01:00
More tests for the new Processing
Pit report: Total - 29% line coverage & 22% mutation coverage (1236/4253 & 436/1982) The new processing - 75% & 77% One class to test before testing cache After that tests on the server and merge.
This commit is contained in:
parent
d0ee96b3ab
commit
c95260bd1f
@ -66,7 +66,7 @@ public class InspectCommand extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
String playerName = MiscUtils.getPlayerDisplayname(args, sender);
|
||||
String playerName = MiscUtils.getPlayerName(args, sender);
|
||||
BukkitTask inspectTask = (new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -14,6 +14,9 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -54,7 +57,7 @@ public class ManageRemoveCommand extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
String playerName = MiscUtils.getPlayerDisplayname(args, sender);
|
||||
String playerName = MiscUtils.getPlayerName(args, sender);
|
||||
|
||||
UUID uuid;
|
||||
try {
|
||||
|
@ -1,5 +1,8 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheGetQueue;
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheSaveQueue;
|
||||
import main.java.com.djrapitops.plan.data.cache.queue.DataCacheClearQueue;
|
||||
import main.java.com.djrapitops.plan.utilities.NewPlayerCreator;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@ -11,12 +14,12 @@ import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.*;
|
||||
import main.java.com.djrapitops.plan.data.handlers.*;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.ReloadInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@ -24,7 +27,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DataCacheHandler {
|
||||
public class DataCacheHandler extends LocationCache {
|
||||
|
||||
// Cache
|
||||
private final HashMap<UUID, UserData> dataCache;
|
||||
@ -34,11 +37,6 @@ public class DataCacheHandler {
|
||||
private final Plan plugin;
|
||||
private final Database db;
|
||||
|
||||
// Handlers
|
||||
private final LocationHandler locationHandler;
|
||||
private CommandUseHandler commandUseHandler;
|
||||
private final SessionHandler sessionHandler;
|
||||
|
||||
// Queues
|
||||
private DataCacheSaveQueue saveTask;
|
||||
private DataCacheClearQueue clearTask;
|
||||
@ -57,11 +55,10 @@ public class DataCacheHandler {
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public DataCacheHandler(Plan plugin) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
db = plugin.getDB();
|
||||
dataCache = new HashMap<>();
|
||||
locationHandler = new LocationHandler(plugin);
|
||||
sessionHandler = new SessionHandler(plugin);
|
||||
|
||||
getTask = new DataCacheGetQueue(plugin);
|
||||
clearTask = new DataCacheClearQueue(plugin, this);
|
||||
@ -69,14 +66,19 @@ public class DataCacheHandler {
|
||||
|
||||
timesSaved = 0;
|
||||
maxPlayers = plugin.getServer().getMaxPlayers();
|
||||
|
||||
try {
|
||||
commandUse = db.getCommandUse();
|
||||
commandUseHandler = new CommandUseHandler(commandUse);
|
||||
} catch (SQLException e) {
|
||||
plugin.toLog(this.getClass().getName(), e);
|
||||
plugin.logError(Phrase.DB_FAILURE_DISABLE + "");
|
||||
plugin.getServer().getPluginManager().disablePlugin(plugin);
|
||||
return;
|
||||
}
|
||||
startAsyncPeriodicSaveTask();
|
||||
}
|
||||
|
||||
public void startAsyncPeriodicSaveTask() throws IllegalArgumentException, IllegalStateException {
|
||||
int minutes = Settings.SAVE_CACHE_MIN.getNumber();
|
||||
if (minutes <= 0) {
|
||||
minutes = 5;
|
||||
@ -91,7 +93,7 @@ public class DataCacheHandler {
|
||||
BukkitTask asyncPeriodicCacheSaveTask = (new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DataCacheHandler handler = plugin.getHandler();
|
||||
DataCacheHandler handler = getPlugin(Plan.class).getHandler();
|
||||
handler.saveHandlerDataToCache();
|
||||
handler.saveCachedUserData();
|
||||
if (timesSaved % clearAfterXsaves == 0) {
|
||||
@ -173,7 +175,7 @@ public class DataCacheHandler {
|
||||
List<UserData> data = new ArrayList<>();
|
||||
data.addAll(dataCache.values());
|
||||
data.parallelStream().forEach((userData) -> {
|
||||
sessionHandler.endSession(userData);
|
||||
endSession(userData);
|
||||
});
|
||||
try {
|
||||
db.saveMultipleUserData(data);
|
||||
@ -193,8 +195,8 @@ public class DataCacheHandler {
|
||||
DBCallableProcessor saveProcessor = new DBCallableProcessor() {
|
||||
@Override
|
||||
public void process(UserData data) {
|
||||
data.addLocations(locationHandler.getLocationsForSaving(uuid));
|
||||
locationHandler.clearLocations(uuid);
|
||||
data.addLocations(getLocationsForSaving(uuid));
|
||||
clearLocations(uuid);
|
||||
saveTask.scheduleForSave(data);
|
||||
scheludeForClear(uuid);
|
||||
}
|
||||
@ -297,8 +299,8 @@ public class DataCacheHandler {
|
||||
/**
|
||||
* @return Current instance of the LocationHandler
|
||||
*/
|
||||
public LocationHandler getLocationHandler() {
|
||||
return locationHandler;
|
||||
public LocationCache getLocationHandler() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,19 +311,12 @@ public class DataCacheHandler {
|
||||
return commandUse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current instance of ServerDataHandler
|
||||
*/
|
||||
public CommandUseHandler getCommandUseHandler() {
|
||||
return commandUseHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SessionHandler getSessionHandler() {
|
||||
return sessionHandler;
|
||||
public SessionCache getSessionCache() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -354,4 +349,11 @@ public class DataCacheHandler {
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
public void handleCommand(String command) {
|
||||
if (!commandUse.containsKey(command)) {
|
||||
commandUse.put(command, 0);
|
||||
}
|
||||
commandUse.put(command, commandUse.get(command) + 1);
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,29 @@
|
||||
package main.java.com.djrapitops.plan.data.handlers;
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class LocationHandler {
|
||||
public class LocationCache extends SessionCache{
|
||||
|
||||
private Plan plugin;
|
||||
private HashMap<UUID, List<Location>> locations;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public LocationHandler(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
public LocationCache() {
|
||||
super();
|
||||
locations = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds location to the UserData if it is not being saved.
|
||||
*
|
||||
* @param uuid UUID of player
|
||||
* @param loc Location from the MoveEvent listener.
|
||||
*/
|
||||
public void addLocation(UUID uuid, Location loc) {
|
||||
if (!locations.containsKey(uuid)) {
|
||||
locations.put(uuid, new ArrayList<>());
|
||||
@ -40,12 +31,6 @@ public class LocationHandler {
|
||||
locations.get(uuid).add(loc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple locaitons to the UserData.
|
||||
*
|
||||
* @param uuid UUID of player
|
||||
* @param locs The Locations that are added.
|
||||
*/
|
||||
public void addLocations(UUID uuid, Collection<Location> locs) {
|
||||
if (!locations.containsKey(uuid)) {
|
||||
locations.put(uuid, new ArrayList<>());
|
||||
@ -53,22 +38,13 @@ public class LocationHandler {
|
||||
locations.get(uuid).addAll(locs);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
public List<Location> getLocationsForSaving(UUID uuid) {
|
||||
if (!locations.containsKey(uuid)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return locations.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
|
||||
public void clearLocations(UUID uuid) {
|
||||
locations.remove(uuid);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
|
||||
package main.java.com.djrapitops.plan.data.handlers;
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@ -13,24 +13,19 @@ import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SessionHandler {
|
||||
public class SessionCache {
|
||||
private final HashMap<UUID, SessionData> activeSessions;
|
||||
private final DataCacheHandler handler;
|
||||
private final Plan plugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public SessionHandler(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
this.handler = plugin.getHandler();
|
||||
public SessionCache() {
|
||||
this.activeSessions = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* @param uuid
|
||||
*/
|
||||
public void startSession(UUID uuid) {
|
||||
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
@ -1,4 +1,4 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
package main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
@ -7,8 +7,10 @@ import java.util.concurrent.BlockingQueue;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
@ -1,4 +1,4 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
package main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@ -11,6 +11,7 @@ import java.util.concurrent.BlockingQueue;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
package main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
@ -1,32 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.handlers;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class CommandUseHandler {
|
||||
|
||||
private HashMap<String, Integer> commandUse;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param serverData ServerData in the DataCacheHandler.
|
||||
*/
|
||||
public CommandUseHandler(HashMap<String, Integer> serverData) {
|
||||
this.commandUse = serverData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds command to the command usage.
|
||||
* @param command Used command, first part (eg. /plan)
|
||||
*/
|
||||
public void handleCommand(String command) {
|
||||
if (!commandUse.containsKey(command)) {
|
||||
commandUse.put(command, 0);
|
||||
}
|
||||
commandUse.put(command, commandUse.get(command) + 1);
|
||||
}
|
||||
}
|
@ -28,6 +28,9 @@ public class KillHandling {
|
||||
try {
|
||||
UUID victimUUID = deadPlayer.getUniqueId();
|
||||
victimID = plugin.getDB().getUserId(victimUUID + "");
|
||||
if (victimID == -1) {
|
||||
return;
|
||||
}
|
||||
data.addPlayerKill(new KillData(victimUUID, victimID, weaponName, time));
|
||||
} catch (SQLException e) {
|
||||
plugin.toLog("main.java.com.djrapitops.plan.KillHandling", e);
|
||||
|
@ -18,6 +18,6 @@ public class LogoutHandling {
|
||||
data.setPlayTime(data.getPlayTime() + (time - data.getLastPlayed()));
|
||||
data.setLastPlayed(time);
|
||||
data.updateBanned(banned);
|
||||
getPlugin(Plan.class).getHandler().getSessionHandler().endSession(data);
|
||||
getPlugin(Plan.class).getHandler().getSessionCache().endSession(data);
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ public class KillInfo extends HandlingInfo {
|
||||
|
||||
@Override
|
||||
public boolean process(UserData uData) {
|
||||
if (!uData.getUuid().equals(uuid)) {
|
||||
return false;
|
||||
}
|
||||
KillHandling.processKillInfo(uData, time, dead, weaponName);
|
||||
return true;
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ public class LogoutInfo extends HandlingInfo{
|
||||
if (uData.getUuid() != uuid) {
|
||||
return false;
|
||||
}
|
||||
LogoutHandling.processLogoutInfo(uData, time, banned);
|
||||
gmInfo.process(uData);
|
||||
LogoutHandling.processLogoutInfo(uData, time, banned);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.GameMode;
|
||||
* @author Risto
|
||||
*/
|
||||
public class ReloadInfo extends HandlingInfo {
|
||||
|
||||
private LoginInfo info;
|
||||
|
||||
public ReloadInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, GameMode gm) {
|
||||
@ -24,7 +25,10 @@ public class ReloadInfo extends HandlingInfo {
|
||||
|
||||
@Override
|
||||
public boolean process(UserData uData) {
|
||||
if (!uData.getUuid().equals(uuid)) {
|
||||
return false;
|
||||
}
|
||||
return info.process(uData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handlers.CommandUseHandler;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -16,7 +15,6 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataCacheHandler handler;
|
||||
private final CommandUseHandler serverH;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -26,7 +24,6 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
public PlanCommandPreprocessListener(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
handler = plugin.getHandler();
|
||||
serverH = handler.getCommandUseHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,6 +39,6 @@ public class PlanCommandPreprocessListener implements Listener {
|
||||
if (event.getPlayer().hasPermission("plan.ignore.commanduse")) {
|
||||
return;
|
||||
}
|
||||
serverH.handleCommand(event.getMessage().split(" ")[0]);
|
||||
handler.handleCommand(event.getMessage().split(" ")[0]);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package main.java.com.djrapitops.plan.data.listeners;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.cache.LocationCache;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handlers.*;
|
||||
import main.java.com.djrapitops.plan.data.handling.InfoPoolProcessor;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KickInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.LoginInfo;
|
||||
@ -28,7 +28,7 @@ public class PlanPlayerListener implements Listener {
|
||||
private final Plan plugin;
|
||||
private final DataCacheHandler handler;
|
||||
private final InfoPoolProcessor processor;
|
||||
private final LocationHandler locationH;
|
||||
private final LocationCache locationH;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -58,7 +58,7 @@ public class PlanPlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
processor.addToPool(new LoginInfo(uuid, new Date().getTime(), player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGameMode(), 1));
|
||||
handler.getSessionHandler().startSession(uuid);
|
||||
handler.getSessionCache().startSession(uuid);
|
||||
BukkitTask asyncNewPlayerCheckTask = (new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.data.listeners;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handlers.LocationHandler;
|
||||
import main.java.com.djrapitops.plan.data.cache.LocationCache;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -18,7 +18,7 @@ public class PlanPlayerMoveListener implements Listener {
|
||||
|
||||
private final Plan plugin;
|
||||
private final DataCacheHandler handler;
|
||||
private final LocationHandler locationH;
|
||||
private final LocationCache locationH;
|
||||
|
||||
/**
|
||||
* Class Consturctor.
|
||||
|
@ -28,6 +28,7 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -19,6 +19,7 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -36,7 +36,7 @@ public class MiscUtils {
|
||||
} catch (IOException | NumberFormatException e) {
|
||||
getPlugin(Plan.class).logError(Phrase.VERSION_CHECK_ERROR + "");
|
||||
}
|
||||
return Phrase.VERSION_FAIL+"";
|
||||
return Phrase.VERSION_FAIL + "";
|
||||
}
|
||||
|
||||
private static String getGitVersion() throws IOException {
|
||||
@ -66,18 +66,17 @@ public class MiscUtils {
|
||||
/**
|
||||
* Used by the inspect command.
|
||||
*
|
||||
* @param args Arguments of the inspect command
|
||||
* @param args Arguments of a command, must be > 0 if console sender.
|
||||
* @param sender Command sender
|
||||
* @return The name of the player searched for, if the arguments are empty
|
||||
* player's own name is returned.
|
||||
* @return The name of the player (first argument or sender)
|
||||
*/
|
||||
public static String getPlayerDisplayname(String[] args, CommandSender sender) {
|
||||
public static String getPlayerName(String[] args, CommandSender sender) {
|
||||
String playerName = "";
|
||||
Plan plugin = getPlugin(Plan.class);
|
||||
boolean isConsole = !(sender instanceof Player);
|
||||
if (args.length > 0) {
|
||||
if (sender.hasPermission("plan.inspect.other")
|
||||
|| isConsole) {
|
||||
if (isConsole) {
|
||||
playerName = args[0];
|
||||
} else if (args.length > 0) {
|
||||
if (sender.hasPermission("plan.inspect.other")) {
|
||||
playerName = args[0];
|
||||
} else if (args[0].toLowerCase().equals(sender.getName().toLowerCase())) {
|
||||
playerName = sender.getName();
|
||||
@ -85,12 +84,7 @@ public class MiscUtils {
|
||||
sender.sendMessage(Phrase.COMMAND_NO_PERMISSION.toString());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Player player = plugin.getServer().getPlayer(UUIDFetcher.getUUIDOf(sender.getName()));
|
||||
playerName = player.getName();
|
||||
} catch (Exception e) {
|
||||
plugin.logError(Phrase.ERROR_CONSOLE_PLAYER.parse(Arrays.toString(args), isConsole + ""));
|
||||
}
|
||||
playerName = sender.getName();
|
||||
}
|
||||
return playerName;
|
||||
}
|
||||
@ -106,8 +100,8 @@ public class MiscUtils {
|
||||
players.addAll(Arrays.asList(Bukkit.getOfflinePlayers()));
|
||||
Set<OfflinePlayer> matches = new HashSet<>();
|
||||
players.parallelStream()
|
||||
.filter((OfflinePlayer player) -> (player.getName().toLowerCase().contains(search.toLowerCase())))
|
||||
.forEach((OfflinePlayer player) -> {
|
||||
.filter(player -> (player.getName().toLowerCase().contains(search.toLowerCase())))
|
||||
.forEach(player -> {
|
||||
matches.add(player);
|
||||
});
|
||||
return matches;
|
||||
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class SettingsTest {
|
||||
|
||||
public SettingsTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsTrue() {
|
||||
assertTrue("Webserver supposed to be enabled by default", Settings.WEBSERVER_ENABLED.isTrue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("sqlite",Settings.DB_TYPE.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumber() {
|
||||
assertEquals(8804,Settings.WEBSERVER_PORT.getNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPath() {
|
||||
assertEquals("Settings.WebServer.Enabled", Settings.WEBSERVER_ENABLED.getPath());
|
||||
}
|
||||
|
||||
}
|
@ -76,4 +76,13 @@ public class SessionDataTest {
|
||||
long result = test.getLength();
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLength2() {
|
||||
long exp = 5L;
|
||||
test = new SessionData(5L);
|
||||
test.endSession(10L);
|
||||
long result = test.getLength();
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,37 @@ public class ChatHandlingTest {
|
||||
assertTrue("Didn't update gender", data.getDemData().getGender() == Gender.MALE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemographicInformationNoInfo() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
ChatHandling.updateDemographicInformation("I'm serious", data);
|
||||
assertTrue("Updated gender", data.getDemData().getGender() == Gender.UNKNOWN);
|
||||
assertTrue("Updated age", data.getDemData().getAge() == -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemographicInformation100Age() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
ChatHandling.updateDemographicInformation("I'm 100", data);
|
||||
assertTrue("Updated age", data.getDemData().getAge() == -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemographicInformationNoTrigger() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
ChatHandling.updateDemographicInformation("18 male", data);
|
||||
assertTrue("Updated gender", data.getDemData().getGender() == Gender.UNKNOWN);
|
||||
assertTrue("Updated age", data.getDemData().getAge() == -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemographicInformationIgnore() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
ChatHandling.updateDemographicInformation("im sure you're male", data);
|
||||
assertTrue("Updated gender", data.getDemData().getGender() == Gender.UNKNOWN);
|
||||
assertTrue("Updated age", data.getDemData().getAge() == -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDemographicInformationAge() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
|
@ -5,20 +5,108 @@
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.KillHandling;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class KillHandlingTest {
|
||||
|
||||
|
||||
private Database db;
|
||||
private Plan plan;
|
||||
|
||||
public KillHandlingTest() {
|
||||
}
|
||||
|
||||
@Ignore("Get DB tests to work")@Test
|
||||
public void testProcessKillInfo() {
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug"+new Date().getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
}
|
||||
};
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
db.init();
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() throws SQLException {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessKillInfoPlayer() throws SQLException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
Player dead = MockUtils.mockPlayer2();
|
||||
db.saveUserData(dead.getUniqueId(), new UserData(dead, new DemographicsData()));
|
||||
KillHandling.processKillInfo(data, 10L, dead, "TestWeapon");
|
||||
KillData expected = new KillData(dead.getUniqueId(), 1, "TestWeapon", 10L);
|
||||
assertTrue("Didn't add the kill", data.getPlayerKills().size() == 1);
|
||||
KillData result = data.getPlayerKills().get(0);
|
||||
assertEquals(expected.getDate(), result.getDate());
|
||||
assertEquals(expected.getVictim(), result.getVictim());
|
||||
assertEquals(expected.getVictimUserID(), result.getVictimUserID());
|
||||
assertEquals(expected.getWeapon(), result.getWeapon());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessKillInfoException() throws SQLException, IOException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
db.close();
|
||||
Player dead = MockUtils.mockPlayer2();
|
||||
KillHandling.processKillInfo(data, 10L, dead, "TestWeapon");
|
||||
assertTrue("Added the kill", data.getPlayerKills().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessKillInfoMob() throws SQLException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
int mobKills = data.getMobKills();
|
||||
int exp = mobKills + 1;
|
||||
KillHandling.processKillInfo(data, 10L, null, "TestWeapon");
|
||||
int result = data.getMobKills();
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,11 +50,13 @@ public class LoginHandlingTest {
|
||||
@Test
|
||||
public void testProcessLoginInfo() throws UnknownHostException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
data.updateBanned(false);
|
||||
InetAddress ip = InetAddress.getByName("137.19.188.146");
|
||||
long time = 10L;
|
||||
int loginTimes = data.getLoginTimes();
|
||||
String nick = "TestProcessLoginInfo";
|
||||
LoginHandling.processLoginInfo(data, time, ip, false, nick, 1);
|
||||
LoginHandling.processLoginInfo(data, time, ip, true, nick, 1);
|
||||
assertTrue("Not Banned", data.isBanned());
|
||||
assertTrue("LastPlayed wrong", data.getLastPlayed() == time);
|
||||
assertTrue("Ip not added", data.getIps().contains(ip));
|
||||
assertTrue("Logintimes not +1", data.getLoginTimes() == loginTimes + 1);
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.LogoutHandling;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class LogoutHandlingTest {
|
||||
|
||||
public LogoutHandlingTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessLogoutInfo() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
data.setLastPlayed(10L);
|
||||
data.updateBanned(false);
|
||||
long time = 20L;
|
||||
Exception ex = null;
|
||||
try {
|
||||
LogoutHandling.processLogoutInfo(data, time, true);
|
||||
} catch (NullPointerException e) {
|
||||
ex = e;
|
||||
}
|
||||
assertTrue("Didn't catch endSessionException", ex != null);
|
||||
assertTrue("Last Played wrong", data.getLastPlayed() == 20L);
|
||||
assertTrue("Playtime wrong", data.getPlayTime()== 10L);
|
||||
assertTrue("Banned wrong", data.isBanned());
|
||||
}
|
||||
|
||||
}
|
@ -49,7 +49,7 @@ public class DeathInfoTest {
|
||||
public void testProcess() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
DeathInfo i = new DeathInfo(data.getUuid());
|
||||
i.process(data);
|
||||
assertTrue(i.process(data));
|
||||
assertEquals(1, data.getDeaths());
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class GamemodeInfoTest {
|
||||
data.setLastPlayed(1000L);
|
||||
long time = 2000L;
|
||||
GamemodeInfo i = new GamemodeInfo(data.getUuid(), time, GameMode.SURVIVAL);
|
||||
i.process(data);
|
||||
assertTrue(i.process(data));
|
||||
Long result = data.getGmTimes().get(GameMode.CREATIVE);
|
||||
assertTrue("Gamemode time was "+result, result == 1050L);
|
||||
result = data.getPlayTime();
|
||||
@ -67,5 +67,49 @@ public class GamemodeInfoTest {
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 1100L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessWrongUUID() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
data.setPlayTime(100L);
|
||||
data.setLastGamemode(GameMode.CREATIVE);
|
||||
data.setLastGmSwapTime(50L);
|
||||
data.setLastPlayed(1000L);
|
||||
long time = 2000L;
|
||||
GamemodeInfo i = new GamemodeInfo(null, time, GameMode.SURVIVAL);
|
||||
assertTrue(!i.process(data));
|
||||
Long result = data.getGmTimes().get(GameMode.CREATIVE);
|
||||
assertTrue("Gamemode time was "+result, result == 0L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 1000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.CREATIVE);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 50L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessNullGM() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
data.setPlayTime(100L);
|
||||
data.setLastGamemode(GameMode.CREATIVE);
|
||||
data.setLastGmSwapTime(50L);
|
||||
data.setLastPlayed(1000L);
|
||||
long time = 2000L;
|
||||
GamemodeInfo i = new GamemodeInfo(data.getUuid(), time, null);
|
||||
assertTrue(!i.process(data));
|
||||
Long result = data.getGmTimes().get(GameMode.CREATIVE);
|
||||
assertTrue("Gamemode time was "+result, result == 0L);
|
||||
result = data.getPlayTime();
|
||||
assertTrue("Playtime was"+result, result == 100L);
|
||||
result = data.getLastPlayed();
|
||||
assertTrue("Last Played was"+result, result == 1000L);
|
||||
GameMode lastGM = data.getLastGamemode();
|
||||
assertTrue("Last gm not Survival", lastGM == GameMode.CREATIVE);
|
||||
result = data.getLastGmSwapTime();
|
||||
assertTrue("Last swaptime was "+result, result == 50L);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.InfoType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class HandlingInfoTest {
|
||||
|
||||
public HandlingInfoTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUuid() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L ) {
|
||||
@Override
|
||||
public boolean process(UserData data) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
assertEquals(uuid,i.getUuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L ) {
|
||||
@Override
|
||||
public boolean process(UserData data) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
assertEquals(InfoType.CHAT,i.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTime() {
|
||||
UUID uuid = UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db");
|
||||
HandlingInfo i = new HandlingInfo(uuid, InfoType.CHAT, 10L ) {
|
||||
@Override
|
||||
public boolean process(UserData data) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
assertEquals(10L,i.getTime());
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KickInfo;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class KickInfoTest {
|
||||
|
||||
public KickInfoTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcess() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
KickInfo i = new KickInfo(data.getUuid());
|
||||
assertTrue(i.process(data));
|
||||
assertEquals(1, data.getTimesKicked());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class KillInfoTest {
|
||||
|
||||
private Database db;
|
||||
|
||||
public KillInfoTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug"+new Date().getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
}
|
||||
};
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
db.init();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws SQLException {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcess() throws SQLException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
Player dead = MockUtils.mockPlayer2();
|
||||
db.saveUserData(dead.getUniqueId(), new UserData(dead, new DemographicsData()));
|
||||
KillInfo i = new KillInfo(data.getUuid(), 10L, dead, "TestWeapon");
|
||||
assertTrue(i.process(data));
|
||||
KillData expected = new KillData(dead.getUniqueId(), 1, "TestWeapon", 10L);
|
||||
assertTrue("Didn't add the kill", data.getPlayerKills().size() == 1);
|
||||
KillData result = data.getPlayerKills().get(0);
|
||||
assertEquals(expected.getDate(), result.getDate());
|
||||
assertEquals(expected.getVictim(), result.getVictim());
|
||||
assertEquals(expected.getVictimUserID(), result.getVictimUserID());
|
||||
assertEquals(expected.getWeapon(), result.getWeapon());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMobKill() throws SQLException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
KillInfo i = new KillInfo(data.getUuid(), 10L, null, "TestWeapon");
|
||||
assertTrue(i.process(data));
|
||||
assertTrue("Added a kill", data.getPlayerKills().isEmpty());
|
||||
assertEquals(1, data.getMobKills());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMobKillWrongUUID() throws SQLException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
KillInfo i = new KillInfo(null, 10L, null, "TestWeapon");
|
||||
assertTrue(!i.process(data));
|
||||
assertTrue("Added a kill", data.getPlayerKills().isEmpty());
|
||||
assertEquals(0, data.getMobKills());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -10,7 +10,6 @@ import java.net.UnknownHostException;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.LoginHandling;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.LoginInfo;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.LogoutHandling;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.LogoutInfo;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class LogoutInfoTest {
|
||||
|
||||
public LogoutInfoTest() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcess() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
data.setLastPlayed(10L);
|
||||
data.updateBanned(false);
|
||||
long time = 20L;
|
||||
Exception ex = null;
|
||||
data.setLastGamemode(GameMode.SURVIVAL);
|
||||
LogoutInfo i = new LogoutInfo(data.getUuid(), time, true, GameMode.CREATIVE);
|
||||
try {
|
||||
assertTrue(i.process(data));
|
||||
} catch (NullPointerException e) {
|
||||
ex = e;
|
||||
}
|
||||
assertTrue("Caught endSessionException", ex != null);
|
||||
assertTrue("Last Played wrong", data.getLastPlayed() == 20L);
|
||||
assertTrue("Playtime wrong", data.getPlayTime()== 10L);
|
||||
assertTrue("Banned wrong", data.isBanned());
|
||||
assertTrue("Didn't process gamemode", data.getLastGamemode() == GameMode.CREATIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessWrongUUID() {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
data.setLastPlayed(10L);
|
||||
data.updateBanned(false);
|
||||
long time = 20L;
|
||||
Exception ex = null;
|
||||
LogoutInfo i = new LogoutInfo(null, time, true, GameMode.CREATIVE);
|
||||
try {
|
||||
assertTrue(!i.process(data));
|
||||
} catch (NullPointerException e) {
|
||||
ex = e;
|
||||
}
|
||||
assertTrue("Caught endSessionException", ex == null);
|
||||
assertTrue("Last Played wrong", data.getLastPlayed() == 10L);
|
||||
assertTrue("Playtime wrong", data.getPlayTime()== 0L);
|
||||
assertTrue("Banned wrong", !data.isBanned());
|
||||
assertTrue("Didn't process gamemode", data.getLastGamemode() == GameMode.SURVIVAL);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.DemographicsData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.ReloadInfo;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
public class ReloadInfoTest {
|
||||
|
||||
public ReloadInfoTest() {
|
||||
}
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
Plan plan = t.getPlanMock();
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
}
|
||||
@Test
|
||||
public void testProcess() throws UnknownHostException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
InetAddress ip = InetAddress.getByName("137.19.188.146");
|
||||
long time = 10L;
|
||||
int loginTimes = data.getLoginTimes();
|
||||
String nick = "TestProcessLoginInfo";
|
||||
ReloadInfo i = new ReloadInfo(data.getUuid(), time, ip, true, nick, GameMode.CREATIVE);
|
||||
assertTrue(i.process(data));
|
||||
assertTrue("LastPlayed wrong: " + data.getLastPlayed(), data.getLastPlayed() == time);
|
||||
assertTrue("Ip not added", data.getIps().contains(ip));
|
||||
assertTrue("Logintimes +1", data.getLoginTimes() == loginTimes);
|
||||
assertTrue("Nick not added", data.getNicknames().contains(nick));
|
||||
assertTrue("Nick not last nick", data.getLastNick().equals(nick));
|
||||
String geo = data.getDemData().getGeoLocation();
|
||||
assertTrue("Wrong location " + geo, geo.equals("United States"));
|
||||
assertTrue("Didn't process gamemode", data.getLastGamemode() == GameMode.CREATIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessWrongUUID() throws UnknownHostException {
|
||||
UserData data = new UserData(MockUtils.mockPlayer(), new DemographicsData());
|
||||
InetAddress ip = InetAddress.getByName("137.19.188.146");
|
||||
long time = 10L;
|
||||
String nick = "TestProcessLoginInfo";
|
||||
ReloadInfo i = new ReloadInfo(null, time, ip, true, nick, GameMode.CREATIVE);
|
||||
assertTrue(!i.process(data));
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -58,6 +59,12 @@ public class DatabaseTest {
|
||||
TestInit t = new TestInit();
|
||||
assertTrue("Not set up", t.setUp());
|
||||
plan = t.getPlanMock();
|
||||
db = new SQLiteDB(plan, "debug"+new Date().getTime()) {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
}
|
||||
};
|
||||
PowerMock.mockStatic(JavaPlugin.class);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
@ -69,12 +76,6 @@ public class DatabaseTest {
|
||||
if (f.exists()) {
|
||||
rows = Files.lines(f.toPath(), Charset.defaultCharset()).collect(Collectors.toList()).size();
|
||||
}
|
||||
db = new SQLiteDB(plan, "debug") {
|
||||
@Override
|
||||
public void startConnectionPingTask(Plan plugin) {
|
||||
|
||||
}
|
||||
};
|
||||
// BukkitRunnable mockRunnable = PowerMockito.mock(BukkitRunnable.class);
|
||||
// when(mockRunnable.runTaskTimerAsynchronously(plan, anyLong(), anyLong())).thenReturn(null);
|
||||
// whenNew(BukkitRunnable.class).withNoArguments().thenReturn(mockRunnable);
|
||||
@ -82,7 +83,7 @@ public class DatabaseTest {
|
||||
PowerMock.mockStatic(Bukkit.class);
|
||||
OfflinePlayer op = MockUtils.mockPlayer();
|
||||
EasyMock.expect(Bukkit.getOfflinePlayer(UUID.fromString("45b0dfdb-f71d-4cf3-8c21-27c9d4c651db"))).andReturn(op);
|
||||
op = MockUtils.mockPlayer2();
|
||||
op = MockUtils.mockPlayer2();
|
||||
EasyMock.expect(Bukkit.getOfflinePlayer(UUID.fromString("ec94a954-1fa1-445b-b09b-9b698519af80"))).andReturn(op);
|
||||
PowerMock.replay(Bukkit.class);
|
||||
// BukkitScheduler mockScheduler = Mockito.mock(BukkitScheduler.class);
|
||||
@ -152,7 +153,7 @@ public class DatabaseTest {
|
||||
};
|
||||
db.giveUserDataToProcessors(data.getUuid(), process);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSaveMultipleUserData() throws SQLException {
|
||||
db.init();
|
||||
|
@ -5,22 +5,25 @@
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.utilities;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.easymock.PowerMock;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
/**
|
||||
@ -28,12 +31,12 @@ import test.java.utils.TestInit;
|
||||
* @author Risto
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(JavaPlugin.class)
|
||||
@PrepareForTest({JavaPlugin.class, Bukkit.class})
|
||||
public class MiscUtilsTest {
|
||||
|
||||
public MiscUtilsTest() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TestInit t = new TestInit();
|
||||
@ -44,9 +47,15 @@ public class MiscUtilsTest {
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
EasyMock.expect(JavaPlugin.getPlugin(Plan.class)).andReturn(plan);
|
||||
PowerMock.replay(JavaPlugin.class);
|
||||
// PowerMock.verify(JavaPlugin.class);
|
||||
|
||||
PowerMock.mockStatic(Bukkit.class);
|
||||
OfflinePlayer op = MockUtils.mockPlayer();
|
||||
OfflinePlayer op2 = MockUtils.mockPlayer2();
|
||||
OfflinePlayer[] ops = new OfflinePlayer[]{op, op2};
|
||||
EasyMock.expect(Bukkit.getOfflinePlayers()).andReturn(ops);
|
||||
PowerMock.replay(Bukkit.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCheckVersion() {
|
||||
String versionG = "2.10.9";
|
||||
@ -54,51 +63,108 @@ public class MiscUtilsTest {
|
||||
String exp = Phrase.VERSION_NEW_AVAILABLE.parse(versionG);
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCheckVersion2() {
|
||||
String result = MiscUtils.checkVersion("3.0.0", "2.10.9");
|
||||
String exp = Phrase.VERSION_LATEST+"";
|
||||
String exp = Phrase.VERSION_LATEST + "";
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCheckVersion3() {
|
||||
String result = MiscUtils.checkVersion("2.11.0", "2.10.9");
|
||||
String exp = Phrase.VERSION_LATEST+"";
|
||||
String exp = Phrase.VERSION_LATEST + "";
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCheckVersion4() {
|
||||
String result = MiscUtils.checkVersion("2.11.0", "2.11.0");
|
||||
String exp = Phrase.VERSION_LATEST+"";
|
||||
String exp = Phrase.VERSION_LATEST + "";
|
||||
assertEquals(exp, result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetPlayerDisplayname() {
|
||||
System.out.println("getPlayerDisplayname");
|
||||
String[] args = null;
|
||||
CommandSender sender = null;
|
||||
String expResult = "";
|
||||
String result = MiscUtils.getPlayerDisplayname(args, sender);
|
||||
public void testGetPlayerDisplaynameArgsPerm() {
|
||||
String[] args = new String[]{"Rsl1122", "Test"};
|
||||
CommandSender sender = MockUtils.mockPlayer();
|
||||
String expResult = "Rsl1122";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameArgsNoPerm() {
|
||||
String[] args = new String[]{"Rsl1122", "Test"};
|
||||
CommandSender sender = MockUtils.mockPlayer();
|
||||
String expResult = "Rsl1122";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameNoArgsPerm() {
|
||||
String[] args = new String[]{};
|
||||
CommandSender sender = MockUtils.mockPlayer();
|
||||
String expResult = "TestName";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameNoArgsNoPerm() {
|
||||
String[] args = new String[]{};
|
||||
CommandSender sender = MockUtils.mockPlayer2();
|
||||
String expResult = "TestName2";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameOwnNameNoPerm() {
|
||||
String[] args = new String[]{"testname2"};
|
||||
CommandSender sender = MockUtils.mockPlayer2();
|
||||
String expResult = "TestName2";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
assertEquals(expResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayerDisplaynameConsole() {
|
||||
String[] args = new String[]{"TestConsoleSender"};
|
||||
CommandSender sender = MockUtils.mockConsoleSender();
|
||||
String expResult = "TestConsoleSender";
|
||||
String result = MiscUtils.getPlayerName(args, sender);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetMatchingDisplaynames() {
|
||||
System.out.println("getMatchingDisplaynames");
|
||||
String search = "";
|
||||
Set<OfflinePlayer> expResult = null;
|
||||
String search = "testname";
|
||||
OfflinePlayer exp1 = MockUtils.mockPlayer();
|
||||
OfflinePlayer exp2 = MockUtils.mockPlayer2();
|
||||
Set<OfflinePlayer> result = MiscUtils.getMatchingDisplaynames(search);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
assertEquals(2, result.size());
|
||||
for (OfflinePlayer r : result) {
|
||||
boolean equalToExp1 = r.getName().equals(exp1.getName());
|
||||
boolean equalToExp2 = r.getName().equals(exp2.getName());
|
||||
if (!(equalToExp1 || equalToExp2)) {
|
||||
fail("Unknown result!: "+r.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMatchingDisplaynames2() {
|
||||
String search = "2";
|
||||
OfflinePlayer exp2 = MockUtils.mockPlayer2();
|
||||
Set<OfflinePlayer> result = MiscUtils.getMatchingDisplaynames(search);
|
||||
assertEquals(1, result.size());
|
||||
for (OfflinePlayer r : result) {
|
||||
if (!r.getName().equals(exp2.getName())) {
|
||||
fail("Unknown result!: "+r.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.utilities.comparators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.GamemodeInfo;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.HandlingInfoTimeComparator;
|
||||
import org.bukkit.GameMode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class HandlingInfoTimeComparatorTest {
|
||||
|
||||
public HandlingInfoTimeComparatorTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompare() {
|
||||
List<HandlingInfo> i = new ArrayList<>();
|
||||
GamemodeInfo one = new GamemodeInfo(null, 500L, GameMode.CREATIVE);
|
||||
i.add(one);
|
||||
GamemodeInfo two = new GamemodeInfo(null, 400L, GameMode.CREATIVE);
|
||||
i.add(two);
|
||||
GamemodeInfo three = new GamemodeInfo(null, 100L, GameMode.CREATIVE);
|
||||
i.add(three);
|
||||
GamemodeInfo four = new GamemodeInfo(null, 700L, GameMode.CREATIVE);
|
||||
i.add(four);
|
||||
Collections.sort(i, new HandlingInfoTimeComparator());
|
||||
assertEquals(three, i.get(0));
|
||||
assertEquals(two, i.get(1));
|
||||
assertEquals(one, i.get(2));
|
||||
assertEquals(four, i.get(3));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import org.mockito.Mockito;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
@ -32,6 +33,7 @@ public class MockUtils {
|
||||
when(p.isBanned()).thenReturn(true);
|
||||
when(p.isOnline()).thenReturn(true);
|
||||
when(p.getName()).thenReturn("TestName");
|
||||
when(p.hasPermission("plan.inspect.other")).thenReturn(true);
|
||||
return p;
|
||||
}
|
||||
public static Player mockPlayer2() {
|
||||
@ -44,6 +46,7 @@ public class MockUtils {
|
||||
when(p.isOp()).thenReturn(false);
|
||||
when(p.isBanned()).thenReturn(false);
|
||||
when(p.isOnline()).thenReturn(false);
|
||||
when(p.hasPermission("plan.inspect.other")).thenReturn(false);
|
||||
when(p.getName()).thenReturn("TestName2");
|
||||
return p;
|
||||
}
|
||||
@ -61,4 +64,9 @@ public class MockUtils {
|
||||
when(p.getName()).thenReturn("TestName");
|
||||
return p;
|
||||
}
|
||||
|
||||
public static CommandSender mockConsoleSender() {
|
||||
CommandSender s = PowerMockito.mock(CommandSender.class);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.file.Files;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.Server;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
@ -52,7 +53,7 @@ public class TestInit {
|
||||
when(mockServer.getIp()).thenReturn("0.0.0.0");
|
||||
// Mockito.doReturn("0.0.0.0").when(mockServer).getIp();
|
||||
when(planMock.getServer()).thenReturn(mockServer);
|
||||
// Mockito.doReturn("0.0.0.0").when(planMock).getServer().getIp();
|
||||
// Mockito.doReturn("0.0.0.0").when(planMock).getServer().getIp();
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
|
Loading…
Reference in New Issue
Block a user