mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +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.Inventory;
|
||||
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.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -20,6 +22,9 @@ import xyz.alexcrea.cuanvil.util.CommonItemUtil;
|
|||
|
||||
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 {
|
||||
|
||||
private AnvilInventory anvil;
|
||||
|
|
@ -42,7 +47,7 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testConflict(){
|
||||
public void testConflict() {
|
||||
ItemStack sharpness1 = CommonItemUtil.sharpness(1);
|
||||
ItemStack arthropods1 = CommonItemUtil.bane_of_arthropods(1);
|
||||
ItemStack illegalResult = AnvilFuseTestUtil.prepareItem(
|
||||
|
|
@ -70,13 +75,7 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
|
|||
AnvilFuseTestUtil.executeAnvilTest(anvil, player, nullResultData);
|
||||
|
||||
// Try to find & remove conflict
|
||||
EnchantConflictGroup conflict = null;
|
||||
for (EnchantConflictGroup enchantConflictGroup : ConflictAPI.getRegisteredConflict()) {
|
||||
if("sword_enchant_conflict".equalsIgnoreCase(enchantConflictGroup.getName())){
|
||||
conflict = enchantConflictGroup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
EnchantConflictGroup conflict = findGroup("sword_enchant_conflict");
|
||||
Assertions.assertNotNull(conflict, "Could not find conflict.");
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@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
|
||||
void testAfterReload(){
|
||||
void writeGroup_Reload() {
|
||||
String groupName = "group";
|
||||
IncludeGroup group = new IncludeGroup(groupName);
|
||||
|
||||
|
|
@ -63,6 +63,16 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
|||
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) {
|
||||
return MaterialGroupApi.getGroup(groupName) != null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue