mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-09-27 14:59:09 +02:00
formatting applied to most of the source code to tidy things up, and misc refactors
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package com.gmail.nossr50;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.ChatConfig;
|
||||
@@ -11,7 +18,11 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.util.*;
|
||||
import com.gmail.nossr50.util.EventUtils;
|
||||
import com.gmail.nossr50.util.MaterialMapStore;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TransientEntityTracker;
|
||||
import com.gmail.nossr50.util.blockmeta.ChunkManager;
|
||||
import com.gmail.nossr50.util.compat.CompatibilityManager;
|
||||
import com.gmail.nossr50.util.platform.MinecraftGameVersion;
|
||||
@@ -20,7 +31,13 @@ import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillTools;
|
||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||
import org.bukkit.*;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -32,12 +49,6 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public abstract class MMOTestEnvironment {
|
||||
protected MockedStatic<Bukkit> mockedBukkit;
|
||||
protected MockedStatic<mcMMO> mockedMcMMO;
|
||||
@@ -190,11 +201,16 @@ public abstract class MMOTestEnvironment {
|
||||
|
||||
private void mockPermissions() {
|
||||
mockedPermissions = mockStatic(Permissions.class);
|
||||
when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(true);
|
||||
when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(true);
|
||||
when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(true);
|
||||
when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(true);
|
||||
when(Permissions.lucky(player, PrimarySkillType.WOODCUTTING)).thenReturn(false); // player is not lucky
|
||||
when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(
|
||||
true);
|
||||
when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(
|
||||
true);
|
||||
when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(
|
||||
true);
|
||||
when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(
|
||||
true);
|
||||
when(Permissions.lucky(player, PrimarySkillType.WOODCUTTING)).thenReturn(
|
||||
false); // player is not lucky
|
||||
}
|
||||
|
||||
private void mockRankConfig() {
|
||||
@@ -209,7 +225,8 @@ public abstract class MMOTestEnvironment {
|
||||
private void mockGeneralConfig() {
|
||||
generalConfig = mock(GeneralConfig.class);
|
||||
when(generalConfig.getTreeFellerThreshold()).thenReturn(100);
|
||||
when(generalConfig.getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, Material.OAK_LOG)).thenReturn(true);
|
||||
when(generalConfig.getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING,
|
||||
Material.OAK_LOG)).thenReturn(true);
|
||||
when(generalConfig.getLocale()).thenReturn("en_US");
|
||||
when(mcMMO.p.getGeneralConfig()).thenReturn(generalConfig);
|
||||
}
|
||||
|
@@ -1,5 +1,14 @@
|
||||
package com.gmail.nossr50.database;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.gmail.nossr50.database.flatfile.LeaderboardStatus;
|
||||
import com.gmail.nossr50.datatypes.database.DatabaseType;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
@@ -8,15 +17,12 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.util.skills.SkillTools;
|
||||
import com.google.common.io.Files;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
@@ -26,9 +32,13 @@ import java.util.UUID;
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
class FlatFileDatabaseManagerTest {
|
||||
|
||||
@@ -94,14 +104,16 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
private static final String[] badUUIDDatabaseData = {
|
||||
"nossr50:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
||||
"z750:2420:::0:2452:0:1983:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:3:5:1600906906:", //This one has an incorrect UUID representation
|
||||
"z750:2420:::0:2452:0:1983:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:3:5:1600906906:",
|
||||
//This one has an incorrect UUID representation
|
||||
"powerless:0:::0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0::0:0:0:0:0:0:0:0:0::0:0:0:0:HEARTS:0:0:e0d07db8-f7e8-43c7-9ded-864dfc6f3b7c:5:1600906906:"
|
||||
};
|
||||
|
||||
private static final String[] outdatedDatabaseData = {
|
||||
"nossr50:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
||||
"mrfloris:2420:::0:2452:0:1983:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:631e3896-da2a-4077-974b-d047859d76bc:5:1600906906:",
|
||||
"electronicboy:0:::0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0::0:0:0:0:0:0:0:0:0::0:0:0:0:HEARTS:0:0:e0d07db8-f7e8-43c7-9ded-864dfc6f3b7c:" //This user is missing data added after UUID index
|
||||
"electronicboy:0:::0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0::0:0:0:0:0:0:0:0:0::0:0:0:0:HEARTS:0:0:e0d07db8-f7e8-43c7-9ded-864dfc6f3b7c:"
|
||||
//This user is missing data added after UUID index
|
||||
};
|
||||
|
||||
private static final String[] emptyLineDatabaseData = {
|
||||
@@ -149,14 +161,16 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
@Test
|
||||
void testUpdateLeaderboards() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
assertNotNull(flatFileDatabaseManager);
|
||||
assertEquals(LeaderboardStatus.UPDATED, flatFileDatabaseManager.updateLeaderboards());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSaveUser() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
//Make a Profile to save and check to see if it worked
|
||||
UUID uuid = UUID.fromString("588fe472-1c82-4c4e-9aa1-7eefccb277e3");
|
||||
String playerName = "nossr50";
|
||||
@@ -165,7 +179,8 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
//Save the zero version and see if it looks correct
|
||||
assertNotNull(flatFileDatabaseManager);
|
||||
assertTrue(flatFileDatabaseManager.getUsersFile().exists()); //Users file should have been created from the above com.gmail.nossr50.database.FlatFileDatabaseManager.checkFileHealthAndStructure
|
||||
assertTrue(flatFileDatabaseManager.getUsersFile()
|
||||
.exists()); //Users file should have been created from the above com.gmail.nossr50.database.FlatFileDatabaseManager.checkFileHealthAndStructure
|
||||
assertNotNull(flatFileDatabaseManager.getUsersFile());
|
||||
|
||||
//The flatFileDatabaseManager is empty at this point, add our user
|
||||
@@ -173,7 +188,8 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
//Check for the empty profile
|
||||
PlayerProfile retrievedFromData = flatFileDatabaseManager.loadPlayerProfile(uuid);
|
||||
assertTrue(retrievedFromData.isLoaded()); //PlayerProfile::isLoaded returns true if the data was created from the file, false if it wasn't found and a dummy profile was returned
|
||||
assertTrue(
|
||||
retrievedFromData.isLoaded()); //PlayerProfile::isLoaded returns true if the data was created from the file, false if it wasn't found and a dummy profile was returned
|
||||
assertEquals(uuid, retrievedFromData.getUniqueId());
|
||||
assertEquals(playerName, retrievedFromData.getPlayerName());
|
||||
|
||||
@@ -183,10 +199,12 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
String alteredName = "changedmyname";
|
||||
PlayerProfile changedNameProfile = new PlayerProfile(alteredName, uuid, 0);
|
||||
assertTrue(flatFileDatabaseManager.saveUser(changedNameProfile)); //True means we saved the user
|
||||
assertTrue(flatFileDatabaseManager.saveUser(
|
||||
changedNameProfile)); //True means we saved the user
|
||||
|
||||
retrievedFromData = flatFileDatabaseManager.loadPlayerProfile(uuid);
|
||||
assertTrue(retrievedFromData.isLoaded()); //PlayerProfile::isLoaded returns true if the data was created from the file, false if it wasn't found and a dummy profile was returned
|
||||
assertTrue(
|
||||
retrievedFromData.isLoaded()); //PlayerProfile::isLoaded returns true if the data was created from the file, false if it wasn't found and a dummy profile was returned
|
||||
assertEquals(uuid, retrievedFromData.getUniqueId());
|
||||
assertEquals(alteredName, retrievedFromData.getPlayerName());
|
||||
}
|
||||
@@ -194,7 +212,8 @@ class FlatFileDatabaseManagerTest {
|
||||
@Test
|
||||
void testAddedMissingLastLoginValues() {
|
||||
File dbFile = prepareDatabaseTestResource(DB_MISSING_LAST_LOGIN);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(dbFile, logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(dbFile,
|
||||
logger, PURGE_TIME, 0, true);
|
||||
List<FlatFileDataFlag> flagsFound = flatFileDatabaseManager.checkFileHealthAndStructure();
|
||||
assertNotNull(flagsFound);
|
||||
assertTrue(flagsFound.contains(FlatFileDataFlag.LAST_LOGIN_SCHEMA_UPGRADE));
|
||||
@@ -207,7 +226,8 @@ class FlatFileDatabaseManagerTest {
|
||||
@Test
|
||||
void testLoadByName() {
|
||||
File healthyDB = prepareDatabaseTestResource(DB_HEALTHY);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(healthyDB, logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(healthyDB,
|
||||
logger, PURGE_TIME, 0, true);
|
||||
List<FlatFileDataFlag> flagsFound = flatFileDatabaseManager.checkFileHealthAndStructure();
|
||||
assertNull(flagsFound); //No flags should be found
|
||||
|
||||
@@ -225,7 +245,9 @@ class FlatFileDatabaseManagerTest {
|
||||
String playerName = "nossr50";
|
||||
|
||||
int newUserTestStartingLvl = 1337;
|
||||
var flatFileDatabaseManager = new FlatFileDatabaseManager(new File(tempDir.getPath() + File.separator + TEST_FILE_NAME), logger, PURGE_TIME, newUserTestStartingLvl, true);
|
||||
var flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(tempDir.getPath() + File.separator + TEST_FILE_NAME), logger, PURGE_TIME,
|
||||
newUserTestStartingLvl, true);
|
||||
flatFileDatabaseManager.checkFileHealthAndStructure();
|
||||
|
||||
PlayerProfile playerProfile = flatFileDatabaseManager.newUser(playerName, uuid);
|
||||
@@ -260,7 +282,8 @@ class FlatFileDatabaseManagerTest {
|
||||
File file = prepareDatabaseTestResource(DB_HEALTHY); //Existing DB
|
||||
|
||||
int newUserTestStartingLvl = 1337;
|
||||
var flatFileDatabaseManager = new FlatFileDatabaseManager(file, logger, PURGE_TIME, newUserTestStartingLvl, true);
|
||||
var flatFileDatabaseManager = new FlatFileDatabaseManager(file, logger, PURGE_TIME,
|
||||
newUserTestStartingLvl, true);
|
||||
flatFileDatabaseManager.checkFileHealthAndStructure();
|
||||
|
||||
PlayerProfile playerProfile = flatFileDatabaseManager.newUser(playerName, uuid);
|
||||
@@ -292,15 +315,16 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
private void checkNewUserValues(@NotNull PlayerProfile playerProfile, int startingLevel) {
|
||||
//Checking a new user for being zero initialized
|
||||
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (SkillTools.isChildSkill(primarySkillType))
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (SkillTools.isChildSkill(primarySkillType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assertEquals(startingLevel, playerProfile.getSkillLevel(primarySkillType));
|
||||
assertEquals(0, playerProfile.getSkillXpLevelRaw(primarySkillType), 0);
|
||||
}
|
||||
|
||||
for(SuperAbilityType superAbilityType : SuperAbilityType.values()) {
|
||||
for (SuperAbilityType superAbilityType : SuperAbilityType.values()) {
|
||||
assertEquals(0, playerProfile.getAbilityDATS(superAbilityType));
|
||||
}
|
||||
|
||||
@@ -312,7 +336,8 @@ class FlatFileDatabaseManagerTest {
|
||||
@Test
|
||||
void testLoadByUUID() {
|
||||
File dbFile = prepareDatabaseTestResource(DB_HEALTHY);
|
||||
var flatFileDatabaseManager = new FlatFileDatabaseManager(dbFile, logger, PURGE_TIME, 0, true);
|
||||
var flatFileDatabaseManager = new FlatFileDatabaseManager(dbFile, logger, PURGE_TIME, 0,
|
||||
true);
|
||||
List<FlatFileDataFlag> flagsFound = flatFileDatabaseManager.checkFileHealthAndStructure();
|
||||
assertNull(flagsFound); //No flags should be found
|
||||
|
||||
@@ -326,14 +351,15 @@ class FlatFileDatabaseManagerTest {
|
||||
PlayerProfile profile1 = flatFileDatabaseManager.loadPlayerProfile(uuid);
|
||||
testHealthyDataProfileValues(playerName, uuid, profile1);
|
||||
|
||||
|
||||
assertFalse(flatFileDatabaseManager.loadPlayerProfile(new UUID(0, 1)).isLoaded()); //This profile should not exist and therefor will return unloaded
|
||||
assertFalse(flatFileDatabaseManager.loadPlayerProfile(new UUID(0, 1))
|
||||
.isLoaded()); //This profile should not exist and therefor will return unloaded
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoadByUUIDAndName() {
|
||||
File dbFile = prepareDatabaseTestResource(DB_HEALTHY);
|
||||
var flatFileDatabaseManager = new FlatFileDatabaseManager(dbFile, logger, PURGE_TIME, 0, true);
|
||||
var flatFileDatabaseManager = new FlatFileDatabaseManager(dbFile, logger, PURGE_TIME, 0,
|
||||
true);
|
||||
List<FlatFileDataFlag> flagsFound = flatFileDatabaseManager.checkFileHealthAndStructure();
|
||||
assertNull(flagsFound); //No flags should be found
|
||||
|
||||
@@ -346,7 +372,8 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
String updatedName = "updatedName";
|
||||
Player updatedNamePlayer = initMockPlayer(updatedName, uuid);
|
||||
PlayerProfile updatedNameProfile = flatFileDatabaseManager.loadPlayerProfile(updatedNamePlayer);
|
||||
PlayerProfile updatedNameProfile = flatFileDatabaseManager.loadPlayerProfile(
|
||||
updatedNamePlayer);
|
||||
testHealthyDataProfileValues(updatedName, uuid, updatedNameProfile);
|
||||
|
||||
Player shouldNotExist = initMockPlayer("doesntexist", new UUID(0, 1));
|
||||
@@ -387,8 +414,10 @@ class FlatFileDatabaseManagerTest {
|
||||
return copyOfFile;
|
||||
}
|
||||
|
||||
private void testHealthyDataProfileValues(@NotNull String playerName, @NotNull UUID uuid, @NotNull PlayerProfile profile) {
|
||||
assertTrue(profile.isLoaded()); //PlayerProfile::isLoaded returns true if the data was created from the file, false if it wasn't found and a dummy profile was returned
|
||||
private void testHealthyDataProfileValues(@NotNull String playerName, @NotNull UUID uuid,
|
||||
@NotNull PlayerProfile profile) {
|
||||
assertTrue(
|
||||
profile.isLoaded()); //PlayerProfile::isLoaded returns true if the data was created from the file, false if it wasn't found and a dummy profile was returned
|
||||
assertEquals(uuid, profile.getUniqueId());
|
||||
assertEquals(playerName, profile.getPlayerName());
|
||||
|
||||
@@ -396,25 +425,30 @@ class FlatFileDatabaseManagerTest {
|
||||
* Player is a match and data is loaded, check values
|
||||
*/
|
||||
|
||||
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (SkillTools.isChildSkill(primarySkillType))
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (SkillTools.isChildSkill(primarySkillType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int expectedLevelHealthyDBEntryOne = getExpectedLevelHealthyDBEntryOne(primarySkillType);
|
||||
int expectedLevelHealthyDBEntryOne = getExpectedLevelHealthyDBEntryOne(
|
||||
primarySkillType);
|
||||
int skillLevel = profile.getSkillLevel(primarySkillType);
|
||||
assertEquals(expectedLevelHealthyDBEntryOne, skillLevel);
|
||||
|
||||
float expectedExperienceHealthyDBEntryOne = getExpectedExperienceHealthyDBEntryOne(primarySkillType);
|
||||
float expectedExperienceHealthyDBEntryOne = getExpectedExperienceHealthyDBEntryOne(
|
||||
primarySkillType);
|
||||
float skillXpLevelRaw = profile.getSkillXpLevelRaw(primarySkillType);
|
||||
assertEquals(expectedExperienceHealthyDBEntryOne, skillXpLevelRaw, 0);
|
||||
}
|
||||
|
||||
//Check the other things
|
||||
for(SuperAbilityType superAbilityType : SuperAbilityType.values()) {
|
||||
assertEquals(getExpectedSuperAbilityDATS(superAbilityType), profile.getAbilityDATS(superAbilityType));
|
||||
for (SuperAbilityType superAbilityType : SuperAbilityType.values()) {
|
||||
assertEquals(getExpectedSuperAbilityDATS(superAbilityType),
|
||||
profile.getAbilityDATS(superAbilityType));
|
||||
}
|
||||
|
||||
assertEquals(expectedChimaeraWingCd, profile.getUniqueData(UniqueDataType.CHIMAERA_WING_DATS));
|
||||
assertEquals(expectedChimaeraWingCd,
|
||||
profile.getUniqueData(UniqueDataType.CHIMAERA_WING_DATS));
|
||||
assertEquals(expectedScoreboardTips, profile.getScoreboardTipsShown());
|
||||
assertEquals(expectedLastLogin, profile.getLastLogin());
|
||||
}
|
||||
@@ -433,13 +467,15 @@ class FlatFileDatabaseManagerTest {
|
||||
case TRIDENTS_SUPER_ABILITY -> expectedTridentSuperCd;
|
||||
case EXPLOSIVE_SHOT -> expectedExplosiveShotCd;
|
||||
case MACES_SUPER_ABILITY -> expectedMacesSuperCd;
|
||||
default -> throw new RuntimeException("Values not defined for super ability please add " +
|
||||
"values for " + superAbilityType.toString() + " to the test");
|
||||
default ->
|
||||
throw new RuntimeException("Values not defined for super ability please add " +
|
||||
"values for " + superAbilityType + " to the test");
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private float getExpectedExperienceHealthyDBEntryOne(@NotNull PrimarySkillType primarySkillType) {
|
||||
private float getExpectedExperienceHealthyDBEntryOne(
|
||||
@NotNull PrimarySkillType primarySkillType) {
|
||||
return switch (primarySkillType) {
|
||||
case ACROBATICS -> expectedExpAcrobatics;
|
||||
case ALCHEMY -> expectedExpAlchemy;
|
||||
@@ -458,8 +494,9 @@ class FlatFileDatabaseManagerTest {
|
||||
case UNARMED -> expectedExpUnarmed;
|
||||
case WOODCUTTING -> expectedExpWoodcutting;
|
||||
case MACES -> expectedExpMaces;
|
||||
default ->
|
||||
throw new RuntimeException("Values for skill not defined, please add values for " + primarySkillType.toString() + " to the test");
|
||||
default -> throw new RuntimeException(
|
||||
"Values for skill not defined, please add values for "
|
||||
+ primarySkillType + " to the test");
|
||||
};
|
||||
|
||||
}
|
||||
@@ -483,23 +520,28 @@ class FlatFileDatabaseManagerTest {
|
||||
case UNARMED -> expectedLvlUnarmed;
|
||||
case WOODCUTTING -> expectedLvlWoodcutting;
|
||||
case MACES -> expectedLvlMaces;
|
||||
default ->
|
||||
throw new RuntimeException("Values for skill not defined, please add values for " + primarySkillType.toString() + " to the test");
|
||||
default -> throw new RuntimeException(
|
||||
"Values for skill not defined, please add values for "
|
||||
+ primarySkillType + " to the test");
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOverwriteName() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, duplicateNameDatabaseData, FlatFileDataFlag.DUPLICATE_NAME);
|
||||
ArrayList<String[]> splitDataLines = getSplitDataFromFile(flatFileDatabaseManager.getUsersFile());
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, duplicateNameDatabaseData,
|
||||
FlatFileDataFlag.DUPLICATE_NAME);
|
||||
ArrayList<String[]> splitDataLines = getSplitDataFromFile(
|
||||
flatFileDatabaseManager.getUsersFile());
|
||||
assertNotEquals(splitDataLines.get(1)[0], splitDataLines.get(0)[0]); //Name comparison
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDataNotFound() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
//Save the zero version and see if it looks correct
|
||||
assertNotNull(flatFileDatabaseManager);
|
||||
assertTrue(flatFileDatabaseManager.getUsersFile().exists());
|
||||
@@ -507,12 +549,14 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
//Check for the "unloaded" profile
|
||||
PlayerProfile retrievedFromData = flatFileDatabaseManager.loadPlayerProfile("nossr50");
|
||||
assertFalse(retrievedFromData.isLoaded()); //PlayerProfile::isLoaded returns false if data doesn't exist for the user
|
||||
assertFalse(
|
||||
retrievedFromData.isLoaded()); //PlayerProfile::isLoaded returns false if data doesn't exist for the user
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPurgePowerlessUsers() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
replaceDataInFile(flatFileDatabaseManager, normalDatabaseData);
|
||||
int purgeCount = flatFileDatabaseManager.purgePowerlessUsers();
|
||||
assertEquals(purgeCount, 1); //1 User should have been purged
|
||||
@@ -520,7 +564,8 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
@Test
|
||||
void testCheckFileHealthAndStructure() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
replaceDataInFile(flatFileDatabaseManager, badDatabaseData);
|
||||
|
||||
List<FlatFileDataFlag> dataFlags = flatFileDatabaseManager.checkFileHealthAndStructure();
|
||||
@@ -530,49 +575,64 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
@Test
|
||||
void testFindFixableDuplicateNames() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, duplicateNameDatabaseData, FlatFileDataFlag.DUPLICATE_NAME);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, duplicateNameDatabaseData,
|
||||
FlatFileDataFlag.DUPLICATE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindDuplicateUUIDs() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, duplicateUUIDDatabaseData, FlatFileDataFlag.DUPLICATE_UUID);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, duplicateUUIDDatabaseData,
|
||||
FlatFileDataFlag.DUPLICATE_UUID);
|
||||
}
|
||||
|
||||
@Test()
|
||||
void findBadUUIDData() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, badUUIDDatabaseData, FlatFileDataFlag.BAD_UUID_DATA);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, badUUIDDatabaseData,
|
||||
FlatFileDataFlag.BAD_UUID_DATA);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindCorruptData() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, corruptDatabaseData, FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, corruptDatabaseData,
|
||||
FlatFileDataFlag.CORRUPTED_OR_UNRECOGNIZABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindEmptyNames() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, emptyNameDatabaseData, FlatFileDataFlag.MISSING_NAME);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, emptyNameDatabaseData,
|
||||
FlatFileDataFlag.MISSING_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindBadValues() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, badDatabaseData, FlatFileDataFlag.BAD_VALUES);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, badDatabaseData,
|
||||
FlatFileDataFlag.BAD_VALUES);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindOutdatedData() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, outdatedDatabaseData, FlatFileDataFlag.INCOMPLETE);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
overwriteDataAndCheckForFlag(flatFileDatabaseManager, outdatedDatabaseData,
|
||||
FlatFileDataFlag.INCOMPLETE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetDatabaseType() {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
assertNotNull(flatFileDatabaseManager);
|
||||
assertEquals(flatFileDatabaseManager.getDatabaseType(), DatabaseType.FLATFILE);
|
||||
}
|
||||
@@ -580,20 +640,25 @@ class FlatFileDatabaseManagerTest {
|
||||
@Test
|
||||
void testReadRank() {
|
||||
//This is an empty DB
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
String rankBoyName = "rankBoy";
|
||||
UUID rankBoyUUID = new UUID(1337, 1337);
|
||||
String rankGirlName = "rankGirl";
|
||||
UUID rankGirlUUID = new UUID(7331, 7331);
|
||||
|
||||
PlayerProfile rankGirlProfile = addPlayerProfileWithLevelsAndSave(rankGirlName, rankGirlUUID, 100); //Rank 1
|
||||
PlayerProfile rankBoyProfile = addPlayerProfileWithLevelsAndSave(rankBoyName, rankBoyUUID, 10); //Rank 2
|
||||
PlayerProfile rankGirlProfile = addPlayerProfileWithLevelsAndSave(rankGirlName,
|
||||
rankGirlUUID, 100); //Rank 1
|
||||
PlayerProfile rankBoyProfile = addPlayerProfileWithLevelsAndSave(rankBoyName, rankBoyUUID,
|
||||
10); //Rank 2
|
||||
|
||||
assertEquals(LeaderboardStatus.UPDATED, flatFileDatabaseManager.updateLeaderboards());
|
||||
Map<PrimarySkillType, Integer> rankGirlPositions = flatFileDatabaseManager.readRank(rankGirlName);
|
||||
Map<PrimarySkillType, Integer> rankBoyPositions = flatFileDatabaseManager.readRank(rankBoyName);
|
||||
Map<PrimarySkillType, Integer> rankGirlPositions = flatFileDatabaseManager.readRank(
|
||||
rankGirlName);
|
||||
Map<PrimarySkillType, Integer> rankBoyPositions = flatFileDatabaseManager.readRank(
|
||||
rankBoyName);
|
||||
|
||||
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (primarySkillType.isChildSkill()) {
|
||||
assertNull(rankBoyPositions.get(primarySkillType));
|
||||
assertNull(rankGirlPositions.get(primarySkillType));
|
||||
@@ -603,8 +668,10 @@ class FlatFileDatabaseManagerTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(1, flatFileDatabaseManager.readRank(rankGirlName).get(null)); //Girl should be position 1
|
||||
assertEquals(2, flatFileDatabaseManager.readRank(rankBoyName).get(null)); //Boy should be position 2
|
||||
assertEquals(1, flatFileDatabaseManager.readRank(rankGirlName)
|
||||
.get(null)); //Girl should be position 1
|
||||
assertEquals(2,
|
||||
flatFileDatabaseManager.readRank(rankBoyName).get(null)); //Boy should be position 2
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -639,12 +706,13 @@ class FlatFileDatabaseManagerTest {
|
||||
|
||||
//This makes sure our private method is working before the tests run afterwards
|
||||
ArrayList<String[]> dataFromFile = getSplitDataFromFile(copyOfFile);
|
||||
logger.info("File Path: "+copyOfFile.getAbsolutePath());
|
||||
logger.info("File Path: " + copyOfFile.getAbsolutePath());
|
||||
assertArrayEquals(BAD_FILE_LINE_ONE.split(":"), dataFromFile.get(0));
|
||||
assertEquals(dataFromFile.get(22)[0], "nossr51");
|
||||
assertArrayEquals(BAD_DATA_FILE_LINE_TWENTY_THREE.split(":"), dataFromFile.get(22));
|
||||
|
||||
FlatFileDatabaseManager db_a = new FlatFileDatabaseManager(copyOfFile, logger, PURGE_TIME, 0, true);
|
||||
FlatFileDatabaseManager db_a = new FlatFileDatabaseManager(copyOfFile, logger, PURGE_TIME,
|
||||
0, true);
|
||||
List<FlatFileDataFlag> flagsFound = db_a.checkFileHealthAndStructure();
|
||||
assertNotNull(flagsFound);
|
||||
assertTrue(flagsFound.contains(FlatFileDataFlag.BAD_VALUES));
|
||||
@@ -657,8 +725,9 @@ class FlatFileDatabaseManagerTest {
|
||||
String line;
|
||||
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
if (line.isEmpty())
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] splitData = line.split(":");
|
||||
splitDataList.add(splitData);
|
||||
@@ -671,8 +740,10 @@ class FlatFileDatabaseManagerTest {
|
||||
return splitDataList;
|
||||
}
|
||||
|
||||
private @NotNull PlayerProfile addPlayerProfileWithLevelsAndSave(String playerName, UUID uuid, int levels) {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
private @NotNull PlayerProfile addPlayerProfileWithLevelsAndSave(String playerName, UUID uuid,
|
||||
int levels) {
|
||||
FlatFileDatabaseManager flatFileDatabaseManager = new FlatFileDatabaseManager(
|
||||
new File(getTemporaryUserFilePath()), logger, PURGE_TIME, 0, true);
|
||||
assertFalse(flatFileDatabaseManager.loadPlayerProfile(uuid).isLoaded());
|
||||
|
||||
flatFileDatabaseManager.newUser(playerName, uuid);
|
||||
@@ -682,17 +753,19 @@ class FlatFileDatabaseManagerTest {
|
||||
assertEquals(playerName, leveledProfile.getPlayerName());
|
||||
assertEquals(uuid, leveledProfile.getUniqueId());
|
||||
|
||||
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (SkillTools.isChildSkill(primarySkillType))
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (SkillTools.isChildSkill(primarySkillType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
leveledProfile.modifySkill(primarySkillType, levels); //TODO: This method also resets XP, not cool
|
||||
leveledProfile.modifySkill(primarySkillType,
|
||||
levels); //TODO: This method also resets XP, not cool
|
||||
}
|
||||
|
||||
flatFileDatabaseManager.saveUser(leveledProfile);
|
||||
leveledProfile = flatFileDatabaseManager.loadPlayerProfile(uuid);
|
||||
|
||||
for(PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (SkillTools.isChildSkill(primarySkillType)) {
|
||||
continue;
|
||||
}
|
||||
@@ -703,7 +776,8 @@ class FlatFileDatabaseManagerTest {
|
||||
return leveledProfile;
|
||||
}
|
||||
|
||||
private void replaceDataInFile(@NotNull FlatFileDatabaseManager flatFileDatabaseManager, @NotNull String[] dataEntries) {
|
||||
private void replaceDataInFile(@NotNull FlatFileDatabaseManager flatFileDatabaseManager,
|
||||
@NotNull String[] dataEntries) {
|
||||
String filePath = flatFileDatabaseManager.getUsersFile().getAbsolutePath();
|
||||
BufferedReader in = null;
|
||||
FileWriter out = null;
|
||||
@@ -711,7 +785,7 @@ class FlatFileDatabaseManagerTest {
|
||||
try {
|
||||
StringBuilder writer = new StringBuilder();
|
||||
|
||||
for(String data : dataEntries) {
|
||||
for (String data : dataEntries) {
|
||||
writer.append(data).append("\r\n");
|
||||
}
|
||||
|
||||
@@ -726,15 +800,15 @@ class FlatFileDatabaseManagerTest {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
logger.info("Added the following lines to the FlatFileDatabase for the purposes of the test...");
|
||||
logger.info(
|
||||
"Added the following lines to the FlatFileDatabase for the purposes of the test...");
|
||||
// Open the file
|
||||
in = new BufferedReader(new FileReader(filePath));
|
||||
String line;
|
||||
@@ -747,15 +821,15 @@ class FlatFileDatabaseManagerTest {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void overwriteDataAndCheckForFlag(@NotNull FlatFileDatabaseManager targetDatabase, @NotNull String[] data, @NotNull FlatFileDataFlag flag) {
|
||||
private void overwriteDataAndCheckForFlag(@NotNull FlatFileDatabaseManager targetDatabase,
|
||||
@NotNull String[] data, @NotNull FlatFileDataFlag flag) {
|
||||
replaceDataInFile(targetDatabase, data);
|
||||
|
||||
List<FlatFileDataFlag> dataFlags = targetDatabase.checkFileHealthAndStructure();
|
||||
|
@@ -1,11 +1,10 @@
|
||||
package com.gmail.nossr50.database.flatfile;
|
||||
|
||||
import com.gmail.nossr50.database.FlatFileDatabaseManager;
|
||||
import java.util.HashSet;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
class FlatFileDataUtilTest {
|
||||
|
||||
@Test
|
||||
@@ -26,7 +25,8 @@ class FlatFileDataUtilTest {
|
||||
@Test
|
||||
void testTooManyDataEntriesSplitString() {
|
||||
Assertions.assertThrows(AssertionError.class, () -> {
|
||||
FlatFileDataContainer dataContainer = new CategorizedFlatFileData(0, new HashSet<>(), new String[FlatFileDatabaseManager.DATA_ENTRY_COUNT + 1]);
|
||||
FlatFileDataContainer dataContainer = new CategorizedFlatFileData(0, new HashSet<>(),
|
||||
new String[FlatFileDatabaseManager.DATA_ENTRY_COUNT + 1]);
|
||||
FlatFileDataUtil.getPreparedSaveDataLine(dataContainer);
|
||||
});
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package com.gmail.nossr50.locale;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -7,10 +10,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class LocaleLoaderTest {
|
||||
|
||||
@BeforeEach
|
||||
@@ -59,7 +58,8 @@ class LocaleLoaderTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"&#FF0000Te�FFst", "&#FF0000Te[[RED]]st", "[[BLUE]]Te[[RED]]st", "§9Te§cst"})
|
||||
@ValueSource(strings = {"&#FF0000Te�FFst", "&#FF0000Te[[RED]]st", "[[BLUE]]Te[[RED]]st",
|
||||
"§9Te§cst"})
|
||||
void addColorsShouldAddRedAndBlue(String testString) {
|
||||
// When
|
||||
final String result = LocaleLoader.addColors(testString);
|
||||
|
@@ -1,22 +1,21 @@
|
||||
package com.gmail.nossr50.party;
|
||||
|
||||
import com.gmail.nossr50.MMOTestEnvironment;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.MMOTestEnvironment;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
class PartyManagerTest extends MMOTestEnvironment {
|
||||
private static final Logger logger = getLogger(PartyManagerTest.class.getName());
|
||||
|
||||
@@ -43,7 +42,7 @@ class PartyManagerTest extends MMOTestEnvironment {
|
||||
String partyName = "TestParty";
|
||||
|
||||
Player player = mock(Player.class);
|
||||
McMMOPlayer mmoPlayer = mock(McMMOPlayer.class);
|
||||
final McMMOPlayer mmoPlayer = mock(McMMOPlayer.class);
|
||||
when(mmoPlayer.getPlayer()).thenReturn(player);
|
||||
when(player.getUniqueId()).thenReturn(new UUID(0, 0));
|
||||
|
||||
@@ -59,7 +58,7 @@ class PartyManagerTest extends MMOTestEnvironment {
|
||||
String partyPassword = "somePassword";
|
||||
|
||||
Player player = mock(Player.class);
|
||||
McMMOPlayer mmoPlayer = mock(McMMOPlayer.class);
|
||||
final McMMOPlayer mmoPlayer = mock(McMMOPlayer.class);
|
||||
when(mmoPlayer.getPlayer()).thenReturn(player);
|
||||
when(player.getUniqueId()).thenReturn(new UUID(0, 0));
|
||||
|
||||
@@ -74,7 +73,7 @@ class PartyManagerTest extends MMOTestEnvironment {
|
||||
String partyPassword = "somePassword";
|
||||
|
||||
Player player = mock(Player.class);
|
||||
McMMOPlayer mmoPlayer = mock(McMMOPlayer.class);
|
||||
final McMMOPlayer mmoPlayer = mock(McMMOPlayer.class);
|
||||
when(mmoPlayer.getPlayer()).thenReturn(player);
|
||||
when(player.getUniqueId()).thenReturn(new UUID(0, 0));
|
||||
|
||||
|
@@ -1,5 +1,14 @@
|
||||
package com.gmail.nossr50.skills.acrobatics;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.MMOTestEnvironment;
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
@@ -8,6 +17,7 @@ import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.acrobatics.Roll;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -16,14 +26,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class AcrobaticsTest extends MMOTestEnvironment {
|
||||
private static final Logger logger = getLogger(AcrobaticsTest.class.getName());
|
||||
|
||||
@@ -38,12 +40,17 @@ class AcrobaticsTest extends MMOTestEnvironment {
|
||||
when(advancedConfig.getMaxBonusLevel(SubSkillType.ACROBATICS_ROLL)).thenReturn(1000);
|
||||
when(advancedConfig.getRollDamageThreshold()).thenReturn(7D);
|
||||
|
||||
Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.ACROBATICS_ROLL, 1)).thenReturn(1); // needed?
|
||||
Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.ACROBATICS_DODGE, 1)).thenReturn(1000); // needed?
|
||||
Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.ACROBATICS_ROLL, 1))
|
||||
.thenReturn(1); // needed?
|
||||
Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.ACROBATICS_DODGE, 1))
|
||||
.thenReturn(1000); // needed?
|
||||
|
||||
when(RankUtils.getRankUnlockLevel(SubSkillType.ACROBATICS_ROLL, 1)).thenReturn(1); // needed?
|
||||
when(RankUtils.hasReachedRank(eq(1), any(Player.class), eq(SubSkillType.ACROBATICS_ROLL))).thenReturn(true);
|
||||
when(RankUtils.hasReachedRank(eq(1), any(Player.class), any(AbstractSubSkill.class))).thenReturn(true);
|
||||
when(RankUtils.getRankUnlockLevel(SubSkillType.ACROBATICS_ROLL, 1)).thenReturn(
|
||||
1); // needed?
|
||||
when(RankUtils.hasReachedRank(eq(1), any(Player.class),
|
||||
eq(SubSkillType.ACROBATICS_ROLL))).thenReturn(true);
|
||||
when(RankUtils.hasReachedRank(eq(1), any(Player.class),
|
||||
any(AbstractSubSkill.class))).thenReturn(true);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
@@ -1,11 +1,21 @@
|
||||
package com.gmail.nossr50.skills.excavation;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.MMOTestEnvironment;
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -16,28 +26,28 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class ExcavationTest extends MMOTestEnvironment {
|
||||
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(ExcavationTest.class.getName());
|
||||
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(
|
||||
ExcavationTest.class.getName());
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws InvalidSkillException {
|
||||
mockBaseEnvironment(logger);
|
||||
when(rankConfig.getSubSkillUnlockLevel(SubSkillType.EXCAVATION_ARCHAEOLOGY, 1)).thenReturn(1);
|
||||
when(rankConfig.getSubSkillUnlockLevel(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER, 1)).thenReturn(1);
|
||||
when(rankConfig.getSubSkillUnlockLevel(SubSkillType.EXCAVATION_ARCHAEOLOGY, 1)).thenReturn(
|
||||
1);
|
||||
when(rankConfig.getSubSkillUnlockLevel(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER,
|
||||
1)).thenReturn(1);
|
||||
|
||||
// wire advanced config
|
||||
|
||||
when(RankUtils.getRankUnlockLevel(SubSkillType.EXCAVATION_ARCHAEOLOGY, 1)).thenReturn(1); // needed?
|
||||
when(RankUtils.getRankUnlockLevel(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER, 1)).thenReturn(1); // needed?
|
||||
when(RankUtils.hasReachedRank(eq(1), any(Player.class), eq(SubSkillType.EXCAVATION_ARCHAEOLOGY))).thenReturn(true);
|
||||
when(RankUtils.hasReachedRank(eq(1), any(Player.class), eq(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER))).thenReturn(true);
|
||||
when(RankUtils.getRankUnlockLevel(SubSkillType.EXCAVATION_ARCHAEOLOGY, 1)).thenReturn(
|
||||
1); // needed?
|
||||
when(RankUtils.getRankUnlockLevel(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER,
|
||||
1)).thenReturn(1); // needed?
|
||||
when(RankUtils.hasReachedRank(eq(1), any(Player.class),
|
||||
eq(SubSkillType.EXCAVATION_ARCHAEOLOGY))).thenReturn(true);
|
||||
when(RankUtils.hasReachedRank(eq(1), any(Player.class),
|
||||
eq(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER))).thenReturn(true);
|
||||
|
||||
// setup player and player related mocks after everything else
|
||||
this.player = Mockito.mock(Player.class);
|
||||
@@ -85,18 +95,19 @@ class ExcavationTest extends MMOTestEnvironment {
|
||||
excavationManager.excavationBlockCheck(block);
|
||||
|
||||
// verify ExcavationManager.processExcavationBonusesOnBlock was called
|
||||
verify(excavationManager, never()).processExcavationBonusesOnBlock(any(ExcavationTreasure.class),
|
||||
verify(excavationManager, never()).processExcavationBonusesOnBlock(
|
||||
any(ExcavationTreasure.class),
|
||||
any(Location.class));
|
||||
}
|
||||
|
||||
private List<ExcavationTreasure> getGuaranteedTreasureDrops() {
|
||||
List<ExcavationTreasure> treasures = new ArrayList<>();;
|
||||
List<ExcavationTreasure> treasures = new ArrayList<>();
|
||||
treasures.add(new ExcavationTreasure(new ItemStack(Material.CAKE), 1, 100, 1));
|
||||
return treasures;
|
||||
}
|
||||
|
||||
private List<ExcavationTreasure> getImpossibleTreasureDrops() {
|
||||
List<ExcavationTreasure> treasures = new ArrayList<>();;
|
||||
List<ExcavationTreasure> treasures = new ArrayList<>();
|
||||
treasures.add(new ExcavationTreasure(new ItemStack(Material.CAKE), 1, 0, 1));
|
||||
return treasures;
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
package com.gmail.nossr50.skills.tridents;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
|
||||
import com.gmail.nossr50.MMOTestEnvironment;
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -10,15 +13,12 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
|
||||
class TridentsTest extends MMOTestEnvironment {
|
||||
private static final Logger logger = getLogger(TridentsTest.class.getName());
|
||||
|
||||
TridentsManager tridentsManager;
|
||||
ItemStack trident;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws InvalidSkillException {
|
||||
mockBaseEnvironment(logger);
|
||||
|
@@ -1,11 +1,17 @@
|
||||
package com.gmail.nossr50.skills.woodcutting;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
||||
import com.gmail.nossr50.MMOTestEnvironment;
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import java.util.Collections;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -15,13 +21,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
||||
class WoodcuttingTest extends MMOTestEnvironment {
|
||||
private static final Logger logger = getLogger(WoodcuttingTest.class.getName());
|
||||
|
||||
@@ -30,18 +29,27 @@ class WoodcuttingTest extends MMOTestEnvironment {
|
||||
@BeforeEach
|
||||
void setUp() throws InvalidSkillException {
|
||||
mockBaseEnvironment(logger);
|
||||
Mockito.when(rankConfig.getSubSkillUnlockLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER, 1)).thenReturn(1);
|
||||
Mockito.when(rankConfig.getSubSkillUnlockLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER, 1))
|
||||
.thenReturn(1);
|
||||
|
||||
// wire advanced config
|
||||
Mockito.when(advancedConfig.getMaximumProbability(SubSkillType.WOODCUTTING_HARVEST_LUMBER)).thenReturn(100D);
|
||||
Mockito.when(advancedConfig.getMaximumProbability(SubSkillType.WOODCUTTING_CLEAN_CUTS)).thenReturn(10D);
|
||||
Mockito.when(advancedConfig.getMaxBonusLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER)).thenReturn(1000);
|
||||
Mockito.when(advancedConfig.getMaxBonusLevel(SubSkillType.WOODCUTTING_CLEAN_CUTS)).thenReturn(10000);
|
||||
Mockito.when(advancedConfig.getMaximumProbability(SubSkillType.WOODCUTTING_HARVEST_LUMBER))
|
||||
.thenReturn(100D);
|
||||
Mockito.when(advancedConfig.getMaximumProbability(SubSkillType.WOODCUTTING_CLEAN_CUTS))
|
||||
.thenReturn(10D);
|
||||
Mockito.when(advancedConfig.getMaxBonusLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER))
|
||||
.thenReturn(1000);
|
||||
Mockito.when(advancedConfig.getMaxBonusLevel(SubSkillType.WOODCUTTING_CLEAN_CUTS))
|
||||
.thenReturn(10000);
|
||||
|
||||
Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER, 1)).thenReturn(1); // needed?
|
||||
Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.WOODCUTTING_CLEAN_CUTS, 1)).thenReturn(1000); // needed?
|
||||
Mockito.when(RankUtils.hasReachedRank(eq(1), any(Player.class), eq(SubSkillType.WOODCUTTING_HARVEST_LUMBER))).thenReturn(true);
|
||||
Mockito.when(RankUtils.hasReachedRank(eq(1), any(Player.class), eq(SubSkillType.WOODCUTTING_CLEAN_CUTS))).thenReturn(true);
|
||||
Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER, 1))
|
||||
.thenReturn(1); // needed?
|
||||
Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.WOODCUTTING_CLEAN_CUTS, 1))
|
||||
.thenReturn(1000); // needed?
|
||||
Mockito.when(RankUtils.hasReachedRank(eq(1), any(Player.class),
|
||||
eq(SubSkillType.WOODCUTTING_HARVEST_LUMBER))).thenReturn(true);
|
||||
Mockito.when(RankUtils.hasReachedRank(eq(1), any(Player.class),
|
||||
eq(SubSkillType.WOODCUTTING_CLEAN_CUTS))).thenReturn(true);
|
||||
|
||||
// wire inventory
|
||||
this.itemInMainHand = new ItemStack(Material.DIAMOND_AXE);
|
||||
@@ -70,7 +78,8 @@ class WoodcuttingTest extends MMOTestEnvironment {
|
||||
// verify bonus drops were spawned
|
||||
// TODO: using at least once since triple drops can also happen
|
||||
// TODO: Change the test env to disallow triple drop in the future
|
||||
Mockito.verify(woodcuttingManager, Mockito.atLeastOnce()).spawnHarvestLumberBonusDrops(block);
|
||||
Mockito.verify(woodcuttingManager, Mockito.atLeastOnce())
|
||||
.spawnHarvestLumberBonusDrops(block);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,10 +102,12 @@ class WoodcuttingTest extends MMOTestEnvironment {
|
||||
Block targetBlock = Mockito.mock(Block.class);
|
||||
Mockito.when(targetBlock.getType()).thenReturn(Material.OAK_LOG);
|
||||
// wire XP
|
||||
Mockito.when(ExperienceConfig.getInstance().getXp(PrimarySkillType.WOODCUTTING, Material.OAK_LOG)).thenReturn(5);
|
||||
Mockito.when(ExperienceConfig.getInstance()
|
||||
.getXp(PrimarySkillType.WOODCUTTING, Material.OAK_LOG)).thenReturn(5);
|
||||
|
||||
// Verify XP increased by 5 when processing XP
|
||||
woodcuttingManager.processWoodcuttingBlockXP(targetBlock);
|
||||
Mockito.verify(mmoPlayer, Mockito.times(1)).beginXpGain(eq(PrimarySkillType.WOODCUTTING), eq(5F), any(), any());
|
||||
Mockito.verify(mmoPlayer, Mockito.times(1))
|
||||
.beginXpGain(eq(PrimarySkillType.WOODCUTTING), eq(5F), any(), any());
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,13 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import static com.gmail.nossr50.util.PotionEffectUtil.getNauseaPotionEffectType;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.compat.CompatibilityManager;
|
||||
import com.gmail.nossr50.util.platform.MinecraftGameVersion;
|
||||
@@ -10,15 +18,10 @@ import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import static com.gmail.nossr50.util.PotionEffectUtil.getNauseaPotionEffectType;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class PotionEffectUtilTest {
|
||||
private MockedStatic<mcMMO> mockedStaticMcMMO;
|
||||
private static final java.util.logging.Logger logger = getLogger(PotionEffectUtilTest.class.getName());
|
||||
private static final java.util.logging.Logger logger = getLogger(
|
||||
PotionEffectUtilTest.class.getName());
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
@@ -1,5 +1,12 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import static com.gmail.nossr50.util.PotionUtil.convertLegacyNames;
|
||||
import static com.gmail.nossr50.util.PotionUtil.matchPotionType;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.compat.CompatibilityManager;
|
||||
import com.gmail.nossr50.util.platform.MinecraftGameVersion;
|
||||
@@ -9,11 +16,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import static com.gmail.nossr50.util.PotionUtil.convertLegacyNames;
|
||||
import static com.gmail.nossr50.util.PotionUtil.matchPotionType;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class PotionUtilTest {
|
||||
|
||||
MockedStatic<mcMMO> mockedStaticMcMMO;
|
||||
|
@@ -1,20 +1,10 @@
|
||||
package com.gmail.nossr50.util.blockmeta;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.google.common.io.Files;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.*;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.LEGACY_WORLD_HEIGHT_MAX;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.LEGACY_WORLD_HEIGHT_MIN;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.assertChunkStoreEquals;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.assertEqualIgnoreMinMax;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.serializeChunkStore;
|
||||
import static com.gmail.nossr50.util.blockmeta.UserBlockTrackerTest.recursiveDelete;
|
||||
import static org.bukkit.Bukkit.getWorld;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -22,6 +12,23 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.google.common.io.Files;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
class BitSetChunkStoreTest {
|
||||
private static File tempDir;
|
||||
|
||||
@@ -88,7 +95,8 @@ class BitSetChunkStoreTest {
|
||||
original.setTrue(14, 90, 12);
|
||||
original.setTrue(13, 89, 12);
|
||||
byte[] serializedBytes = serializeChunkStore(original);
|
||||
final ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
final ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(
|
||||
new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
assertChunkStoreEquals(original, deserialized);
|
||||
}
|
||||
|
||||
@@ -101,7 +109,8 @@ class BitSetChunkStoreTest {
|
||||
original.setTrue(14, -64, 12);
|
||||
original.setTrue(13, -63, 12);
|
||||
byte[] serializedBytes = serializeChunkStore(original);
|
||||
final ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
final ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(
|
||||
new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
assertChunkStoreEquals(original, deserialized);
|
||||
}
|
||||
|
||||
@@ -114,7 +123,8 @@ class BitSetChunkStoreTest {
|
||||
byte[] serializedBytes = serializeChunkStore(original);
|
||||
|
||||
when(mockWorld.getMinHeight()).thenReturn(-64);
|
||||
final ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
final ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(
|
||||
new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
assert deserialized != null;
|
||||
assertEqualIgnoreMinMax(original, deserialized);
|
||||
}
|
||||
|
@@ -1,12 +1,11 @@
|
||||
package com.gmail.nossr50.util.blockmeta;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BlockStoreTestUtils {
|
||||
public static final int LEGACY_WORLD_HEIGHT_MAX = 256;
|
||||
@@ -14,6 +13,7 @@ public class BlockStoreTestUtils {
|
||||
|
||||
/**
|
||||
* Asserts that the two ChunkStores are equal.
|
||||
*
|
||||
* @param expected The expected ChunkStore
|
||||
* @param actual The actual ChunkStore
|
||||
*/
|
||||
@@ -25,10 +25,13 @@ public class BlockStoreTestUtils {
|
||||
|
||||
static byte[] serializeChunkStore(@NotNull ChunkStore chunkStore) throws IOException {
|
||||
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
if (chunkStore instanceof BitSetChunkStore)
|
||||
BitSetChunkStore.Serialization.writeChunkStore(new DataOutputStream(byteArrayOutputStream), chunkStore);
|
||||
else
|
||||
new UnitTestObjectOutputStream(byteArrayOutputStream).writeObject(chunkStore); // Serializes the class as if
|
||||
if (chunkStore instanceof BitSetChunkStore) {
|
||||
BitSetChunkStore.Serialization.writeChunkStore(
|
||||
new DataOutputStream(byteArrayOutputStream), chunkStore);
|
||||
} else {
|
||||
new UnitTestObjectOutputStream(byteArrayOutputStream).writeObject(
|
||||
chunkStore); // Serializes the class as if
|
||||
}
|
||||
// it were the old
|
||||
// PrimitiveChunkStore
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
@@ -38,12 +41,17 @@ public class BlockStoreTestUtils {
|
||||
assertEquals(expected.getChunkX(), actual.getChunkX());
|
||||
assertEquals(expected.getChunkZ(), actual.getChunkZ());
|
||||
assertEquals(expected.getWorldId(), actual.getWorldId());
|
||||
for (int y = Math.min(actual.getChunkMin(), expected.getChunkMin()); y < Math.max(actual.getChunkMax(), expected.getChunkMax()); y++) {
|
||||
if (expected.getChunkMin() > y || actual.getChunkMin() > y || expected.getChunkMax() <= y || actual.getChunkMax() <= y)
|
||||
for (int y = Math.min(actual.getChunkMin(), expected.getChunkMin());
|
||||
y < Math.max(actual.getChunkMax(), expected.getChunkMax()); y++) {
|
||||
if (expected.getChunkMin() > y || actual.getChunkMin() > y
|
||||
|| expected.getChunkMax() <= y || actual.getChunkMax() <= y) {
|
||||
continue; // Ignore
|
||||
for (int x = 0; x < 16; x++)
|
||||
for (int z = 0; z < 16; z++)
|
||||
}
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
assertEquals(expected.isTrue(x, y, z), actual.isTrue(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +1,33 @@
|
||||
package com.gmail.nossr50.util.blockmeta;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.google.common.io.Files;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.*;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.LEGACY_WORLD_HEIGHT_MAX;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.LEGACY_WORLD_HEIGHT_MIN;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.assertChunkStoreEquals;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.serializeChunkStore;
|
||||
import static com.gmail.nossr50.util.blockmeta.UserBlockTrackerTest.recursiveDelete;
|
||||
import static org.bukkit.Bukkit.getWorld;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.google.common.io.Files;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
class ChunkStoreTest {
|
||||
private static File tempDir;
|
||||
|
||||
@@ -65,7 +76,8 @@ class ChunkStoreTest {
|
||||
original.setTrue(14, 90, 12);
|
||||
original.setTrue(13, 89, 12);
|
||||
byte[] serializedBytes = serializeChunkStore(original);
|
||||
ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(
|
||||
new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
assert deserialized != null;
|
||||
assertChunkStoreEquals(original, deserialized);
|
||||
}
|
||||
@@ -83,7 +95,8 @@ class ChunkStoreTest {
|
||||
}
|
||||
region.close();
|
||||
region = new McMMOSimpleRegionFile(file, 0, 0);
|
||||
try (DataInputStream is = region.getInputStream(original.getChunkX(), original.getChunkZ())) {
|
||||
try (DataInputStream is = region.getInputStream(original.getChunkX(),
|
||||
original.getChunkZ())) {
|
||||
Assertions.assertNotNull(is);
|
||||
ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(is);
|
||||
assert deserialized != null;
|
||||
|
@@ -1,13 +1,12 @@
|
||||
package com.gmail.nossr50.util.blockmeta;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Used for unit testing upgrades from the old ChunkStore class.
|
||||
@@ -71,24 +70,27 @@ class LegacyChunkStore implements ChunkStore, Serializable {
|
||||
|
||||
@Override
|
||||
public void setTrue(int x, int y, int z) {
|
||||
if (y >= store[0][0].length || y < 0)
|
||||
if (y >= store[0][0].length || y < 0) {
|
||||
return;
|
||||
}
|
||||
store[x][z][y] = true;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFalse(int x, int y, int z) {
|
||||
if (y >= store[0][0].length || y < 0)
|
||||
if (y >= store[0][0].length || y < 0) {
|
||||
return;
|
||||
}
|
||||
store[x][z][y] = false;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, boolean value) {
|
||||
if (y >= store[0][0].length || y < 0)
|
||||
if (y >= store[0][0].length || y < 0) {
|
||||
return;
|
||||
}
|
||||
store[x][z][y] = value;
|
||||
dirty = true;
|
||||
}
|
||||
@@ -120,7 +122,8 @@ class LegacyChunkStore implements ChunkStore, Serializable {
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
private void readObject(@NotNull ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
private void readObject(@NotNull ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package com.gmail.nossr50.util.blockmeta;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class UnitTestObjectOutputStream extends ObjectOutputStream {
|
||||
|
||||
@@ -15,8 +14,9 @@ class UnitTestObjectOutputStream extends ObjectOutputStream {
|
||||
@Override
|
||||
public void writeUTF(@NotNull String str) throws IOException {
|
||||
// Pretend to be the old class
|
||||
if (str.equals(LegacyChunkStore.class.getName()))
|
||||
if (str.equals(LegacyChunkStore.class.getName())) {
|
||||
str = "com.gmail.nossr50.util.blockmeta.chunkmeta.PrimitiveChunkStore";
|
||||
}
|
||||
super.writeUTF(str);
|
||||
}
|
||||
|
||||
|
@@ -1,20 +1,5 @@
|
||||
package com.gmail.nossr50.util.blockmeta;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.google.common.io.Files;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.LEGACY_WORLD_HEIGHT_MAX;
|
||||
import static com.gmail.nossr50.util.blockmeta.BlockStoreTestUtils.LEGACY_WORLD_HEIGHT_MIN;
|
||||
import static org.bukkit.Bukkit.getWorld;
|
||||
@@ -23,9 +8,28 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.google.common.io.Files;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
* Could be a lot better. But some tests are better than none! Tests the major things, still kinda unit-testy. Verifies
|
||||
* that the serialization isn't completely broken.
|
||||
* Could be a lot better. But some tests are better than none! Tests the major things, still kinda
|
||||
* unit-testy. Verifies that the serialization isn't completely broken.
|
||||
*/
|
||||
class UserBlockTrackerTest {
|
||||
private static File tempDir;
|
||||
@@ -61,7 +65,7 @@ class UserBlockTrackerTest {
|
||||
when(mockWorld.getMinHeight()).thenReturn(LEGACY_WORLD_HEIGHT_MIN);
|
||||
when(mockWorld.getMaxHeight()).thenReturn(LEGACY_WORLD_HEIGHT_MAX);
|
||||
}
|
||||
|
||||
|
||||
@AfterEach
|
||||
void teardownMock() {
|
||||
bukkitMock.close();
|
||||
@@ -76,11 +80,13 @@ class UserBlockTrackerTest {
|
||||
// Top Block
|
||||
int illegalMaxHeight = 256 + 1;
|
||||
final Block illegalHeightBlock = initMockBlock(1337, illegalMaxHeight, -1337);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(illegalHeightBlock));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> hashChunkManager.setIneligible(illegalHeightBlock));
|
||||
|
||||
int illegalMinHeight = -65;
|
||||
final Block otherIllegalHeightBlock = initMockBlock(1337, illegalMinHeight, -1337);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> hashChunkManager.setIneligible(otherIllegalHeightBlock));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> hashChunkManager.setIneligible(otherIllegalHeightBlock));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,23 +144,34 @@ class UserBlockTrackerTest {
|
||||
void testSimpleRegionRejectsOutOfBounds() {
|
||||
File file = new File(tempDir, "SimpleRegionRoundTrip.region");
|
||||
McMMOSimpleRegionFile region = new McMMOSimpleRegionFile(file, 0, 0);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> region.getOutputStream(-1, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> region.getOutputStream(0, -1));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> region.getOutputStream(32, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> region.getOutputStream(0, 32));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> region.getOutputStream(-1, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> region.getOutputStream(0, -1));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> region.getOutputStream(32, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> region.getOutputStream(0, 32));
|
||||
region.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChunkStoreRejectsOutOfBounds() {
|
||||
ChunkStore chunkStore = new BitSetChunkStore(mockWorld, 0, 0);
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(-1, 0, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, -1, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, 0, -1));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(16, 0, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, mockWorld.getMaxHeight()+1, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, mockWorld.getMinHeight()-1, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> chunkStore.setTrue(0, 0, 16));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> chunkStore.setTrue(-1, 0, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> chunkStore.setTrue(0, -1, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> chunkStore.setTrue(0, 0, -1));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> chunkStore.setTrue(16, 0, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> chunkStore.setTrue(0, mockWorld.getMaxHeight() + 1, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> chunkStore.setTrue(0, mockWorld.getMinHeight() - 1, 0));
|
||||
Assertions.assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> chunkStore.setTrue(0, 0, 16));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -1,6 +1,12 @@
|
||||
package com.gmail.nossr50.util.platform;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -10,11 +16,6 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MinecraftGameVersionTest {
|
||||
|
||||
@Test
|
||||
@@ -81,7 +82,8 @@ class MinecraftGameVersionTest {
|
||||
* we will just simulate some "Spigot" version here, so that the test can
|
||||
* continue successfully.
|
||||
*/
|
||||
String serverSoftwareVersion = "git-Spigot-12345-abcdef (MC: " + major + '.' + minor + '.' + patch + ')';
|
||||
String serverSoftwareVersion =
|
||||
"git-Spigot-12345-abcdef (MC: " + major + '.' + minor + '.' + patch + ')';
|
||||
|
||||
// Set up a mock plugin for logging.
|
||||
mcMMO plugin = Mockito.mock(mcMMO.class);
|
||||
@@ -111,19 +113,19 @@ class MinecraftGameVersionTest {
|
||||
* These samples were taken directly from the historical
|
||||
* data of CraftBukkit's pom.xml file:
|
||||
* https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/pom.xml
|
||||
*
|
||||
*
|
||||
* We should be safe to assume that forks follow these conventions and do not mess
|
||||
* with this version number (Spigot, Paper and Tuinity do at least).
|
||||
*/
|
||||
return Stream.of(
|
||||
Arguments.of("1.13.2-R0.1-SNAPSHOT", 1, 13, 2),
|
||||
Arguments.of("1.13-R0.2-SNAPSHOT", 1, 13, 0),
|
||||
Arguments.of("1.13.2-R0.1-SNAPSHOT", 1, 13, 2),
|
||||
Arguments.of("1.13-pre7-R0.1-SNAPSHOT", 1, 13, 0),
|
||||
Arguments.of("1.14-pre5-SNAPSHOT", 1, 14, 0),
|
||||
Arguments.of("1.15-R0.1-SNAPSHOT", 1, 15, 0),
|
||||
Arguments.of("1.16.5-R0.1-SNAPSHOT", 1, 16, 5),
|
||||
Arguments.of("1.17-R0.1-SNAPSHOT", 1, 17, 0)
|
||||
Arguments.of("1.13.2-R0.1-SNAPSHOT", 1, 13, 2),
|
||||
Arguments.of("1.13-R0.2-SNAPSHOT", 1, 13, 0),
|
||||
Arguments.of("1.13.2-R0.1-SNAPSHOT", 1, 13, 2),
|
||||
Arguments.of("1.13-pre7-R0.1-SNAPSHOT", 1, 13, 0),
|
||||
Arguments.of("1.14-pre5-SNAPSHOT", 1, 14, 0),
|
||||
Arguments.of("1.15-R0.1-SNAPSHOT", 1, 15, 0),
|
||||
Arguments.of("1.16.5-R0.1-SNAPSHOT", 1, 16, 5),
|
||||
Arguments.of("1.17-R0.1-SNAPSHOT", 1, 17, 0)
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -1,14 +1,15 @@
|
||||
package com.gmail.nossr50.util.random;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ProbabilityTest {
|
||||
|
||||
private static Stream<Arguments> provideProbabilitiesForWithinExpectations() {
|
||||
@@ -48,6 +49,7 @@ class ProbabilityTest {
|
||||
Arguments.of(Probability.ofPercent(1000), 100)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAlwaysWinConstructor() {
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
|
@@ -3,7 +3,8 @@ package com.gmail.nossr50.util.random;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ProbabilityTestUtils {
|
||||
public static void assertProbabilityExpectations(double expectedWinPercent, Probability probability) {
|
||||
public static void assertProbabilityExpectations(double expectedWinPercent,
|
||||
Probability probability) {
|
||||
double iterations = 2.0e7; //20 million
|
||||
double winCount = 0;
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
@@ -15,7 +16,8 @@ public class ProbabilityTestUtils {
|
||||
double successPercent = (winCount / iterations) * 100;
|
||||
System.out.println("Wins: " + winCount);
|
||||
System.out.println("Fails: " + (iterations - winCount));
|
||||
System.out.println("Percentage succeeded: " + successPercent + ", Expected: " + expectedWinPercent);
|
||||
System.out.println(
|
||||
"Percentage succeeded: " + successPercent + ", Expected: " + expectedWinPercent);
|
||||
assertEquals(expectedWinPercent, successPercent, 0.035D);
|
||||
System.out.println("Variance is within tolerance levels!");
|
||||
}
|
||||
|
@@ -1,7 +1,23 @@
|
||||
package com.gmail.nossr50.util.random;
|
||||
|
||||
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.ACROBATICS;
|
||||
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.MINING;
|
||||
import static com.gmail.nossr50.datatypes.skills.SubSkillType.ACROBATICS_DODGE;
|
||||
import static com.gmail.nossr50.datatypes.skills.SubSkillType.AXES_ARMOR_IMPACT;
|
||||
import static com.gmail.nossr50.datatypes.skills.SubSkillType.AXES_GREATER_IMPACT;
|
||||
import static com.gmail.nossr50.datatypes.skills.SubSkillType.MINING_DOUBLE_DROPS;
|
||||
import static com.gmail.nossr50.datatypes.skills.SubSkillType.TAMING_FAST_FOOD_SERVICE;
|
||||
import static com.gmail.nossr50.datatypes.skills.SubSkillType.UNARMED_ARROW_DEFLECT;
|
||||
import static com.gmail.nossr50.util.random.ProbabilityTestUtils.assertProbabilityExpectations;
|
||||
import static com.gmail.nossr50.util.random.ProbabilityUtil.calculateCurrentSkillProbability;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.gmail.nossr50.MMOTestEnvironment;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -9,18 +25,6 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.ACROBATICS;
|
||||
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.MINING;
|
||||
import static com.gmail.nossr50.datatypes.skills.SubSkillType.*;
|
||||
import static com.gmail.nossr50.util.random.ProbabilityTestUtils.assertProbabilityExpectations;
|
||||
import static com.gmail.nossr50.util.random.ProbabilityUtil.calculateCurrentSkillProbability;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
private static final Logger logger = getLogger(ProbabilityUtilTest.class.getName());
|
||||
|
||||
@@ -52,7 +56,8 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("staticChanceSkills")
|
||||
void staticChanceSkillsShouldSucceedAsExpected(SubSkillType subSkillType, double expectedWinPercent)
|
||||
void staticChanceSkillsShouldSucceedAsExpected(SubSkillType subSkillType,
|
||||
double expectedWinPercent)
|
||||
throws InvalidStaticChance {
|
||||
Probability staticRandomChance = ProbabilityUtil.getStaticRandomChance(subSkillType);
|
||||
assertProbabilityExpectations(expectedWinPercent, staticRandomChance);
|
||||
@@ -64,8 +69,8 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
when(advancedConfig.getMaximumProbability(UNARMED_ARROW_DEFLECT)).thenReturn(20D);
|
||||
when(advancedConfig.getMaxBonusLevel(UNARMED_ARROW_DEFLECT)).thenReturn(0);
|
||||
|
||||
@SuppressWarnings("all")
|
||||
final Probability probability = ProbabilityUtil.getSkillProbability(UNARMED_ARROW_DEFLECT, mmoPlayer);
|
||||
@SuppressWarnings("all") final Probability probability = ProbabilityUtil.getSkillProbability(
|
||||
UNARMED_ARROW_DEFLECT, mmoPlayer);
|
||||
assertEquals(0.2D, probability.getValue());
|
||||
assertProbabilityExpectations(20, probability);
|
||||
}
|
||||
@@ -91,10 +96,12 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideSkillProbabilityTestData")
|
||||
void testCalculateCurrentSkillProbability(double skillLevel, double floor, double ceiling, double maxBonusLevel,
|
||||
double expectedValue) {
|
||||
void testCalculateCurrentSkillProbability(double skillLevel, double floor, double ceiling,
|
||||
double maxBonusLevel,
|
||||
double expectedValue) {
|
||||
// When
|
||||
final Probability probability = calculateCurrentSkillProbability(skillLevel, floor, ceiling, maxBonusLevel);
|
||||
final Probability probability = calculateCurrentSkillProbability(skillLevel, floor, ceiling,
|
||||
maxBonusLevel);
|
||||
|
||||
// Then
|
||||
assertEquals(expectedValue, probability.getValue());
|
||||
@@ -108,7 +115,8 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
mmoPlayer.modifySkill(ACROBATICS, 500);
|
||||
|
||||
// When & Then
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, ACROBATICS_DODGE);
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
|
||||
ACROBATICS_DODGE);
|
||||
assertEquals("10.00%", rngDisplayValues[0]);
|
||||
}
|
||||
|
||||
@@ -120,7 +128,8 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
mmoPlayer.modifySkill(ACROBATICS, 1000);
|
||||
|
||||
// When & then
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, ACROBATICS_DODGE);
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
|
||||
ACROBATICS_DODGE);
|
||||
assertEquals("20.00%", rngDisplayValues[0]);
|
||||
}
|
||||
|
||||
@@ -132,7 +141,8 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
mmoPlayer.modifySkill(ACROBATICS, 0);
|
||||
|
||||
// When & then
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, ACROBATICS_DODGE);
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
|
||||
ACROBATICS_DODGE);
|
||||
assertEquals("0.00%", rngDisplayValues[0]);
|
||||
}
|
||||
|
||||
@@ -144,7 +154,8 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
mmoPlayer.modifySkill(MINING, 100);
|
||||
|
||||
// When & Then
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, MINING_DOUBLE_DROPS);
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
|
||||
MINING_DOUBLE_DROPS);
|
||||
assertEquals("10.00%", rngDisplayValues[0]);
|
||||
}
|
||||
|
||||
@@ -156,7 +167,8 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
mmoPlayer.modifySkill(MINING, 500);
|
||||
|
||||
// When & Then
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, MINING_DOUBLE_DROPS);
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
|
||||
MINING_DOUBLE_DROPS);
|
||||
assertEquals("50.00%", rngDisplayValues[0]);
|
||||
}
|
||||
|
||||
@@ -168,7 +180,8 @@ class ProbabilityUtilTest extends MMOTestEnvironment {
|
||||
mmoPlayer.modifySkill(MINING, 1000);
|
||||
|
||||
// When & Then
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, MINING_DOUBLE_DROPS);
|
||||
final String[] rngDisplayValues = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
|
||||
MINING_DOUBLE_DROPS);
|
||||
assertEquals("100.00%", rngDisplayValues[0]);
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,19 @@
|
||||
package com.gmail.nossr50.util.text;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class StringUtilsTest {
|
||||
|
||||
@BeforeEach
|
||||
@@ -17,20 +23,23 @@ class StringUtilsTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to clear all caches in StringUtils.
|
||||
* Reflection is used since the caches are private.
|
||||
* Utility method to clear all caches in StringUtils. Reflection is used since the caches are
|
||||
* private.
|
||||
*/
|
||||
private void clearCaches() {
|
||||
try {
|
||||
java.lang.reflect.Field entityCache = StringUtils.class.getDeclaredField("formattedEntityStrings");
|
||||
java.lang.reflect.Field entityCache = StringUtils.class.getDeclaredField(
|
||||
"formattedEntityStrings");
|
||||
entityCache.setAccessible(true);
|
||||
((java.util.Map<?, ?>) entityCache.get(null)).clear();
|
||||
|
||||
java.lang.reflect.Field superAbilityCache = StringUtils.class.getDeclaredField("formattedSuperAbilityStrings");
|
||||
java.lang.reflect.Field superAbilityCache = StringUtils.class.getDeclaredField(
|
||||
"formattedSuperAbilityStrings");
|
||||
superAbilityCache.setAccessible(true);
|
||||
((java.util.Map<?, ?>) superAbilityCache.get(null)).clear();
|
||||
|
||||
java.lang.reflect.Field materialCache = StringUtils.class.getDeclaredField("formattedMaterialStrings");
|
||||
java.lang.reflect.Field materialCache = StringUtils.class.getDeclaredField(
|
||||
"formattedMaterialStrings");
|
||||
materialCache.setAccessible(true);
|
||||
((java.util.Map<?, ?>) materialCache.get(null)).clear();
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
|
@@ -6,13 +6,12 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* This Unit Test checks if Adventure was set up correctly and works as expected.
|
||||
* Normally, we can rely on this to be the case. However sometimes our dependencies
|
||||
* lack so far behind that things stop working correctly.
|
||||
* This test ensures that basic functionality is guaranteed to work as we would expect.
|
||||
*
|
||||
* This Unit Test checks if Adventure was set up correctly and works as expected. Normally, we can
|
||||
* rely on this to be the case. However sometimes our dependencies lack so far behind that things
|
||||
* stop working correctly. This test ensures that basic functionality is guaranteed to work as we
|
||||
* would expect.
|
||||
* <p>
|
||||
* See https://github.com/mcMMO-Dev/mcMMO/pull/4446
|
||||
*
|
||||
*/
|
||||
class TextUtilsTest {
|
||||
|
||||
|
Reference in New Issue
Block a user