|
| 1 | +package net.p3pp3rf1y.sophisticatedcore.upgrades.tank; |
| 2 | + |
| 3 | +import net.minecraft.SharedConstants; |
| 4 | +import net.minecraft.core.component.DataComponentMap; |
| 5 | +import net.minecraft.core.component.DataComponents; |
| 6 | +import net.minecraft.network.chat.contents.TranslatableContents; |
| 7 | +import net.minecraft.server.Bootstrap; |
| 8 | +import net.minecraft.world.item.Item; |
| 9 | +import net.minecraft.world.item.ItemStack; |
| 10 | +import net.minecraft.world.item.Items; |
| 11 | +import net.neoforged.neoforge.fluids.SimpleFluidContent; |
| 12 | +import net.p3pp3rf1y.sophisticatedcore.api.IStorageWrapper; |
| 13 | +import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeSlotChangeResult; |
| 14 | +import net.p3pp3rf1y.sophisticatedcore.init.ModCoreDataComponents; |
| 15 | +import org.junit.jupiter.api.BeforeAll; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | + |
| 18 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 19 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 21 | +import static org.mockito.ArgumentMatchers.any; |
| 22 | +import static org.mockito.Mockito.CALLS_REAL_METHODS; |
| 23 | +import static org.mockito.Mockito.doReturn; |
| 24 | +import static org.mockito.Mockito.mock; |
| 25 | +import static org.mockito.Mockito.when; |
| 26 | + |
| 27 | +class TankUpgradeItemTest { |
| 28 | + @BeforeAll |
| 29 | + static void setup() { |
| 30 | + SharedConstants.tryDetectVersion(); |
| 31 | + Bootstrap.bootStrap(); |
| 32 | + Bootstrap.validate(); |
| 33 | + bindTestComponents(Items.EXPERIENCE_BOTTLE, Items.POTION, Items.GLASS_BOTTLE); |
| 34 | + } |
| 35 | + |
| 36 | + private static void bindTestComponents(Item... items) { |
| 37 | + DataComponentMap components = DataComponentMap.builder().set(DataComponents.MAX_STACK_SIZE, 64).build(); |
| 38 | + for (Item item : items) { |
| 39 | + item.builtInRegistryHolder().bindComponents(components); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + void canSwapUpgradeForRejectsSameTankWithContentsAboveTargetCapacity() { |
| 45 | + TankUpgradeItem tankUpgrade = mock(TankUpgradeItem.class, CALLS_REAL_METHODS); |
| 46 | + ItemStack upgradeStack = mock(ItemStack.class); |
| 47 | + SimpleFluidContent contents = mock(SimpleFluidContent.class); |
| 48 | + when(upgradeStack.getItem()).thenReturn(tankUpgrade); |
| 49 | + when(contents.getAmount()).thenReturn(40_001); |
| 50 | + when(upgradeStack.getOrDefault(ModCoreDataComponents.FLUID_CONTENTS, SimpleFluidContent.EMPTY)).thenReturn(contents); |
| 51 | + doReturn(40_000).when(tankUpgrade).getTankCapacity(any()); |
| 52 | + |
| 53 | + UpgradeSlotChangeResult result = tankUpgrade.canSwapUpgradeFor(upgradeStack, 0, mock(IStorageWrapper.class), false); |
| 54 | + |
| 55 | + assertFalse(result.successful()); |
| 56 | + TranslatableContents errorContents = assertInstanceOf(TranslatableContents.class, result.errorMessage().getContents()); |
| 57 | + assertArrayEquals(new Object[]{"1.1"}, errorContents.getArgs()); |
| 58 | + } |
| 59 | +} |
0 commit comments