diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 345803a49..d8476f963 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -145,7 +145,7 @@ Additionally, tests in the `refinedstorage2-network` module use the `refinedstor To test the entire chain from Minecraft to the API modules, we use integration tests. These tests are located in the test source set of the `refinedstorage2-platform-forge` module. -We write these integration tests as Minecraft gametests using the NeoForge testing framework. +We write these integration tests as Minecraft gametests. ### Test coverage diff --git a/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java b/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java index b5f52b618..2a1faeabf 100644 --- a/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java +++ b/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/ConstructorTest.java @@ -1,7 +1,9 @@ package com.refinedmods.refinedstorage2.platform.forge; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.constructordestructor.ConstructorBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; @@ -14,6 +16,8 @@ import net.minecraft.gametest.framework.GameTestSequence; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.gametest.GameTestHolder; import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; import org.apache.commons.lang3.function.TriConsumer; @@ -21,7 +25,9 @@ import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.DIRT; import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.RSBLOCKS; import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.STONE; -import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.insertItem; +import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.WATER; +import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.assertFluidPresent; +import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.insert; import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.networkIsAvailable; import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.requireBlockEntity; import static com.refinedmods.refinedstorage2.platform.forge.GameTestUtil.storageContainsExactly; @@ -40,6 +46,10 @@ private static void prepareConstructorPlot(final GameTestHelper helper, consumer) { helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault()); helper.setBlock(ZERO.above().above(), RSBLOCKS.getItemStorageBlock(ItemStorageType.Variant.ONE_K)); + helper.setBlock( + ZERO.above().above().north(), + RSBLOCKS.getFluidStorageBlock(FluidStorageType.Variant.SIXTY_FOUR_B) + ); final BlockPos constructorPos = ZERO.above().above().above(); helper.setBlock(constructorPos, RSBLOCKS.getConstructor().getDefault().rotated(direction)); consumer.accept( @@ -54,8 +64,8 @@ public static void shouldPlaceBlock(final GameTestHelper helper) { prepareConstructorPlot(helper, Direction.EAST, (constructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { - insertItem(helper, network, DIRT, 10); - insertItem(helper, network, STONE, 15); + insert(helper, network, DIRT, 10); + insert(helper, network, STONE, 15); })); // Act @@ -74,13 +84,40 @@ public static void shouldPlaceBlock(final GameTestHelper helper) { }); } + @GameTest(template = "empty_15x15") + public static void shouldPlaceWater(final GameTestHelper helper) { + prepareConstructorPlot(helper, Direction.EAST, (constructor, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, DIRT, 10); + insert(helper, network, STONE, 15); + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 2); + })); + + // Act + constructor.setFilters(List.of(WATER)); + + // Assert + sequence + .thenWaitUntil(() -> assertFluidPresent(helper, pos.east(), Fluids.WATER, FluidState.AMOUNT_FULL)) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(DIRT, 10), + new ResourceAmount(STONE, 15), + new ResourceAmount(WATER, Platform.INSTANCE.getBucketAmount()) + )) + .thenSucceed(); + }); + } + @GameTest(template = "empty_15x15") public static void shouldDropItem(final GameTestHelper helper) { prepareConstructorPlot(helper, Direction.EAST, (constructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { - insertItem(helper, network, DIRT, 10); - insertItem(helper, network, STONE, 15); + insert(helper, network, DIRT, 10); + insert(helper, network, STONE, 15); })); // Act diff --git a/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/GameTestUtil.java b/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/GameTestUtil.java index 7d2ab9fbb..5c95e0e20 100644 --- a/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/GameTestUtil.java +++ b/refinedstorage2-platform-forge/src/test/java/com/refinedmods/refinedstorage2/platform/forge/GameTestUtil.java @@ -5,9 +5,11 @@ import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.platform.api.support.network.AbstractNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.Arrays; @@ -20,10 +22,14 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; public final class GameTestUtil { public static final ItemResource DIRT = ItemResource.ofItemStack(new ItemStack(Items.DIRT)); public static final ItemResource STONE = ItemResource.ofItemStack(new ItemStack(Items.STONE)); + public static final FluidResource WATER = new FluidResource(Fluids.WATER, null); public static final Blocks RSBLOCKS = Blocks.INSTANCE; private GameTestUtil() { @@ -52,13 +58,13 @@ public static Runnable networkIsAvailable(final GameTestHelper helper, }; } - public static void insertItem(final GameTestHelper helper, - final Network network, - final ItemResource resource, - final long amount) { + public static void insert(final GameTestHelper helper, + final Network network, + final ResourceKey resource, + final long amount) { final StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); final long inserted = storage.insert(resource, amount, Action.EXECUTE, EmptyActor.INSTANCE); - helper.assertTrue(inserted == amount, "Item couldn't be inserted"); + helper.assertTrue(inserted == amount, "Resource couldn't be inserted"); } @SuppressWarnings("unchecked") @@ -79,6 +85,17 @@ public static T requireBlockEntity( return (T) blockEntity; } + public static void assertFluidPresent(final GameTestHelper helper, + final BlockPos pos, + final Fluid fluid, + final int level) { + final FluidState fluidState = helper.getLevel().getFluidState(helper.absolutePos(pos)); + helper.assertTrue( + fluidState.getType() == fluid && fluidState.getAmount() == level, + "Unexpected " + fluidState.getType() + ", " + fluidState.getAmount() + ); + } + public static Runnable storageContainsExactly(final GameTestHelper helper, final BlockPos networkPos, final ResourceAmount... expected) {