-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Controller gametest
- Loading branch information
Showing
3 changed files
with
112 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
72 changes: 72 additions & 0 deletions
72
...oforge/src/test/java/com/refinedmods/refinedstorage/common/controller/ControllerTest.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,72 @@ | ||
package com.refinedmods.refinedstorage.common.controller; | ||
|
||
import com.refinedmods.refinedstorage.api.core.Action; | ||
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage; | ||
import com.refinedmods.refinedstorage.common.Platform; | ||
import com.refinedmods.refinedstorage.common.util.IdentifierUtil; | ||
|
||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.neoforged.neoforge.gametest.GameTestHolder; | ||
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; | ||
|
||
import static com.refinedmods.refinedstorage.common.GameTestUtil.RSBLOCKS; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.energyStoredExactly; | ||
import static com.refinedmods.refinedstorage.common.GameTestUtil.networkIsAvailable; | ||
|
||
@GameTestHolder(IdentifierUtil.MOD_ID) | ||
@PrefixGameTestTemplate(false) | ||
public final class ControllerTest { | ||
private ControllerTest() { | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldConsumeEnergy(final GameTestHelper helper) { | ||
ControllerTestPlots.preparePlot(helper, false, (controller, pos, sequence) -> { | ||
// Arrange | ||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
})); | ||
|
||
// Act | ||
final EnergyStorage energyStorage = controller.getEnergyStorage(); | ||
energyStorage.receive(energyStorage.getCapacity(), Action.EXECUTE); | ||
|
||
// Assert | ||
sequence | ||
.thenIdle(20) | ||
.thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity())) | ||
.thenWaitUntil(() -> helper.setBlock(pos.above(), RSBLOCKS.getGrid().getDefault())) | ||
.thenIdle(1) | ||
.thenExecute(energyStoredExactly( | ||
energyStorage, | ||
energyStorage.getCapacity() - Platform.INSTANCE.getConfig().getGrid().getEnergyUsage() | ||
)) | ||
.thenIdle(9) | ||
.thenExecute(energyStoredExactly( | ||
energyStorage, | ||
energyStorage.getCapacity() - Platform.INSTANCE.getConfig().getGrid().getEnergyUsage() * 10 | ||
)) | ||
.thenSucceed(); | ||
}); | ||
} | ||
|
||
@GameTest(template = "empty_15x15") | ||
public static void shouldNotConsumeEnergy(final GameTestHelper helper) { | ||
ControllerTestPlots.preparePlot(helper, true, (controller, pos, sequence) -> { | ||
// Arrange | ||
final EnergyStorage energyStorage = controller.getEnergyStorage(); | ||
|
||
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { | ||
})); | ||
|
||
// Assert | ||
sequence | ||
.thenIdle(20) | ||
.thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity())) | ||
.thenWaitUntil(() -> helper.setBlock(pos.above(), RSBLOCKS.getGrid().getDefault())) | ||
.thenIdle(20) | ||
.thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity())) | ||
.thenSucceed(); | ||
}); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...e/src/test/java/com/refinedmods/refinedstorage/common/controller/ControllerTestPlots.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,29 @@ | ||
package com.refinedmods.refinedstorage.common.controller; | ||
|
||
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 ControllerTestPlots { | ||
private ControllerTestPlots() { | ||
} | ||
|
||
static void preparePlot(final GameTestHelper helper, | ||
final boolean isCreative, | ||
final TriConsumer<ControllerBlockEntity, BlockPos, GameTestSequence> consumer) { | ||
final BlockPos controllerPos = ZERO.above(); | ||
helper.setBlock(controllerPos, isCreative | ||
? RSBLOCKS.getCreativeController().getDefault() | ||
: RSBLOCKS.getController().getDefault()); | ||
consumer.accept( | ||
requireBlockEntity(helper, controllerPos, ControllerBlockEntity.class), | ||
controllerPos, | ||
helper.startSequence() | ||
); | ||
} | ||
} |