mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add some dot in name and reload unit test
This commit is contained in:
parent
d6155eff55
commit
03438a0bf2
2 changed files with 61 additions and 9 deletions
|
|
@ -6,6 +6,8 @@ import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.AnvilInventory;
|
import org.bukkit.inventory.AnvilInventory;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -20,6 +22,9 @@ import xyz.alexcrea.cuanvil.util.CommonItemUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConflictApiTests extends ConfigResetCustomAnvilTest {
|
public class ConflictApiTests extends ConfigResetCustomAnvilTest {
|
||||||
|
|
||||||
private AnvilInventory anvil;
|
private AnvilInventory anvil;
|
||||||
|
|
@ -70,13 +75,7 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
|
||||||
AnvilFuseTestUtil.executeAnvilTest(anvil, player, nullResultData);
|
AnvilFuseTestUtil.executeAnvilTest(anvil, player, nullResultData);
|
||||||
|
|
||||||
// Try to find & remove conflict
|
// Try to find & remove conflict
|
||||||
EnchantConflictGroup conflict = null;
|
EnchantConflictGroup conflict = findGroup("sword_enchant_conflict");
|
||||||
for (EnchantConflictGroup enchantConflictGroup : ConflictAPI.getRegisteredConflict()) {
|
|
||||||
if("sword_enchant_conflict".equalsIgnoreCase(enchantConflictGroup.getName())){
|
|
||||||
conflict = enchantConflictGroup;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Assertions.assertNotNull(conflict, "Could not find conflict.");
|
Assertions.assertNotNull(conflict, "Could not find conflict.");
|
||||||
|
|
||||||
// Test what happen when we remove the conflict (illegal item should be allowed)
|
// Test what happen when we remove the conflict (illegal item should be allowed)
|
||||||
|
|
@ -97,4 +96,47 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
|
||||||
AnvilFuseTestUtil.executeAnvilTest(anvil, player, nullResultData);
|
AnvilFuseTestUtil.executeAnvilTest(anvil, player, nullResultData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void writeGroup_Reload() {
|
||||||
|
String conflictName = "conflict";
|
||||||
|
ConflictBuilder builder = new ConflictBuilder(conflictName);
|
||||||
|
|
||||||
|
// Group not being set should not exist
|
||||||
|
assertFalse(doGroupExist(conflictName));
|
||||||
|
|
||||||
|
// Add group and reload
|
||||||
|
assertTrue(ConflictAPI.writeConflict(builder));
|
||||||
|
assertFalse(doGroupExist(conflictName));
|
||||||
|
|
||||||
|
// Tick so write get reloaded
|
||||||
|
server.getScheduler().performOneTick();
|
||||||
|
|
||||||
|
assertTrue(doGroupExist(conflictName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void writeGroup_InvalidDot() {
|
||||||
|
String conflictName = "conflict.conflict";
|
||||||
|
ConflictBuilder builder = new ConflictBuilder(conflictName);
|
||||||
|
|
||||||
|
// Try write group
|
||||||
|
assertFalse(ConflictAPI.writeConflict(builder));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maybe move to ConflictApi class ?
|
||||||
|
private static boolean doGroupExist(@NotNull String groupName) {
|
||||||
|
return findGroup(groupName) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maybe move to ConflictApi class ?
|
||||||
|
@Nullable
|
||||||
|
private static EnchantConflictGroup findGroup(@NotNull String groupName){
|
||||||
|
for (EnchantConflictGroup enchantConflictGroup : ConflictAPI.getRegisteredConflict()) {
|
||||||
|
if (groupName.equalsIgnoreCase(enchantConflictGroup.getName())) {
|
||||||
|
return enchantConflictGroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAfterReload(){
|
void writeGroup_Reload() {
|
||||||
String groupName = "group";
|
String groupName = "group";
|
||||||
IncludeGroup group = new IncludeGroup(groupName);
|
IncludeGroup group = new IncludeGroup(groupName);
|
||||||
|
|
||||||
|
|
@ -63,6 +63,16 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
||||||
assertTrue(doGroupCanBeFound(groupName));
|
assertTrue(doGroupCanBeFound(groupName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void writeGroup_InvalidDot() {
|
||||||
|
String groupName = "group.group";
|
||||||
|
IncludeGroup group = new IncludeGroup(groupName);
|
||||||
|
|
||||||
|
// Try write group
|
||||||
|
assertFalse(MaterialGroupApi.writeMaterialGroup(group));
|
||||||
|
}
|
||||||
|
|
||||||
boolean doGroupExist(String groupName) {
|
boolean doGroupExist(String groupName) {
|
||||||
return MaterialGroupApi.getGroup(groupName) != null;
|
return MaterialGroupApi.getGroup(groupName) != null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue