-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enchantment item meta mock & Anvil fuse test
Also fixed durability being set for item that should be at -1
- Loading branch information
Showing
7 changed files
with
231 additions
and
9 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/test/java/io/delilaheve/util/EnchantmentUtilTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.delilaheve.util; | ||
|
||
import be.seeseemelk.mockbukkit.entity.PlayerMock; | ||
import be.seeseemelk.mockbukkit.inventory.ItemStackMock; | ||
import io.delilaheve.CustomAnvil; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.AnvilInventory; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.permissions.PermissionAttachment; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import xyz.alexcrea.cuanvil.config.ConfigHolder; | ||
import xyz.alexcrea.cuanvil.tests.DefaultCustomAnvilTest; | ||
import xyz.alexcrea.cuanvil.util.AnvilFuseTestData; | ||
import xyz.alexcrea.cuanvil.util.AnvilFuseTestUtil; | ||
|
||
import java.util.List; | ||
|
||
public class EnchantmentUtilTests extends DefaultCustomAnvilTest { | ||
|
||
private AnvilInventory anvil; | ||
private PlayerMock player; | ||
|
||
@Override | ||
@BeforeEach | ||
public void setUp() { | ||
super.setUp(); | ||
// Mock used player & open anvil | ||
player = server.addPlayer(); | ||
|
||
Inventory anvil = server.createInventory(player, InventoryType.ANVIL); | ||
|
||
this.anvil = (AnvilInventory) anvil; | ||
player.openInventory(anvil); | ||
|
||
ConfigHolder.DEFAULT_CONFIG.getConfig().set("debug_log", true); | ||
ConfigHolder.DEFAULT_CONFIG.getConfig().set("debug_log_verbose", true); | ||
} | ||
|
||
@Test | ||
public void testBypassFuse(){ | ||
// Test permission did not changed (if it do then server owner should be warned) | ||
String permission = CustomAnvil.bypassFusePermission; | ||
Assertions.assertEquals("ca.bypass.fuse", permission, "bypass fuse permission changed. " + | ||
"Caution with that as it will break some server CustomAnvil setup."); | ||
|
||
// Create item | ||
ItemStack normalStick = new ItemStackMock(Material.STICK); | ||
ItemStack sharpnessBook = AnvilFuseTestUtil.prepareItem( | ||
Material.ENCHANTED_BOOK, | ||
List.of("sharpness"), 1); | ||
|
||
ItemStack sharpnessStick = AnvilFuseTestUtil.prepareItem( | ||
Material.STICK, | ||
List.of("sharpness"), 1); | ||
|
||
ItemStack sharpnessResultStick = AnvilFuseTestUtil.prepareItem( | ||
Material.STICK, 1, | ||
List.of("sharpness"), 1); | ||
ItemStack sharpness2ResultStick = AnvilFuseTestUtil.prepareItem( | ||
Material.STICK, 1, | ||
List.of("sharpness"), 2); | ||
|
||
// Create anvil fuse data | ||
AnvilFuseTestData nullResultData = new AnvilFuseTestData( | ||
normalStick, sharpnessBook, | ||
null | ||
); | ||
AnvilFuseTestData nullResultData2 = new AnvilFuseTestData( | ||
sharpnessStick, sharpnessStick, | ||
null | ||
); | ||
|
||
AnvilFuseTestData legalResultData = new AnvilFuseTestData( | ||
normalStick, sharpnessBook, | ||
sharpnessResultStick | ||
// TODO add expected price | ||
); | ||
AnvilFuseTestData legalResultData2 = new AnvilFuseTestData( | ||
sharpnessStick, sharpnessStick, | ||
sharpness2ResultStick | ||
// TODO add expected price | ||
); | ||
|
||
// Test with no permission | ||
AnvilFuseTestUtil.executeAnvilTest(anvil, player, nullResultData); | ||
AnvilFuseTestUtil.executeAnvilTest(anvil, player, nullResultData2); | ||
|
||
// Add permission | ||
PermissionAttachment attachment = player.addAttachment(plugin); | ||
attachment.setPermission(permission, true); | ||
|
||
// Test with new permission | ||
AnvilFuseTestUtil.executeAnvilTest(anvil, player, legalResultData); | ||
AnvilFuseTestUtil.executeAnvilTest(anvil, player, legalResultData2); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/xyz/alexcrea/cuanvil/mock/EnchantedItemMetaMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package xyz.alexcrea.cuanvil.mock; | ||
|
||
import be.seeseemelk.mockbukkit.inventory.meta.ItemMetaMock; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.inventory.meta.EnchantmentStorageMeta; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Map; | ||
|
||
public class EnchantedItemMetaMock extends ItemMetaMock implements EnchantmentStorageMeta { | ||
|
||
|
||
public EnchantedItemMetaMock() { | ||
|
||
} | ||
|
||
public EnchantedItemMetaMock(@NotNull ItemMeta meta) { | ||
super(meta); | ||
} | ||
|
||
|
||
@Override | ||
public boolean hasStoredEnchants() { | ||
return super.hasEnchants(); | ||
} | ||
|
||
@Override | ||
public boolean hasStoredEnchant(@NotNull Enchantment ench) { | ||
return super.hasEnchant(ench); | ||
} | ||
|
||
@Override | ||
public int getStoredEnchantLevel(@NotNull Enchantment ench) { | ||
return super.getEnchantLevel(ench); | ||
} | ||
|
||
@Override | ||
public @NotNull Map<Enchantment, Integer> getStoredEnchants() { | ||
return super.getEnchants(); | ||
} | ||
|
||
@Override | ||
public boolean addStoredEnchant(@NotNull Enchantment ench, int level, boolean ignoreLevelRestriction) { | ||
return super.addEnchant(ench, level, ignoreLevelRestriction); | ||
} | ||
|
||
@Override | ||
public boolean removeStoredEnchant(@NotNull Enchantment ench) throws IllegalArgumentException { | ||
return super.removeEnchant(ench); | ||
} | ||
|
||
@Override | ||
public boolean hasConflictingStoredEnchant(@NotNull Enchantment ench) { | ||
return this.hasConflictingEnchant(ench); | ||
} | ||
|
||
|
||
@Override | ||
public EnchantedItemMetaMock clone() { | ||
// Not ideal but we do with what we have | ||
return new EnchantedItemMetaMock(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters