-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Interface gametest
- Loading branch information
Showing
3 changed files
with
326 additions
and
0 deletions.
There are no files selected for viewing
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
279 changes: 279 additions & 0 deletions
279
...age-neoforge/src/test/java/com/refinedmods/refinedstorage/common/iface/InterfaceTest.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,279 @@ | ||
package com.refinedmods.refinedstorage.common.iface; | ||
|
||
import com.refinedmods.refinedstorage.api.core.Action; | ||
import com.refinedmods.refinedstorage.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage.common.Platform; | ||
import com.refinedmods.refinedstorage.common.util.IdentifierUtil; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.neoforge.gametest.GameTestHolder; | ||
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; | ||
|
||
import static com.refinedmods.refinedstorage.common.GameTestUtil.asResource; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.assertInterfaceEmpty; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.getItemAsDamaged; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.insert; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.interfaceContainsExactly; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.networkIsAvailable; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.storageContainsExactly; | ||
import static com.refinedmods.refinedstorage.common.iface.InterfaceTestPlots.preparePlot; | ||
import static net.minecraft.world.item.Items.DIAMOND_CHESTPLATE; | ||
import static net.minecraft.world.item.Items.DIRT; | ||
import static net.minecraft.world.item.Items.STONE; | ||
import static net.minecraft.world.level.material.Fluids.WATER; | ||
|
||
@GameTestHolder(IdentifierUtil.MOD_ID) | ||
@PrefixGameTestTemplate(false) | ||
public final class InterfaceTest { | ||
private InterfaceTest() { | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldExportItem(final GameTestHelper helper) { | ||
preparePlot(helper, (iface, pos, sequence) -> { | ||
// Arrange | ||
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); | ||
|
||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
insert(helper, network, asResource(damagedDiamondChestplate), 1); | ||
})); | ||
|
||
// Act | ||
iface.setFuzzyMode(false); | ||
iface.setFilters(List.of( | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1) | ||
)); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(interfaceContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(STONE), 15), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1) | ||
)) | ||
.thenExecute(() -> { | ||
iface.clearFilters(); | ||
iface.setFilters(List.of( | ||
new ResourceAmount(asResource(DIRT), 5) | ||
)); | ||
}) | ||
.thenWaitUntil(interfaceContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 5) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 5), | ||
new ResourceAmount(asResource(STONE), 15), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1) | ||
)) | ||
.thenExecute(() -> iface.setFilters(List.of( | ||
new ResourceAmount(asResource(DIRT), 7) | ||
))) | ||
.thenWaitUntil(interfaceContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 7) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 3), | ||
new ResourceAmount(asResource(STONE), 15), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldExportItemFuzzy(final GameTestHelper helper) { | ||
preparePlot(helper, (iface, pos, sequence) -> { | ||
// Arrange | ||
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); | ||
|
||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 10); | ||
insert(helper, network, STONE, 15); | ||
insert(helper, network, asResource(damagedDiamondChestplate), 1); | ||
insert(helper, network, DIAMOND_CHESTPLATE, 1); | ||
})); | ||
|
||
// Act | ||
iface.setFuzzyMode(true); | ||
iface.setFilters(List.of( | ||
new ResourceAmount(asResource(DIRT), 5), | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1) | ||
)); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(interfaceContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 5), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1), | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 5), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenExecute(() -> { | ||
iface.clearFilters(); | ||
iface.setFilters(List.of( | ||
new ResourceAmount(asResource(DIRT), 10)) | ||
); | ||
}) | ||
.thenWaitUntil(interfaceContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(STONE), 15), | ||
new ResourceAmount(asResource(damagedDiamondChestplate), 1), | ||
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldExportFluid(final GameTestHelper helper) { | ||
preparePlot(helper, (iface, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 10); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Act | ||
iface.setFilters(List.of(new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 10))); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(interfaceContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 10) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenExecute(() -> iface.setFilters(List.of( | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5)) | ||
)) | ||
.thenWaitUntil(interfaceContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenExecute(() -> iface.setFilters(List.of( | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 7)) | ||
)) | ||
.thenWaitUntil(interfaceContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 7) | ||
)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 3), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldImportItem(final GameTestHelper helper) { | ||
preparePlot(helper, (iface, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, DIRT, 5); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(assertInterfaceEmpty(helper, pos)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 5), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenExecute(() -> iface.getExportedResources().insert(asResource(DIRT), 5, Action.EXECUTE)) | ||
.thenWaitUntil(assertInterfaceEmpty(helper, pos)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(DIRT), 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldImportFluid(final GameTestHelper helper) { | ||
preparePlot(helper, (iface, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 5); | ||
insert(helper, network, STONE, 15); | ||
})); | ||
|
||
// Assert | ||
sequence | ||
.thenWaitUntil(assertInterfaceEmpty(helper, pos)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenExecute(() -> iface.getExportedResources().insert( | ||
asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5, Action.EXECUTE | ||
)) | ||
.thenWaitUntil(assertInterfaceEmpty(helper, pos)) | ||
.thenWaitUntil(storageContainsExactly( | ||
helper, | ||
pos, | ||
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 10), | ||
new ResourceAmount(asResource(STONE), 15) | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...eoforge/src/test/java/com/refinedmods/refinedstorage/common/iface/InterfaceTestPlots.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,35 @@ | ||
package com.refinedmods.refinedstorage.common.iface; | ||
|
||
import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant; | ||
import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.minecraft.gametest.framework.GameTestSequence; | ||
import org.apache.commons.lang3.function.TriConsumer; | ||
|
||
import static com.refinedmods.refinedstorage.common.GameTestUtil.RSBLOCKS; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.requireBlockEntity; | ||
import static net.minecraft.core.BlockPos.ZERO; | ||
|
||
final class InterfaceTestPlots { | ||
private InterfaceTestPlots() { | ||
} | ||
|
||
static void preparePlot(final GameTestHelper helper, | ||
final TriConsumer<InterfaceBlockEntity, BlockPos, GameTestSequence> consumer) { | ||
helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault()); | ||
helper.setBlock(ZERO.above().above(), RSBLOCKS.getItemStorageBlock(ItemStorageVariant.ONE_K)); | ||
helper.setBlock( | ||
ZERO.above().above().north(), | ||
RSBLOCKS.getFluidStorageBlock(FluidStorageVariant.SIXTY_FOUR_B) | ||
); | ||
final BlockPos interfacePos = ZERO.above().above().above(); | ||
helper.setBlock(interfacePos, RSBLOCKS.getInterface()); | ||
consumer.accept( | ||
requireBlockEntity(helper, interfacePos, InterfaceBlockEntity.class), | ||
interfacePos, | ||
helper.startSequence() | ||
); | ||
} | ||
} |