How to use ChestInventoryMock method of be.seeseemelk.mockbukkit.inventory.ChestInventoryMock class

Best MockBukkit code snippet using be.seeseemelk.mockbukkit.inventory.ChestInventoryMock.ChestInventoryMock

Source:TestAutoCrafter.java Github

copy

Full Screen

...10import org.junit.jupiter.api.BeforeAll;11import org.junit.jupiter.api.DisplayName;12import org.junit.jupiter.api.Test;13import be.seeseemelk.mockbukkit.MockBukkit;14import be.seeseemelk.mockbukkit.inventory.ChestInventoryMock;15import be.seeseemelk.mockbukkit.inventory.InventoryMock;16import io.github.thebusybiscuit.cscorelib2.item.CustomItem;17import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;18import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;19import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.AbstractAutoCrafter;20import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.AbstractRecipe;21import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.VanillaAutoCrafter;22import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;23import me.mrCookieSlime.Slimefun.Lists.RecipeType;24import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;25import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;26class TestAutoCrafter {27 private static SlimefunPlugin plugin;28 @BeforeAll29 public static void load() {30 MockBukkit.mock();31 plugin = MockBukkit.load(SlimefunPlugin.class);32 }33 @AfterAll34 public static void unload() {35 MockBukkit.unmock();36 }37 @Test38 @DisplayName("Test crafting a valid ShapelessRecipe")39 void testValidShapelessRecipe() {40 NamespacedKey key = new NamespacedKey(plugin, "shapeless_recipe_test");41 ItemStack result = new CustomItem(Material.DIAMOND, "&6Special Diamond :o");42 ShapelessRecipe recipe = new ShapelessRecipe(key, result);43 recipe.addIngredient(new MaterialChoice(Material.IRON_NUGGET, Material.GOLD_NUGGET));44 AbstractRecipe abstractRecipe = AbstractRecipe.of(recipe);45 AbstractAutoCrafter crafter = getVanillaAutoCrafter();46 InventoryMock inv = new ChestInventoryMock(null, 9);47 // Test first choice48 inv.addItem(new ItemStack(Material.IRON_NUGGET));49 Assertions.assertTrue(crafter.craft(inv, abstractRecipe));50 Assertions.assertFalse(inv.contains(Material.IRON_NUGGET, 1));51 Assertions.assertTrue(inv.containsAtLeast(result, 1));52 inv.clear();53 // Test other choice54 inv.addItem(new ItemStack(Material.GOLD_NUGGET));55 Assertions.assertTrue(crafter.craft(inv, abstractRecipe));56 Assertions.assertFalse(inv.contains(Material.GOLD_NUGGET, 1));57 Assertions.assertTrue(inv.containsAtLeast(result, 1));58 }59 @Test60 @DisplayName("Test crafting a valid ShapelessRecipe")61 void testDisabledRecipe() {62 NamespacedKey key = new NamespacedKey(plugin, "disabled_recipe_test");63 ItemStack result = new CustomItem(Material.DIAMOND, "&bAmazing Diamond :o");64 ShapelessRecipe recipe = new ShapelessRecipe(key, result);65 recipe.addIngredient(new MaterialChoice(Material.GOLD_NUGGET));66 AbstractRecipe abstractRecipe = AbstractRecipe.of(recipe);67 AbstractAutoCrafter crafter = getVanillaAutoCrafter();68 InventoryMock inv = new ChestInventoryMock(null, 9);69 // Test enabled Recipe70 abstractRecipe.setEnabled(true);71 inv.addItem(new ItemStack(Material.GOLD_NUGGET));72 Assertions.assertTrue(crafter.craft(inv, abstractRecipe));73 Assertions.assertFalse(inv.contains(Material.GOLD_NUGGET, 1));74 Assertions.assertTrue(inv.containsAtLeast(result, 1));75 inv.clear();76 // Test disabled Recipe77 abstractRecipe.setEnabled(false);78 inv.addItem(new ItemStack(Material.GOLD_NUGGET));79 Assertions.assertFalse(crafter.craft(inv, abstractRecipe));80 Assertions.assertTrue(inv.contains(Material.GOLD_NUGGET, 1));81 Assertions.assertFalse(inv.containsAtLeast(result, 1));82 }83 @Test84 @DisplayName("Test resource leftovers when crafting")85 void testResourceLeftovers() {86 NamespacedKey key = new NamespacedKey(plugin, "resource_leftovers_test");87 ItemStack result = new CustomItem(Material.DIAMOND, "&9Diamond. Nuff said.");88 ShapelessRecipe recipe = new ShapelessRecipe(key, result);89 recipe.addIngredient(new MaterialChoice(Material.HONEY_BOTTLE));90 recipe.addIngredient(new MaterialChoice(Material.HONEY_BOTTLE));91 AbstractRecipe abstractRecipe = AbstractRecipe.of(recipe);92 AbstractAutoCrafter crafter = getVanillaAutoCrafter();93 InventoryMock inv = new ChestInventoryMock(null, 9);94 inv.addItem(new ItemStack(Material.HONEY_BOTTLE, 2));95 Assertions.assertTrue(crafter.craft(inv, abstractRecipe));96 Assertions.assertFalse(inv.contains(Material.HONEY_BOTTLE, 2));97 Assertions.assertTrue(inv.containsAtLeast(result, 1));98 // Check for leftovers99 Assertions.assertTrue(inv.contains(Material.GLASS_BOTTLE, 2));100 }101 @Test102 @DisplayName("Test crafting an invalid ShapelessRecipe")103 void testInvalidShapelessRecipe() {104 NamespacedKey key = new NamespacedKey(plugin, "shapeless_recipe_test");105 ItemStack result = new CustomItem(Material.DIAMOND, "&6Special Diamond :o");106 ShapelessRecipe recipe = new ShapelessRecipe(key, result);107 recipe.addIngredient(Material.IRON_NUGGET);108 AbstractRecipe abstractRecipe = AbstractRecipe.of(recipe);109 AbstractAutoCrafter crafter = getVanillaAutoCrafter();110 InventoryMock inv = new ChestInventoryMock(null, 9);111 // Test non-compatible Item112 inv.addItem(new ItemStack(Material.BAMBOO));113 Assertions.assertFalse(crafter.craft(inv, abstractRecipe));114 Assertions.assertTrue(inv.contains(Material.BAMBOO, 1));115 Assertions.assertFalse(inv.containsAtLeast(result, 1));116 }117 @Test118 @DisplayName("Test crafting a ShapelessRecipe with a SlimefunItem")119 void ShapelessRecipeWithSlimefunItem() {120 NamespacedKey key = new NamespacedKey(plugin, "shapeless_recipe_test");121 ItemStack result = new CustomItem(Material.DIAMOND, "&6Special Diamond :o");122 ShapelessRecipe recipe = new ShapelessRecipe(key, result);123 recipe.addIngredient(Material.BAMBOO);124 AbstractRecipe abstractRecipe = AbstractRecipe.of(recipe);125 AbstractAutoCrafter crafter = getVanillaAutoCrafter();126 InventoryMock inv = new ChestInventoryMock(null, 9);127 SlimefunItemStack itemStack = new SlimefunItemStack("AUTO_CRAFTER_TEST_ITEM", Material.BAMBOO, "Panda Candy");128 SlimefunItem slimefunItem = TestUtilities.mockSlimefunItem(plugin, itemStack.getItemId(), itemStack);129 slimefunItem.register(plugin);130 inv.addItem(itemStack.clone());131 // Test unusable SlimefunItem132 slimefunItem.setUseableInWorkbench(false);133 Assertions.assertFalse(crafter.craft(inv, abstractRecipe));134 Assertions.assertTrue(inv.containsAtLeast(itemStack, 1));135 Assertions.assertFalse(inv.containsAtLeast(result, 1));136 // Test allowed SlimefunItem137 slimefunItem.setUseableInWorkbench(true);138 Assertions.assertTrue(crafter.craft(inv, abstractRecipe));139 Assertions.assertFalse(inv.containsAtLeast(itemStack, 1));140 Assertions.assertTrue(inv.containsAtLeast(result, 1));141 }142 @Test143 @DisplayName("Test crafting with a full Inventory")144 void testFullInventory() {145 NamespacedKey key = new NamespacedKey(plugin, "shapeless_recipe_test");146 ItemStack result = new CustomItem(Material.DIAMOND, "&6Special Diamond :o");147 ShapelessRecipe recipe = new ShapelessRecipe(key, result);148 recipe.addIngredient(Material.IRON_NUGGET);149 AbstractRecipe abstractRecipe = AbstractRecipe.of(recipe);150 AbstractAutoCrafter crafter = getVanillaAutoCrafter();151 InventoryMock inv = new ChestInventoryMock(null, 9);152 for (int i = 0; i < 9; i++) {153 inv.setItem(i, new ItemStack(Material.OAK_SAPLING));154 }155 // Test valid item but inventory is full.156 inv.addItem(new ItemStack(Material.IRON_NUGGET));157 Assertions.assertFalse(crafter.craft(inv, abstractRecipe));158 Assertions.assertTrue(inv.contains(Material.OAK_SAPLING, 9));159 Assertions.assertFalse(inv.containsAtLeast(result, 1));160 }161 @Test162 @DisplayName("Verify Auto Crafters are marked as energy consumers")163 void testEnergyConsumer() {164 AbstractAutoCrafter crafter = getVanillaAutoCrafter();165 Assertions.assertEquals(EnergyNetComponentType.CONSUMER, crafter.getEnergyComponentType());...

Full Screen

Full Screen

ChestInventoryMock

Using AI Code Generation

copy

Full Screen

1import be.seeseemelk.mockbukkit.inventory.ChestInventoryMock;2ChestInventoryMock inventoryMock = new ChestInventoryMock(null, 9);3inventoryMock.setItem(0, new ItemStack(Material.STONE));4inventoryMock.getItem(0);5inventoryMock.getSize();6inventoryMock.getTitle();7inventoryMock.getHolder();8inventoryMock.getMaxStackSize();9inventoryMock.getLocation();10inventoryMock.getType();11inventoryMock.contains(Material.STONE);12inventoryMock.contains(Material.STONE, 1);13inventoryMock.contains(Material.STONE, 1, (short) 0);14inventoryMock.containsAtLeast(new ItemStack(Material.STONE, 1), 1);15inventoryMock.containsAtLeast(new ItemStack(Material.STONE, 1), 1);16inventoryMock.firstEmpty();17inventoryMock.first(Material.STONE);18inventoryMock.first(Material.STONE, 1);19inventoryMock.first(Material.STONE, 1, (short) 0);20inventoryMock.first(new ItemStack(Material.STONE, 1));21inventoryMock.first(new ItemStack(Material.STONE, 1));22inventoryMock.firstEmpty();

Full Screen

Full Screen

ChestInventoryMock

Using AI Code Generation

copy

Full Screen

1ChestInventoryMock inv = new ChestInventoryMock(54, "Test Inventory");2inv.setTitle("Test Inventory");3inv.getTitle();4inv.getSize();5inv.getMaxStackSize();6inv.getMaxStackSize();7inv.getType();8inv.getLocation();9inv.getHolder();10inv.getViewers();11inv.getItem(0);12inv.setItem(0, new ItemStack(Material.AIR));13inv.firstEmpty();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run MockBukkit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in ChestInventoryMock

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful