Work on some unit tests for #7 and reorganize part of the config.

This commit is contained in:
graywolf336 2014-07-22 20:58:05 -05:00
parent b63773c7a9
commit 6b8dec6c7b
8 changed files with 159 additions and 54 deletions

View File

@ -24,6 +24,7 @@ import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.beans.SimpleLocation;
import com.graywolf336.jail.enums.LangString;
import com.graywolf336.jail.enums.Settings;
/**
* Handles all the saving and loading of the plugin's data.
@ -61,7 +62,7 @@ public class JailIO {
/** Loads the language file from disk, if there is none then we save the default one. */
@SuppressWarnings("deprecation")
public void loadLanguage() {
String language = pl.getConfig().getString("system.language");
String language = pl.getConfig().getString(Settings.LANGUAGE.getPath());
boolean save = false;
File langFile = new File(pl.getDataFolder(), language + ".yml");

View File

@ -84,7 +84,7 @@ public class JailCommand implements Command {
Long time = 10L;
try {
if(params.getTime() == null) {
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m"));
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.DEFAULTTIME.getPath(), "30m"));
}else if(params.getTime() == String.valueOf(-1)) {
time = -1L;
}else {

View File

@ -15,7 +15,7 @@ import com.graywolf336.jail.enums.LangString;
needsPlayer = false,
pattern = "time|t",
permission = "jail.command.jailtime",
usage = "/jail time <add|remove|show> <player> <time>"
usage = "/jail time [add|remove|show] [player] <time>"
)
public class JailTimeCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {

View File

@ -19,20 +19,21 @@ public enum Settings {
COMMANDPENALTY("jailing.during.commandPenalty"),
COMMANDPROTECTION("jailing.during.commandProtection"),
COMMANDWHITELIST("jailing.during.commandWhitelist"),
CONFIGVERSION("system.version"),
COUNTDOWNTIMEOFFLINE("jailing.during.countDownTimeWhileOffline"),
CROPTRAMPLINGPENALTY("jailing.during.cropTramplingPenalty"),
CROPTRAMPLINGPROTECTION("jailing.during.cropTramplingProtection"),
DEBUG("system.debug"),
DEFAULTJAIL("jailing.jail.defaultJail"),
DEFAULTJAIL("jailing.jail.default.jail"),
DEFAULTTIME("jailing.jail.default.time"),
ENDERMENPROTECTION("jails.endermenProtection"),
EXPLOSIONPROTECTION("jails.explosionProtection"),
FOODCONTROL("jailing.during.foodControl"),
FOODCONTROLMAX("jailing.during.foodControlMax"),
FOODCONTROLMIN("jailing.during.foodControlMin"),
FOODCONTROL("jailing.during.foodControl.enabled"),
FOODCONTROLMAX("jailing.during.foodControl.max"),
FOODCONTROLMIN("jailing.during.foodControl.min"),
IGNORESLEEPINGSTATE("jailing.during.ignoreSleeping"),
JAILSTICKENABLED("jailstick.enabled"),
JAILSTICKSTICKS("jailstick.sticks"),
JAILDEFAULTTIME("jailing.jail.defaultTime"),
JAILEDGAMEMODE("jailing.jail.gameMode"),
JAILEDINVENTORYBLACKLIST("jailing.jail.inventory.blacklist"),
JAILEDSTOREINVENTORY("jailing.jail.inventory.store"),
@ -40,7 +41,9 @@ public enum Settings {
JAILPAYITEM("jailpay.item"),
JAILPAYPRICEPERMINUTE ("jailpay.pricePerMinute"),
JAILPAYPRICEINFINITE ("jailpay.priceInfinite"),
LOGJAILINGTOCONSOLE("jailing.jail.logToConsole"),
LANGUAGE("system.language"),
LOGJAILINGTOCONSOLE("jailing.jail.log.console"),
LOGJAILINGTOPROFILE("jailing.jail.log.profile"),
MAXAFKTIME("jailing.during.maxAFKTime"),
MOVEPENALTY("jailing.during.movePenalty"),
MOVEPROTECTION("jailing.during.moveProtection"),

View File

@ -192,8 +192,8 @@ public class LegacyManager {
break;
case DefaultJailTime:
if(global.contains(s.getString())) {
c.set(Settings.JAILDEFAULTTIME.getPath(), OldSettings.getGlobalInt(global, s));
pl.debug(Settings.JAILDEFAULTTIME.getPath() + " <-- " + s.getString());
c.set(Settings.DEFAULTTIME.getPath(), OldSettings.getGlobalInt(global, s));
pl.debug(Settings.DEFAULTTIME.getPath() + " <-- " + s.getString());
count++;
}
break;

View File

@ -29,19 +29,23 @@ public class JailingListener implements Listener {
@EventHandler(ignoreCancelled=true)
public void preJailingListener(PrePrisonerJailedEvent event) {
if(pl.getConfig().getBoolean(Settings.LOGJAILINGTOPROFILE.getPath())) {
pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(),
event.getPrisoner().getLastKnownName(),
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
}
}
@EventHandler(ignoreCancelled=true)
public void preJailingListener(PrePrisonerJailedByJailStickEvent event) {
if(pl.getConfig().getBoolean(Settings.LOGJAILINGTOPROFILE.getPath())) {
pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(),
event.getPrisoner().getLastKnownName(),
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
}
}
@EventHandler
public void setInmatesClothing(PrisonerJailedEvent event) {

View File

@ -1,5 +1,5 @@
system:
configVersion: 3
version: 3
debug: false
language: 'en'
updates:
@ -30,9 +30,10 @@ jailing:
countDownTimeWhileOffline: false
cropTramplingPenalty: 5m
cropTramplingProtection: true
foodControl: true
foodControlMax: 20
foodControlMin: 10
foodControl:
enabled: true
max: 20
min: 10
ignoreSleeping: true
maxAFKTime: 10m #in minutes
movePenalty: 10m
@ -57,14 +58,16 @@ jailing:
legs: leather_leggings~175,105,33
boots: leather_boots~175,105,33
commands: []
defaultJail: nearest #the jail nearest to the player
defaultTime: 30m #default the time to 30 minutes, if no time
default:
jail: nearest #the jail nearest to the player
time: 30m #default the time to 30 minutes, if no time
gameMode: adventure
inventory:
blacklist: [] #items they aren't allowed to keep
store: true
logToConsole: true
logToProfile: false
log:
console: true
profile: true
release:
backToPreviousPosition: false
commands: []

View File

@ -3,6 +3,8 @@ package test.java.com.graywolf336.jail;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import java.util.List;
import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -14,6 +16,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import test.java.com.graywolf336.jail.util.TestInstanceCreator;
import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.enums.Settings;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
@ -46,40 +49,131 @@ public class TestJailStuff {
}
@Test
public void testDefaultConfig() {
assertEquals("The config version is not 3.", 3, main.getConfig().getInt("system.configVersion"));
//This is enabled by default in testing.
//assertFalse("Default debugging is on.", main.getConfig().getBoolean("system.debug"));
assertEquals("Default updating channel is not bukkit.", "bukkit", main.getConfig().getString("system.updates.channel"));
assertTrue("Default updating notifications is false.", main.getConfig().getBoolean("system.updates.notification"));
assertEquals("Default updating time checking is not 1h.", "1h", main.getConfig().getString("system.updates.time"));
public void testSystemDefaultConfig() {
assertEquals("The config version is not 3.", 3, main.getConfig().getInt(Settings.CONFIGVERSION.getPath()));
assertTrue("Default debugging is off.", main.getConfig().getBoolean(Settings.DEBUG.getPath()));
assertEquals("Default language is not 'en'.", "en", main.getConfig().getString(Settings.LANGUAGE.getPath()));
assertEquals("Default updating channel is not bukkit.", "bukkit", main.getConfig().getString(Settings.UPDATECHANNEL.getPath()));
assertTrue("Default updating notifications is false.", main.getConfig().getBoolean(Settings.UPDATENOTIFICATIONS.getPath()));
assertEquals("Default updating time checking is not 1h.", "1h", main.getConfig().getString(Settings.UPDATETIME.getPath()));
assertTrue("Default usage of bukkit timer is false.", main.getConfig().getBoolean(Settings.USEBUKKITTIMER.getPath()));
}
//Storage system
@Test
public void testStorageDefaultConfig() {
assertEquals("The default storage system is not flatfile.", "flatfile", main.getConfig().getString("storage.type"));
assertEquals("The default mysql host is not localhost.", "localhost", main.getConfig().getString("storage.mysql.host"));
assertEquals("The default mysql port is not 3306.", 3306, main.getConfig().getInt("storage.mysql.port"));
assertEquals("The default mysql username is not root.", "root", main.getConfig().getString("storage.mysql.username"));
assertEquals("The default mysql password is not password.", "password", main.getConfig().getString("storage.mysql.password"));
assertEquals("The default mysql database is not jailDatabase.", "jailDatabase", main.getConfig().getString("storage.mysql.database"));
assertEquals("The default mysql prefix is not j3_.", "j3_", main.getConfig().getString("storage.mysql.prefix"));
}
//Settings pertaining to being jailed
assertFalse("Default setting for counting down time while prisoner is offline is true.", main.getConfig().getBoolean("jailing.during.countDownTimeWhileOffline"));
assertTrue("Default setting for ignoring sleeping is false.", main.getConfig().getBoolean("jailing.during.ignoreSleeping"));
assertTrue("Default setting for opening a chest is false.", main.getConfig().getBoolean("jailing.during.openChest"));
@Test
public void testDuringJailingDefaultConfig() {
// block breaking section
assertEquals("Default setting for block break penalty is not 5m.", "5m", main.getConfig().getString(Settings.BLOCKBREAKPENALTY.getPath()));
assertTrue("Default setting for block break proection is false.", main.getConfig().getBoolean(Settings.BLOCKBREAKPROTECTION.getPath()));
//Settings pertaining to when jailed
assertTrue("Default setting for automatically muting is false.", main.getConfig().getBoolean("jailing.jail.automaticMute"));
assertFalse("Default setting for broadcasting a jailing is true.", main.getConfig().getBoolean("jailing.jail.broadcastJailing"));
assertEquals("Default setting for commands contains information.", 0, main.getConfig().getList("jailing.jail.commands").size());
assertEquals("Default setting for default jail is not 'nearest' but something else.", "nearest", main.getConfig().getString("jailing.jail.defaultJail"));
assertEquals("Default setting for time is not 30 minutes.", "30m", main.getConfig().getString("jailing.jail.defaultTime"));
assertFalse("Default setting for deleting inventory is true.", main.getConfig().getBoolean("jailing.jail.deleteInventory"));
assertTrue("Default setting for logging to console when someone is jailed is false.", main.getConfig().getBoolean("jailing.jail.logToConsole"));
assertFalse("Default setting for logging to prisoner's profile is true.", main.getConfig().getBoolean("jailing.jail.logToProfile"));
assertTrue("Default setting for storing prisoner's inventory upon jailing is false.", main.getConfig().getBoolean("jailing.jail.inventory.store"));
List<String> blockbreakwhite = main.getConfig().getStringList(Settings.BLOCKBREAKWHITELIST.getPath());
assertTrue("Default block breaking doesn't contain crops.", blockbreakwhite.contains("crops"));
assertTrue("Default block breaking doesn't contain carrot.", blockbreakwhite.contains("carrot"));
assertTrue("Default block breaking doesn't contain potato.", blockbreakwhite.contains("potato"));
//Settings pertaining to after a prisoner is released
assertFalse("Default setting for releasing back to previous position is true.", main.getConfig().getBoolean("jailing.release.backToPreviousPosition"));
assertEquals("Default setting for commands contains information.", 0, main.getConfig().getList("jailing.release.commands").size());
assertTrue("Default setting for teleporting them out of the jail is false.", main.getConfig().getBoolean("jailing.release.teleport"));
// block placing section
assertEquals("Default setting for block place penalty is not 5m.", "5m", main.getConfig().getString(Settings.BLOCKPLACEPENALTY.getPath()));
assertTrue("Default setting for block place proection is false.", main.getConfig().getBoolean(Settings.BLOCKPLACEPROTECTION.getPath()));
List<String> blockplacewhite = main.getConfig().getStringList(Settings.BLOCKPLACEWHITELIST.getPath());
assertTrue("Default block placing whitelist doesn't contain crops.", blockplacewhite.contains("crops"));
assertTrue("Default block placing whitelist doesn't contain carrot.", blockplacewhite.contains("carrot"));
assertTrue("Default block placing whitelist doesn't contain potato.", blockplacewhite.contains("potato"));
// command protection section
assertEquals("Default setting for command penalty is not 5m.", "5m", main.getConfig().getString(Settings.COMMANDPENALTY.getPath()));
assertTrue("Default setting for command proection is false.", main.getConfig().getBoolean(Settings.COMMANDPROTECTION.getPath()));
List<String> commandwhite = main.getConfig().getStringList(Settings.COMMANDWHITELIST.getPath());
assertTrue("Default command whitelist doesn't contain /ping.", commandwhite.contains("/ping"));
assertTrue("Default command whitelist doesn't contain /list.", commandwhite.contains("/list"));
assertTrue("Default command whitelist doesn't contain /jail status.", commandwhite.contains("/jail status"));
assertTrue("Default command whitelist doesn't contain /jail pay.", commandwhite.contains("/jail pay"));
assertFalse("Default setting for counting down time while prisoner is offline is true.", main.getConfig().getBoolean(Settings.COUNTDOWNTIMEOFFLINE.getPath()));
assertEquals("Default setting for crop trampling penalty is not 5m.", "5m", main.getConfig().getString(Settings.CROPTRAMPLINGPENALTY.getPath()));
assertTrue("Default setting for crop trampling proection is false.", main.getConfig().getBoolean(Settings.CROPTRAMPLINGPROTECTION.getPath()));
assertTrue("Default setting for food control enabled is false.", main.getConfig().getBoolean(Settings.FOODCONTROL.getPath()));
assertEquals("Default setting for food control max is not 20.", 20, main.getConfig().getInt(Settings.FOODCONTROLMAX.getPath()));
assertEquals("Default setting for food control min is not 10.", 10, main.getConfig().getInt(Settings.FOODCONTROLMIN.getPath()));
assertTrue("Default setting for ignoring sleeping is false.", main.getConfig().getBoolean(Settings.IGNORESLEEPINGSTATE.getPath()));
assertEquals("Default setting max afk time is not 10 minutes.", "10m", main.getConfig().getString(Settings.MAXAFKTIME.getPath()));
assertEquals("Default setting move penalty is not 10 minutes.", "10m", main.getConfig().getString(Settings.MOVEPENALTY.getPath()));
assertTrue("Default setting for move protection is false.", main.getConfig().getBoolean(Settings.MOVEPROTECTION.getPath()));
assertTrue("Default setting for opening a chest is false.", main.getConfig().getBoolean(Settings.PRISONEROPENCHEST.getPath()));
// interaction blocks protection section
List<String> interactionBlocks = main.getConfig().getStringList(Settings.PREVENTINTERACTIONBLOCKS.getPath());
assertTrue("Default interaction blocks whitelist doesn't contain wooden_door.", interactionBlocks.contains("wooden_door"));
assertTrue("Default interaction blocks whitelist doesn't contain iron_door_block.", interactionBlocks.contains("iron_door_block"));
assertEquals("Default setting for preventing interaction blocks penalty is not 5m.", "5m", main.getConfig().getString(Settings.PREVENTINTERACTIONBLOCKSPENALTY.getPath()));
// interaction items protection section
assertTrue("Default interaction items whitelist isn't empty.", main.getConfig().getStringList(Settings.PREVENTINTERACTIONITEMS.getPath()).isEmpty());
assertEquals("Default setting for preventing interaction blocks penalty is not 5m.", "5m", main.getConfig().getString(Settings.PREVENTINTERACTIONBLOCKSPENALTY.getPath()));
assertTrue("Default setting for recieving messages is false.", main.getConfig().getBoolean(Settings.RECIEVEMESSAGES.getPath()));
assertFalse("Default setting for scoreboard being enabled is true.", main.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath()));
assertEquals("Default setting for the scoreboard title is not Jail Info.", "Jail Info", main.getConfig().getString(Settings.SCOREBOARDTITLE.getPath()));
assertEquals("Default setting for the scoreboard time language is not &aTime:", "&aTime:", main.getConfig().getString(Settings.SCOREBOARDTIME.getPath()));
}
@Test
public void testJailingDefaultConfig() {
assertTrue("Default setting for automatically muting is false.", main.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()));
assertFalse("Default setting for broadcasting a jailing is true.", main.getConfig().getBoolean(Settings.BROADCASTJAILING.getPath()));
assertTrue("Default setting for jail clothing is not enabled.", main.getConfig().getBoolean(Settings.CLOTHINGENABLED.getPath()));
assertEquals("Default setting for jail clothing's helmet is not leather_helmet~175,105,33.", "leather_helmet~175,105,33", main.getConfig().getString(Settings.CLOTHINGHELMET.getPath()));
assertEquals("Default setting for jail clothing's chestplate is not leather_chestplate~175,105,33.", "leather_chestplate~175,105,33", main.getConfig().getString(Settings.CLOTHINGCHEST.getPath()));
assertEquals("Default setting for jail clothing's legs is not leather_leggings~175,105,33.", "leather_leggings~175,105,33", main.getConfig().getString(Settings.CLOTHINGLEGS.getPath()));
assertEquals("Default setting for jail clothing's boots is not leather_boots~175,105,33.", "leather_boots~175,105,33", main.getConfig().getString(Settings.CLOTHINGBOOTS.getPath()));
assertTrue("Default setting for commands is not empty.", main.getConfig().getStringList(Settings.COMMANDSONJAIL.getPath()).isEmpty());
assertEquals("Default setting for default jail is not 'nearest' but something else.", "nearest", main.getConfig().getString(Settings.DEFAULTJAIL.getPath()));
assertEquals("Default setting for time is not 30 minutes.", "30m", main.getConfig().getString(Settings.DEFAULTTIME.getPath()));
assertEquals("Default setting for the prisoner's default gamemode is not adventure.", "adventure", main.getConfig().getString(Settings.JAILEDGAMEMODE.getPath()));
assertTrue("Default setting for inventory storing blacklist is not empty.", main.getConfig().getStringList(Settings.JAILEDINVENTORYBLACKLIST.getPath()).isEmpty());
assertTrue("Default setting for inventory storing is false.", main.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath()));
assertTrue("Default setting for logging to console when someone is jailed is false.", main.getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath()));
assertTrue("Default setting for logging to prisoner's profile is false.", main.getConfig().getBoolean(Settings.LOGJAILINGTOPROFILE.getPath()));
}
@Test
public void testReleaseDefaultConfig() {
assertFalse("Default setting for releasing back to previous position is true.", main.getConfig().getBoolean(Settings.RELEASETOPREVIOUSPOSITION.getPath()));
assertTrue("Default setting for commands is not empty.", main.getConfig().getStringList(Settings.COMMANDSONRELEASE.getPath()).isEmpty());
assertFalse("Default setting for restoring previous gamemode is true.", main.getConfig().getBoolean(Settings.RESTOREPREVIOUSGAMEMODE.getPath()));
assertTrue("Default setting for teleporting them out of the jail is false.", main.getConfig().getBoolean(Settings.TELEPORTONRELEASE.getPath()));
}
@Test
public void testJailsDefaultConfig() {
assertTrue("Default setting for protecting jails from endermen is false.", main.getConfig().getBoolean(Settings.ENDERMENPROTECTION.getPath()));
assertTrue("Default setting for protecting jails from explosions is false.", main.getConfig().getBoolean(Settings.EXPLOSIONPROTECTION.getPath()));
}
@Test
public void testJailPayDefaultConfig() {
assertFalse("Default setting for jail pay enabled is true, meaning Jail Pay somehow got enabled in testing.", main.getConfig().getBoolean(Settings.JAILPAYENABLED.getPath()));
assertEquals("Default setting for jail pay item is not air.", "air", main.getConfig().getString(Settings.JAILPAYITEM.getPath()));
assertEquals("Default setting for jail pay price per minute is not 1.5.", 1.5, main.getConfig().getDouble(Settings.JAILPAYPRICEPERMINUTE.getPath()), 0);
assertEquals("Default setting for jail pay price for infinite is not 10000.", 10000, main.getConfig().getDouble(Settings.JAILPAYPRICEINFINITE.getPath()), 0);
}
@Test
public void testJailStickDefaultConfig() {
assertTrue("Default setting for jail stick enabled is false.", main.getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath()));
List<String> jailSticks = main.getConfig().getStringList(Settings.JAILSTICKSTICKS.getPath());
assertTrue("Default setting for jail sticks doesn't contain a stick with item of stick.", jailSticks.contains("stick,30m,,Running away,-1"));
assertTrue("Default setting for jail sticks doesn't contain a stick with item of blaze_rod.", jailSticks.contains("blaze_rod,15m,,Having too much fun,6"));
}
}