Skip to content

Commit

Permalink
Add some dot in name and reload unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrea committed Nov 16, 2024
1 parent d6155ef commit 03438a0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
58 changes: 50 additions & 8 deletions src/test/java/xyz/alexcrea/cuanvil/api/ConflictApiTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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;
Expand All @@ -20,6 +22,9 @@

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;
Expand All @@ -42,7 +47,7 @@ public void setUp() {
}

@Test
public void testConflict(){
public void testConflict() {
ItemStack sharpness1 = CommonItemUtil.sharpness(1);
ItemStack arthropods1 = CommonItemUtil.bane_of_arthropods(1);
ItemStack illegalResult = AnvilFuseTestUtil.prepareItem(
Expand Down Expand Up @@ -70,13 +75,7 @@ public void testConflict(){
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)
Expand All @@ -97,4 +96,47 @@ public void testConflict(){
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void groupAddAndRemove() {
}

@Test
void testAfterReload(){
void writeGroup_Reload() {
String groupName = "group";
IncludeGroup group = new IncludeGroup(groupName);

Expand All @@ -63,6 +63,16 @@ void testAfterReload(){
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;
}
Expand Down

0 comments on commit 03438a0

Please sign in to comment.