Test empty group and reformat style

This commit is contained in:
alexcrea 2024-11-17 01:44:38 +01:00
parent 101047a25b
commit 9458362453
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
4 changed files with 110 additions and 66 deletions

View file

@ -19,7 +19,8 @@ import java.util.List;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class ConflictAPI { public class ConflictAPI {
private ConflictAPI() {} private ConflictAPI() {
}
private static Object saveChangeTask = null; private static Object saveChangeTask = null;
private static Object reloadChangeTask = null; private static Object reloadChangeTask = null;
@ -32,7 +33,7 @@ public class ConflictAPI {
* @param builder The conflict builder to be based on * @param builder The conflict builder to be based on
* @return True if successful. * @return True if successful.
*/ */
public static boolean addConflict(@NotNull ConflictBuilder builder){ public static boolean addConflict(@NotNull ConflictBuilder builder) {
return addConflict(builder, false); return addConflict(builder, false);
} }
@ -45,14 +46,14 @@ public class ConflictAPI {
* @param overrideDeleted If we should write even if the conflict was previously deleted. * @param overrideDeleted If we should write even if the conflict was previously deleted.
* @return True if successful. * @return True if successful.
*/ */
public static boolean addConflict(@NotNull ConflictBuilder builder, boolean overrideDeleted){ public static boolean addConflict(@NotNull ConflictBuilder builder, boolean overrideDeleted) {
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig(); FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
// Test if conflict can be added // Test if conflict can be added
if(!overrideDeleted && ConfigHolder.CONFLICT_HOLDER.isDeleted(builder.getName())) return false; if (!overrideDeleted && ConfigHolder.CONFLICT_HOLDER.isDeleted(builder.getName())) return false;
if(config.contains(builder.getName())) return false; if (config.contains(builder.getName())) return false;
if(!writeConflict(builder, false)) return false; if (!writeConflict(builder, false)) return false;
EnchantConflictGroup conflict = builder.build(); EnchantConflictGroup conflict = builder.build();
// Register conflict // Register conflict
@ -60,7 +61,7 @@ public class ConflictAPI {
// Add conflict to gui // Add conflict to gui
EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance(); EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance();
if(conflictGui != null) conflictGui.updateValueForGeneric(conflict, true); if (conflictGui != null) conflictGui.updateValueForGeneric(conflict, true);
return true; return true;
} }
@ -73,7 +74,7 @@ public class ConflictAPI {
* @param builder the builder * @param builder the builder
* @return true if was written successfully. * @return true if was written successfully.
*/ */
public static boolean writeConflict(@NotNull ConflictBuilder builder){ public static boolean writeConflict(@NotNull ConflictBuilder builder) {
return writeConflict(builder, true); return writeConflict(builder, true);
} }
@ -86,12 +87,12 @@ public class ConflictAPI {
* @param updatePlanned If we should plan a global update for conflicts * @param updatePlanned If we should plan a global update for conflicts
* @return true if was written successfully. * @return true if was written successfully.
*/ */
public static boolean writeConflict(@NotNull ConflictBuilder builder, boolean updatePlanned){ public static boolean writeConflict(@NotNull ConflictBuilder builder, boolean updatePlanned) {
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig(); FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
String name = builder.getName(); String name = builder.getName();
if(name.contains(".")) { if (name.contains(".")) {
CustomAnvil.instance.getLogger().warning("Conflict " + name +" contain \".\" in its name but should not. this conflict is ignored."); CustomAnvil.instance.getLogger().warning("Conflict " + name + " contain \".\" in its name but should not. this conflict is ignored.");
logConflictOrigin(builder); logConflictOrigin(builder);
return false; return false;
} }
@ -100,25 +101,27 @@ public class ConflictAPI {
List<String> enchantments = extractEnchantments(builder); List<String> enchantments = extractEnchantments(builder);
List<String> excludedGroups = new ArrayList<>(builder.getExcludedGroupNames()); List<String> excludedGroups = new ArrayList<>(builder.getExcludedGroupNames());
if(!enchantments.isEmpty()) config.set(basePath + "enchantments", enchantments); if (!enchantments.isEmpty()) config.set(basePath + "enchantments", enchantments);
if(!excludedGroups.isEmpty()) config.set(basePath + "notAffectedGroups", excludedGroups); if (!excludedGroups.isEmpty()) config.set(basePath + "notAffectedGroups", excludedGroups);
if(builder.getMaxBeforeConflict() > 0) config.set(basePath + "maxEnchantmentBeforeConflict", builder.getMaxBeforeConflict()); if (builder.getMaxBeforeConflict() > 0)
config.set(basePath + "maxEnchantmentBeforeConflict", builder.getMaxBeforeConflict());
if(!config.isConfigurationSection(name)) return false; if (!config.isConfigurationSection(name)) return false;
prepareSaveTask(); prepareSaveTask();
if(updatePlanned) prepareUpdateTask(); if (updatePlanned) prepareUpdateTask();
return true; return true;
} }
/** /**
* Extract every enchantment names from a builder. * Extract every enchantment names from a builder.
*
* @param builder The builder storing the enchantments * @param builder The builder storing the enchantments
* @return Builder's stored enchantment. * @return Builder's stored enchantment.
*/ */
@NotNull @NotNull
private static List<String> extractEnchantments(@NotNull ConflictBuilder builder){ private static List<String> extractEnchantments(@NotNull ConflictBuilder builder) {
List<String> result = new ArrayList<>(builder.getEnchantmentNames()); List<String> result = new ArrayList<>(builder.getEnchantmentNames());
for (NamespacedKey enchantmentKey : builder.getEnchantmentKeys()) { for (NamespacedKey enchantmentKey : builder.getEnchantmentKeys()) {
result.add(enchantmentKey.toString()); result.add(enchantmentKey.toString());
@ -133,7 +136,7 @@ public class ConflictAPI {
* @param conflict The conflict to remove * @param conflict The conflict to remove
* @return True if successful. * @return True if successful.
*/ */
public static boolean removeConflict(@NotNull EnchantConflictGroup conflict){ public static boolean removeConflict(@NotNull EnchantConflictGroup conflict) {
// Remove from registry // Remove from registry
ConfigHolder.CONFLICT_HOLDER.getConflictManager().removeConflict(conflict); ConfigHolder.CONFLICT_HOLDER.getConflictManager().removeConflict(conflict);
@ -143,7 +146,7 @@ public class ConflictAPI {
// Remove from gui // Remove from gui
EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance(); EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance();
if(conflictGui != null) conflictGui.removeGeneric(conflict); if (conflictGui != null) conflictGui.removeGeneric(conflict);
return true; return true;
@ -153,9 +156,9 @@ public class ConflictAPI {
* Prepare a task to save conflict configuration. * Prepare a task to save conflict configuration.
*/ */
private static void prepareSaveTask() { private static void prepareSaveTask() {
if(saveChangeTask != null) return; if (saveChangeTask != null) return;
saveChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, ()->{ saveChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, () -> {
ConfigHolder.CONFLICT_HOLDER.saveToDisk(true); ConfigHolder.CONFLICT_HOLDER.saveToDisk(true);
saveChangeTask = null; saveChangeTask = null;
}); });
@ -165,28 +168,29 @@ public class ConflictAPI {
* Prepare a task to reload every conflict. * Prepare a task to reload every conflict.
*/ */
private static void prepareUpdateTask() { private static void prepareUpdateTask() {
if(reloadChangeTask != null) return; if (reloadChangeTask != null) return;
reloadChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, ()->{ reloadChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, () -> {
ConfigHolder.CONFLICT_HOLDER.reload(); ConfigHolder.CONFLICT_HOLDER.reload();
EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance(); EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance();
if(conflictGui != null) conflictGui.reloadValues(); if (conflictGui != null) conflictGui.reloadValues();
reloadChangeTask = null; reloadChangeTask = null;
}); });
} }
static void logConflictOrigin(@NotNull ConflictBuilder builder){ static void logConflictOrigin(@NotNull ConflictBuilder builder) {
CustomAnvil.instance.getLogger().warning("Conflict " + builder.getName() + " came from " + builder.getSourceName() + "."); CustomAnvil.instance.getLogger().warning("Conflict " + builder.getName() + " came from " + builder.getSourceName() + ".");
} }
/** /**
* Get every registered conflict. * Get every registered conflict.
*
* @return An immutable collection of conflict. * @return An immutable collection of conflict.
*/ */
@NotNull @NotNull
public static List<EnchantConflictGroup> getRegisteredConflict(){ public static List<EnchantConflictGroup> getRegisteredConflict() {
List<EnchantConflictGroup> mutableList = ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList(); List<EnchantConflictGroup> mutableList = ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
return Collections.unmodifiableList(mutableList); return Collections.unmodifiableList(mutableList);
} }

View file

@ -22,7 +22,8 @@ import java.util.*;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class MaterialGroupApi { public class MaterialGroupApi {
private MaterialGroupApi(){} private MaterialGroupApi() {
}
private static Object saveChangeTask = null; private static Object saveChangeTask = null;
private static Object reloadChangeTask = null; private static Object reloadChangeTask = null;
@ -35,7 +36,7 @@ public class MaterialGroupApi {
* @param group The group to add * @param group The group to add
* @return true if successful. * @return true if successful.
*/ */
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){ public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group) {
return addMaterialGroup(group, false); return addMaterialGroup(group, false);
} }
@ -48,24 +49,24 @@ public class MaterialGroupApi {
* @param overrideDeleted If we should write even if the group was previously deleted. * @param overrideDeleted If we should write even if the group was previously deleted.
* @return true if successful. * @return true if successful.
*/ */
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group, boolean overrideDeleted){ public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group, boolean overrideDeleted) {
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
// Test if it exists/existed // Test if it exists/existed
if(!overrideDeleted && ConfigHolder.ITEM_GROUP_HOLDER.isDeleted(group.getName())) return false; if (!overrideDeleted && ConfigHolder.ITEM_GROUP_HOLDER.isDeleted(group.getName())) return false;
if(itemGroupManager.get(group.getName()) != null) return false; if (itemGroupManager.get(group.getName()) != null) return false;
// Add group // Add group
itemGroupManager.getGroupMap().put(group.getName(), group); itemGroupManager.getGroupMap().put(group.getName(), group);
if(!writeMaterialGroup(group, false)) return false; if (!writeMaterialGroup(group, false)) return false;
if(group instanceof IncludeGroup includeGroup){ if (group instanceof IncludeGroup includeGroup) {
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance(); GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
if(configGui != null) configGui.updateValueForGeneric(includeGroup, true); if (configGui != null) configGui.updateValueForGeneric(includeGroup, true);
} }
if(ConfigOptions.INSTANCE.getVerboseDebugLog()){ if (ConfigOptions.INSTANCE.getVerboseDebugLog()) {
CustomAnvil.instance.getLogger().info("Registered group " + group.getName()); CustomAnvil.instance.getLogger().info("Registered group " + group.getName());
} }
@ -80,7 +81,7 @@ public class MaterialGroupApi {
* @param group the group to write * @param group the group to write
* @return true if was written successfully. * @return true if was written successfully.
*/ */
public static boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group){ public static boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group) {
return writeMaterialGroup(group, true); return writeMaterialGroup(group, true);
} }
@ -93,43 +94,43 @@ public class MaterialGroupApi {
* @param updatePlanned if we should plan a global update for material groups * @param updatePlanned if we should plan a global update for material groups
* @return true if was written successfully. * @return true if was written successfully.
*/ */
public static boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group, boolean updatePlanned){ public static boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group, boolean updatePlanned) {
String name = group.getName(); String name = group.getName();
if(name.contains(".")) { if (name.contains(".")) {
CustomAnvil.instance.getLogger().warning("Group " + name +" contain . in its name but should not. this material group is ignored."); CustomAnvil.instance.getLogger().warning("Group " + name + " contain . in its name but should not. this material group is ignored.");
return false; return false;
} }
boolean changed; boolean changed;
if(group instanceof IncludeGroup includeGroup){ if (group instanceof IncludeGroup includeGroup) {
changed = writeKnownGroup("include", includeGroup); changed = writeKnownGroup("include", includeGroup);
}else if(group instanceof ExcludeGroup excludeGroup){ } else if (group instanceof ExcludeGroup excludeGroup) {
changed = writeKnownGroup("exclude", excludeGroup); changed = writeKnownGroup("exclude", excludeGroup);
}else{ } else {
changed = writeUnknownGroup(group); changed = writeUnknownGroup(group);
} }
if(!changed) return false; if (!changed) return false;
prepareSaveTask(); prepareSaveTask();
if(updatePlanned) prepareUpdateTask(); if (updatePlanned) prepareUpdateTask();
return true; return true;
} }
private static boolean writeKnownGroup(@NotNull String groupType, @NotNull AbstractMaterialGroup group){ private static boolean writeKnownGroup(@NotNull String groupType, @NotNull AbstractMaterialGroup group) {
FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig(); FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
String basePath = group.getName() + "."; String basePath = group.getName() + ".";
Set<Material> materialSet = group.getNonGroupInheritedMaterials(); Set<Material> materialSet = group.getNonGroupInheritedMaterials();
Set<AbstractMaterialGroup> groupSet = group.getGroups(); Set<AbstractMaterialGroup> groupSet = group.getGroups();
if(!materialSet.isEmpty()){ if (!materialSet.isEmpty()) {
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materialSet)); config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materialSet));
} }
if(!groupSet.isEmpty()){ if (!groupSet.isEmpty()) {
config.set(basePath + ItemGroupManager.GROUP_LIST_PATH, materialGroupSetToStringList(groupSet)); config.set(basePath + ItemGroupManager.GROUP_LIST_PATH, materialGroupSetToStringList(groupSet));
} }
if(!config.isConfigurationSection(group.getName())) return false; if (!config.isConfigurationSection(group.getName())) return false;
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, groupType); config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, groupType);
return true; return true;
@ -141,7 +142,7 @@ public class MaterialGroupApi {
String basePath = group.getName() + "."; String basePath = group.getName() + ".";
EnumSet<Material> materials = group.getMaterials(); EnumSet<Material> materials = group.getMaterials();
if(materials.isEmpty()) return false; if (materials.isEmpty()) return false;
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, "include"); config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, "include");
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materials)); config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materials));
@ -149,11 +150,11 @@ public class MaterialGroupApi {
return true; return true;
} }
public static List<String> materialSetToStringList(@NotNull Set<Material> materials){ public static List<String> materialSetToStringList(@NotNull Set<Material> materials) {
return materials.stream().map(material -> material.getKey().getKey().toLowerCase()).toList(); return materials.stream().map(material -> material.getKey().getKey().toLowerCase()).toList();
} }
public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractMaterialGroup> groups){ public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractMaterialGroup> groups) {
return groups.stream().map(AbstractMaterialGroup::getName).toList(); return groups.stream().map(AbstractMaterialGroup::getName).toList();
} }
@ -165,19 +166,19 @@ public class MaterialGroupApi {
* @param group The recipe to remove * @param group The recipe to remove
* @return True if the group was present. * @return True if the group was present.
*/ */
public static boolean removeGroup(@NotNull AbstractMaterialGroup group){ public static boolean removeGroup(@NotNull AbstractMaterialGroup group) {
// Remove from registry // Remove from registry
AbstractMaterialGroup removed = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName()); AbstractMaterialGroup removed = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName());
if(removed == null) return false; if (removed == null) return false;
// Delete and save to file // Delete and save to file
ConfigHolder.ITEM_GROUP_HOLDER.delete(group.getName()); ConfigHolder.ITEM_GROUP_HOLDER.delete(group.getName());
prepareSaveTask(); prepareSaveTask();
// Remove from gui // Remove from gui
if(group instanceof IncludeGroup includeGroup){ if (group instanceof IncludeGroup includeGroup) {
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance(); GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
if(configGui != null) configGui.removeGeneric(includeGroup); if (configGui != null) configGui.removeGeneric(includeGroup);
} }
return true; return true;
@ -187,9 +188,9 @@ public class MaterialGroupApi {
* Prepare a task to reload every conflict. * Prepare a task to reload every conflict.
*/ */
private static void prepareSaveTask() { private static void prepareSaveTask() {
if(saveChangeTask != null) return; if (saveChangeTask != null) return;
saveChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, ()->{ saveChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, () -> {
ConfigHolder.ITEM_GROUP_HOLDER.saveToDisk(true); ConfigHolder.ITEM_GROUP_HOLDER.saveToDisk(true);
saveChangeTask = null; saveChangeTask = null;
}); });
@ -199,13 +200,13 @@ public class MaterialGroupApi {
* Prepare a task to save configuration. * Prepare a task to save configuration.
*/ */
private static void prepareUpdateTask() { private static void prepareUpdateTask() {
if(reloadChangeTask != null) return; if (reloadChangeTask != null) return;
reloadChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, ()->{ reloadChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, () -> {
ConfigHolder.ITEM_GROUP_HOLDER.reload(); ConfigHolder.ITEM_GROUP_HOLDER.reload();
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance(); GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
if(configGui != null) configGui.reloadValues(); if (configGui != null) configGui.reloadValues();
reloadChangeTask = null; reloadChangeTask = null;
}); });
@ -219,16 +220,17 @@ public class MaterialGroupApi {
* @return the abstract group of this name. null if not found. * @return the abstract group of this name. null if not found.
*/ */
@Nullable @Nullable
public static AbstractMaterialGroup getGroup(@NotNull String groupName){ public static AbstractMaterialGroup getGroup(@NotNull String groupName) {
return ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().get(groupName); return ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().get(groupName);
} }
/** /**
* Get every registered material groups. * Get every registered material groups.
*
* @return An immutable map of group name as its key and group as mapped value. * @return An immutable map of group name as its key and group as mapped value.
*/ */
@NotNull @NotNull
public static Map<String, AbstractMaterialGroup> getRegisteredGroups(){ public static Map<String, AbstractMaterialGroup> getRegisteredGroups() {
return Collections.unmodifiableMap(ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap()); return Collections.unmodifiableMap(ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap());
} }

View file

@ -100,6 +100,7 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
void writeGroup_Reload() { void writeGroup_Reload() {
String conflictName = "conflict"; String conflictName = "conflict";
ConflictBuilder builder = new ConflictBuilder(conflictName); ConflictBuilder builder = new ConflictBuilder(conflictName);
builder.addEnchantment("bane_of_arthropods");
// Group not being set should not exist // Group not being set should not exist
assertFalse(doGroupExist(conflictName)); assertFalse(doGroupExist(conflictName));
@ -114,6 +115,24 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
assertTrue(doGroupExist(conflictName)); assertTrue(doGroupExist(conflictName));
} }
@Test
void writeGroup_Empty() {
String conflictName = "conflict";
ConflictBuilder builder = new ConflictBuilder(conflictName);
// Group not being set should not exist
assertFalse(doGroupExist(conflictName));
// Add group and reload
assertFalse(ConflictAPI.writeConflict(builder));
assertFalse(doGroupExist(conflictName));
// Tick so write get reloaded
server.getScheduler().performOneTick();
assertFalse(doGroupExist(conflictName));
}
@Test @Test
void writeGroup_InvalidDot() { void writeGroup_InvalidDot() {
String conflictName = "conflict.conflict"; String conflictName = "conflict.conflict";
@ -130,7 +149,7 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
// Maybe move to ConflictApi class ? // Maybe move to ConflictApi class ?
@Nullable @Nullable
private static EnchantConflictGroup findGroup(@NotNull String groupName){ private static EnchantConflictGroup findGroup(@NotNull String groupName) {
for (EnchantConflictGroup enchantConflictGroup : ConflictAPI.getRegisteredConflict()) { for (EnchantConflictGroup enchantConflictGroup : ConflictAPI.getRegisteredConflict()) {
if (groupName.equalsIgnoreCase(enchantConflictGroup.getName())) { if (groupName.equalsIgnoreCase(enchantConflictGroup.getName())) {
return enchantConflictGroup; return enchantConflictGroup;

View file

@ -1,5 +1,6 @@
package xyz.alexcrea.cuanvil.api; package xyz.alexcrea.cuanvil.api;
import org.bukkit.Material;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup; import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.group.IncludeGroup; import xyz.alexcrea.cuanvil.group.IncludeGroup;
@ -14,6 +15,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
void groupAddAndRemove() { void groupAddAndRemove() {
String groupName = "group"; String groupName = "group";
IncludeGroup group = new IncludeGroup(groupName); IncludeGroup group = new IncludeGroup(groupName);
group.addToPolicy(Material.DIAMOND_PICKAXE); // We do not want it to be empty
// Group not being set should not exist // Group not being set should not exist
assertFalse(doGroupExist(groupName)); assertFalse(doGroupExist(groupName));
@ -46,6 +48,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
void writeGroup_Reload() { void writeGroup_Reload() {
String groupName = "group"; String groupName = "group";
IncludeGroup group = new IncludeGroup(groupName); IncludeGroup group = new IncludeGroup(groupName);
group.addToPolicy(Material.DIAMOND_PICKAXE); // We do not want it to be empty
// Group not being set should not exist // Group not being set should not exist
assertFalse(doGroupExist(groupName)); assertFalse(doGroupExist(groupName));
@ -63,6 +66,22 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
assertTrue(doGroupCanBeFound(groupName)); assertTrue(doGroupCanBeFound(groupName));
} }
@Test
void writeGroup_Empty() {
String groupName = "group";
IncludeGroup group = new IncludeGroup(groupName);
// Add group and reload
assertFalse(MaterialGroupApi.writeMaterialGroup(group));
assertFalse(doGroupExist(groupName));
assertFalse(doGroupCanBeFound(groupName));
// Tick so write get reloaded
server.getScheduler().performOneTick();
assertFalse(doGroupExist(groupName));
assertFalse(doGroupCanBeFound(groupName));
}
@Test @Test
void writeGroup_InvalidDot() { void writeGroup_InvalidDot() {