mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add Material group api unit test
This commit is contained in:
parent
94677b58ff
commit
d6155eff55
2 changed files with 80 additions and 2 deletions
|
|
@ -0,0 +1,79 @@
|
||||||
|
package xyz.alexcrea.cuanvil.api;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||||
|
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
||||||
|
import xyz.alexcrea.cuanvil.tests.ConfigResetCustomAnvilTest;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void groupAddAndRemove() {
|
||||||
|
String groupName = "group";
|
||||||
|
IncludeGroup group = new IncludeGroup(groupName);
|
||||||
|
|
||||||
|
// Group not being set should not exist
|
||||||
|
assertFalse(doGroupExist(groupName));
|
||||||
|
assertFalse(doGroupCanBeFound(groupName));
|
||||||
|
|
||||||
|
// Add group
|
||||||
|
assertTrue(MaterialGroupApi.addMaterialGroup(group));
|
||||||
|
assertFalse(MaterialGroupApi.addMaterialGroup(group, true));
|
||||||
|
|
||||||
|
assertTrue(doGroupExist(groupName));
|
||||||
|
assertTrue(doGroupCanBeFound(groupName));
|
||||||
|
|
||||||
|
// Remove group
|
||||||
|
assertTrue(MaterialGroupApi.removeGroup(group));
|
||||||
|
assertFalse(MaterialGroupApi.removeGroup(group));
|
||||||
|
|
||||||
|
assertFalse(doGroupExist(groupName));
|
||||||
|
assertFalse(doGroupCanBeFound(groupName));
|
||||||
|
|
||||||
|
// Re add
|
||||||
|
assertFalse(MaterialGroupApi.addMaterialGroup(group, false));
|
||||||
|
assertTrue(MaterialGroupApi.addMaterialGroup(group, true));
|
||||||
|
|
||||||
|
assertTrue(doGroupExist(groupName));
|
||||||
|
assertTrue(doGroupCanBeFound(groupName));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAfterReload(){
|
||||||
|
String groupName = "group";
|
||||||
|
IncludeGroup group = new IncludeGroup(groupName);
|
||||||
|
|
||||||
|
// Group not being set should not exist
|
||||||
|
assertFalse(doGroupExist(groupName));
|
||||||
|
assertFalse(doGroupCanBeFound(groupName));
|
||||||
|
|
||||||
|
// Add group and reload
|
||||||
|
assertTrue(MaterialGroupApi.writeMaterialGroup(group));
|
||||||
|
assertFalse(doGroupExist(groupName));
|
||||||
|
assertFalse(doGroupCanBeFound(groupName));
|
||||||
|
|
||||||
|
// Tick so write get reloaded
|
||||||
|
server.getScheduler().performOneTick();
|
||||||
|
|
||||||
|
assertTrue(doGroupExist(groupName));
|
||||||
|
assertTrue(doGroupCanBeFound(groupName));
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean doGroupExist(String groupName) {
|
||||||
|
return MaterialGroupApi.getGroup(groupName) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean doGroupCanBeFound(String groupName) {
|
||||||
|
ConflictBuilder builder = new ConflictBuilder(groupName);
|
||||||
|
builder.addExcludedGroup(groupName);
|
||||||
|
|
||||||
|
EnchantConflictGroup group = builder.build();
|
||||||
|
IncludeGroup materialGroup = (IncludeGroup) group.getCantConflictGroup();
|
||||||
|
return materialGroup.getGroups().size() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,6 @@ 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.bukkit.inventory.meta.Damageable;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.Repairable;
|
import org.bukkit.inventory.meta.Repairable;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
@ -19,7 +18,7 @@ import xyz.alexcrea.cuanvil.util.AnvilFuseTestUtil;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class UnitRepairApiTest extends ConfigResetCustomAnvilTest {
|
public class UnitRepairApiTests extends ConfigResetCustomAnvilTest {
|
||||||
|
|
||||||
private AnvilInventory anvil;
|
private AnvilInventory anvil;
|
||||||
private PlayerMock player;
|
private PlayerMock player;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue