diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ac637d70..b670f9698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added - Autocrafter +- The Relay now has support for propagating autocrafting when not in pass-through mode. ### Changed diff --git a/build.gradle.kts b/build.gradle.kts index e7891180d..7ad772db3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,3 +21,12 @@ project.extensions.getByType().apply { ) } } + +allprojects { + apply(plugin = "publishing") + publishing { + repositories { + mavenLocal() + } + } +} diff --git a/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/AutocraftingPreviewProvider.java b/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/AutocraftingPreviewProvider.java index 207a0d2fd..29c7210b2 100644 --- a/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/AutocraftingPreviewProvider.java +++ b/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/AutocraftingPreviewProvider.java @@ -7,5 +7,5 @@ public interface AutocraftingPreviewProvider { Optional getPreview(ResourceKey resource, long amount); - boolean start(ResourceKey resource, long amount); + boolean startTask(ResourceKey resource, long amount); } diff --git a/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepository.java b/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepository.java index 01433fc7f..9d6d174fa 100644 --- a/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepository.java +++ b/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepository.java @@ -13,4 +13,6 @@ public interface PatternRepository { void remove(Pattern pattern); Set getOutputs(); + + Set getAll(); } diff --git a/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImpl.java b/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImpl.java index 27c2ec929..4f8139fc2 100644 --- a/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImpl.java +++ b/refinedstorage-autocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImpl.java @@ -2,11 +2,13 @@ import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import java.util.Collections; import java.util.HashSet; import java.util.Set; public class PatternRepositoryImpl implements PatternRepository { private final Set patterns = new HashSet<>(); + private final Set patternsView = Collections.unmodifiableSet(patterns); private final Set outputs = new HashSet<>(); @Override @@ -31,4 +33,9 @@ public void remove(final Pattern pattern) { public Set getOutputs() { return outputs; } + + @Override + public Set getAll() { + return patternsView; + } } diff --git a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImplTest.java b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImplTest.java index e357b796f..8567892e4 100644 --- a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImplTest.java +++ b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/PatternRepositoryImplTest.java @@ -17,35 +17,43 @@ void setUp() { void testDefaultState() { // Assert assertThat(sut.getOutputs()).isEmpty(); + assertThat(sut.getAll()).isEmpty(); } @Test void shouldAddPattern() { // Act - sut.add(new SimplePattern(FakeResources.A)); + sut.add(new SimplePattern(ResourceFixtures.A)); // Assert - assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(FakeResources.A); + assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(ResourceFixtures.A); + assertThat(sut.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new SimplePattern(ResourceFixtures.A) + ); } @Test void shouldAddMultiplePatterns() { // Act - sut.add(new SimplePattern(FakeResources.A)); - sut.add(new SimplePattern(FakeResources.B)); + sut.add(new SimplePattern(ResourceFixtures.A)); + sut.add(new SimplePattern(ResourceFixtures.B)); // Assert assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( - FakeResources.A, - FakeResources.B + ResourceFixtures.A, + ResourceFixtures.B + ); + assertThat(sut.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new SimplePattern(ResourceFixtures.A), + new SimplePattern(ResourceFixtures.B) ); } @Test void shouldRemovePattern() { // Arrange - final SimplePattern a = new SimplePattern(FakeResources.A); - final SimplePattern b = new SimplePattern(FakeResources.B); + final SimplePattern a = new SimplePattern(ResourceFixtures.A); + final SimplePattern b = new SimplePattern(ResourceFixtures.B); sut.add(a); sut.add(b); @@ -54,14 +62,17 @@ void shouldRemovePattern() { sut.remove(a); // Assert - assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(FakeResources.B); + assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(ResourceFixtures.B); + assertThat(sut.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new SimplePattern(ResourceFixtures.B) + ); } @Test void shouldRemoveMultiplePatterns() { // Arrange - final SimplePattern a = new SimplePattern(FakeResources.A); - final SimplePattern b = new SimplePattern(FakeResources.B); + final SimplePattern a = new SimplePattern(ResourceFixtures.A); + final SimplePattern b = new SimplePattern(ResourceFixtures.B); sut.add(a); sut.add(b); @@ -72,13 +83,14 @@ void shouldRemoveMultiplePatterns() { // Assert assertThat(sut.getOutputs()).isEmpty(); + assertThat(sut.getAll()).isEmpty(); } @Test void shouldRemovePatternButNotRemoveOutputIfAnotherPatternStillHasThatOutput() { // Arrange - final SimplePattern a = new SimplePattern(FakeResources.A); - final SimplePattern b = new SimplePattern(FakeResources.B, FakeResources.A); + final SimplePattern a = new SimplePattern(ResourceFixtures.A); + final SimplePattern b = new SimplePattern(ResourceFixtures.B, ResourceFixtures.A); sut.add(a); sut.add(b); @@ -88,8 +100,11 @@ void shouldRemovePatternButNotRemoveOutputIfAnotherPatternStillHasThatOutput() { // Assert assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( - FakeResources.A, - FakeResources.B + ResourceFixtures.A, + ResourceFixtures.B + ); + assertThat(sut.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new SimplePattern(ResourceFixtures.B, ResourceFixtures.A) ); } } diff --git a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/FakeResources.java b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/ResourceFixtures.java similarity index 73% rename from refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/FakeResources.java rename to refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/ResourceFixtures.java index e7a9b3a4c..6ecf50222 100644 --- a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/FakeResources.java +++ b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/ResourceFixtures.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage.api.resource.ResourceKey; -public enum FakeResources implements ResourceKey { +enum ResourceFixtures implements ResourceKey { A, B, C diff --git a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/SimplePattern.java b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/SimplePattern.java index 3d43c06b4..c77a80e77 100644 --- a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/SimplePattern.java +++ b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/SimplePattern.java @@ -4,10 +4,10 @@ import java.util.Set; -public class SimplePattern implements Pattern { +class SimplePattern implements Pattern { private final Set outputs; - public SimplePattern(final ResourceKey... outputs) { + SimplePattern(final ResourceKey... outputs) { this.outputs = Set.of(outputs); } diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java index 73afb28de..95b3116cc 100644 --- a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApi.java @@ -206,5 +206,5 @@ EnergyStorage asBlockItemEnergyStorage( Optional getPattern(ItemStack stack, Level level); - void openCraftingPreview(List requests); + void openAutocraftingPreview(List requests, @Nullable Object parentScreen); } diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java index 267910bd2..cd6065445 100644 --- a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/RefinedStorageApiProxy.java @@ -404,8 +404,8 @@ public Optional getPattern(final ItemStack stack, final Level level) { } @Override - public void openCraftingPreview(final List requests) { - ensureLoaded().openCraftingPreview(requests); + public void openAutocraftingPreview(final List requests, @Nullable final Object parentScreen) { + ensureLoaded().openAutocraftingPreview(requests, parentScreen); } private RefinedStorageApi ensureLoaded() { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java index aeedd165b..c67803c40 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java @@ -1,6 +1,5 @@ package com.refinedmods.refinedstorage.common; -import com.refinedmods.refinedstorage.api.autocrafting.PatternRepositoryImpl; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.autocrafting.AutocraftingNetworkComponentImpl; @@ -271,7 +270,7 @@ private void registerNetworkComponents() { ); RefinedStorageApi.INSTANCE.getNetworkComponentMapFactory().addFactory( AutocraftingNetworkComponent.class, - network -> new AutocraftingNetworkComponentImpl(new PatternRepositoryImpl()) + network -> new AutocraftingNetworkComponentImpl() ); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/Config.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/Config.java index 4954b9077..3daa6a815 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/Config.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/Config.java @@ -73,7 +73,7 @@ public interface Config { RelayEntry getRelay(); - SimpleEnergyUsageEntry getAutocrafter(); + AutocrafterEntry getAutocrafter(); interface SimpleEnergyUsageEntry { long getEnergyUsage(); @@ -208,4 +208,8 @@ interface RelayEntry { long getOutputNetworkEnergyUsage(); } + + interface AutocrafterEntry extends SimpleEnergyUsageEntry { + long getEnergyUsagePerPattern(); + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java index 1daca02e8..71589c077 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java @@ -50,8 +50,6 @@ import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceProvider; import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeRegistry; import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier; -import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingPreviewScreen; -import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingRequest; import com.refinedmods.refinedstorage.common.grid.NoopGridSynchronizer; import com.refinedmods.refinedstorage.common.grid.screen.hint.GridInsertionHintsImpl; import com.refinedmods.refinedstorage.common.grid.screen.hint.ItemGridInsertionHint; @@ -82,6 +80,7 @@ import com.refinedmods.refinedstorage.common.support.slotreference.CompositeSlotReferenceProvider; import com.refinedmods.refinedstorage.common.support.slotreference.InventorySlotReference; import com.refinedmods.refinedstorage.common.upgrade.UpgradeRegistryImpl; +import com.refinedmods.refinedstorage.common.util.ClientPlatformUtil; import com.refinedmods.refinedstorage.common.util.IdentifierUtil; import com.refinedmods.refinedstorage.common.util.ServerEventQueue; @@ -102,14 +101,12 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; -import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.Item; @@ -602,19 +599,10 @@ public Optional getPattern(final ItemStack stack, final Level level) { } @Override - public void openCraftingPreview(final List requests) { + public void openAutocraftingPreview(final List requests, @Nullable final Object parentScreen) { if (requests.isEmpty()) { return; } - final Minecraft minecraft = Minecraft.getInstance(); - if (minecraft.screen == null || minecraft.player == null) { - return; - } - final Inventory inventory = minecraft.player.getInventory(); - minecraft.setScreen(new AutocraftingPreviewScreen( - minecraft.screen, - inventory, - requests.stream().map(AutocraftingRequest::of).toList() - )); + ClientPlatformUtil.openCraftingPreview(requests, parentScreen); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java index 0bd4f665d..2bc3d18c5 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java @@ -40,12 +40,11 @@ import static com.refinedmods.refinedstorage.common.support.AbstractDirectionalBlock.tryExtractDirection; -// TODO: More energy usage for more patterns. public class AutocrafterBlockEntity extends AbstractBaseNetworkNodeContainerBlockEntity implements ExtendedMenuProvider, BlockEntityWithDrops, PatternInventory.Listener { static final int PATTERNS = 9; - private static final int MAX_CHAINED_CRAFTERS = 8; + private static final int MAX_CHAINED_AUTOCRAFTERS = 8; private static final String TAG_UPGRADES = "upgr"; private static final String TAG_PATTERNS = "patterns"; private static final String TAG_LOCK_MODE = "lm"; @@ -65,11 +64,18 @@ public AutocrafterBlockEntity(final BlockPos pos, final BlockState state) { ); this.upgradeContainer = new UpgradeContainer(UpgradeDestinations.AUTOCRAFTER, upgradeEnergyUsage -> { final long baseEnergyUsage = Platform.INSTANCE.getConfig().getAutocrafter().getEnergyUsage(); - mainNetworkNode.setEnergyUsage(baseEnergyUsage + upgradeEnergyUsage); + final long patternEnergyUsage = patternContainer.getEnergyUsage(); + mainNetworkNode.setEnergyUsage(baseEnergyUsage + patternEnergyUsage + upgradeEnergyUsage); setChanged(); }); - patternContainer.addListener(container -> setChanged()); - patternContainer.setListener(this); + this.patternContainer.addListener(container -> { + final long upgradeEnergyUsage = upgradeContainer.getEnergyUsage(); + final long baseEnergyUsage = Platform.INSTANCE.getConfig().getAutocrafter().getEnergyUsage(); + final long patternEnergyUsage = patternContainer.getEnergyUsage(); + mainNetworkNode.setEnergyUsage(baseEnergyUsage + patternEnergyUsage + upgradeEnergyUsage); + setChanged(); + }); + this.patternContainer.setListener(this); } @Override @@ -91,7 +97,7 @@ private boolean isPartOfChain() { return getChainingRoot() != this; } - // if there is another autocrafter next to us, that is pointing in our direction, + // If there is another autocrafter next to us, that is pointing in our direction, // and we are not part of a chain, we are the head of the chain private boolean isHeadOfChain() { if (level == null || isPartOfChain()) { @@ -119,7 +125,7 @@ private AutocrafterBlockEntity getChainingRoot() { private AutocrafterBlockEntity getChainingRoot(final int depth, final AutocrafterBlockEntity origin) { final Direction direction = tryExtractDirection(getBlockState()); - if (level == null || direction == null || depth >= MAX_CHAINED_CRAFTERS) { + if (level == null || direction == null || depth >= MAX_CHAINED_AUTOCRAFTERS) { return origin; } final BlockEntity neighbor = getConnectedMachine(); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterScreen.java index ab50b8f88..913f464e6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterScreen.java @@ -93,17 +93,6 @@ protected void renderBg(final GuiGraphics graphics, final float delta, final int } } - @Override - public boolean mouseClicked(final double mouseX, final double mouseY, final int clickedButton) { - if (!editName && getMenu().canChangeName() && isHovering( - titleLabelX, titleLabelY, titleMarquee.getEffectiveWidth(font), font.lineHeight, mouseX, mouseY - )) { - setEditName(true); - return true; - } - return super.mouseClicked(mouseX, mouseY, clickedButton); - } - @Override protected void init() { super.init(); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/PatternInventory.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/PatternInventory.java index d094ad103..cbb2cfcc7 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/PatternInventory.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/PatternInventory.java @@ -1,6 +1,7 @@ package com.refinedmods.refinedstorage.common.autocrafting; import com.refinedmods.refinedstorage.api.core.NullableType; +import com.refinedmods.refinedstorage.common.Platform; import com.refinedmods.refinedstorage.common.support.FilteredContainer; import java.util.Optional; @@ -44,6 +45,17 @@ public void setItem(final int slot, final ItemStack stack) { } } + long getEnergyUsage() { + long patterns = 0; + for (int i = 0; i < getContainerSize(); i++) { + final ItemStack stack = getItem(i); + if (!stack.isEmpty()) { + patterns++; + } + } + return patterns * Platform.INSTANCE.getConfig().getAutocrafter().getEnergyUsagePerPattern(); + } + interface Listener { void patternChanged(int slot); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/ProcessingPatternGridRenderer.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/ProcessingPatternGridRenderer.java index 467b224d1..71ca95ca9 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/ProcessingPatternGridRenderer.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/ProcessingPatternGridRenderer.java @@ -252,7 +252,7 @@ private void renderMatrixSlot(final GuiGraphics graphics, final ResourceSlot resourceSlot, final ProcessingMatrixResourceSlot matrixSlot) { if (matrixSlot.getResource() != null && menu.getView().isAutocraftable(matrixSlot.getResource())) { - AbstractGridScreen.renderCraftableBackground( + AbstractGridScreen.renderSlotBackground( graphics, resourceSlot.x + leftPos, resourceSlot.y + topPos, diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewContainerMenu.java index 2b9bc38d9..3534d49e5 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewContainerMenu.java @@ -65,40 +65,43 @@ void setCurrentRequest(final AutocraftingRequest request) { } void amountChanged(final double amount) { - if (currentRequest.trySendRequest(amount) && listener != null) { + if (currentRequest.sendPreviewRequest(amount) && listener != null) { listener.previewChanged(null); } } public void previewResponseReceived(final UUID id, final AutocraftingPreview preview) { - if (currentRequest.previewReceived(id, preview) && listener != null) { + if (!currentRequest.getId().equals(id)) { + return; + } + currentRequest.previewResponseReceived(preview); + if (listener != null) { listener.previewChanged(preview); } } void loadCurrentRequest() { + currentRequest.clearPreview(); if (listener != null) { - currentRequest.clearPreview(); listener.requestChanged(currentRequest); } } - void startRequest(final double amount) { - currentRequest.start(amount); + void sendRequest(final double amount) { + currentRequest.sendRequest(amount); } - boolean requestStarted(final UUID id) { - if (currentRequest.isStarted(id)) { - if (listener != null) { - listener.requestRemoved(currentRequest); - } - requests.remove(currentRequest); - if (!requests.isEmpty()) { - setCurrentRequest(requests.getFirst()); - return false; - } - return true; + public void responseReceived(final UUID id, final boolean started) { + if (!currentRequest.getId().equals(id) || !started) { + return; + } + requests.remove(currentRequest); + final boolean last = requests.isEmpty(); + if (listener != null) { + listener.requestRemoved(currentRequest, last); + } + if (!last) { + setCurrentRequest(requests.getFirst()); } - return false; } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewListener.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewListener.java index 5ba959f4e..5b38d81e8 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewListener.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewListener.java @@ -9,5 +9,5 @@ interface AutocraftingPreviewListener { void previewChanged(@Nullable AutocraftingPreview preview); - void requestRemoved(AutocraftingRequest request); + void requestRemoved(AutocraftingRequest request, boolean last); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java index fabe0d70a..2aec4e0de 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java @@ -13,7 +13,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.UUID; import javax.annotation.Nullable; import com.google.common.util.concurrent.RateLimiter; @@ -453,7 +452,7 @@ protected void reset() { @Override protected boolean confirm(final Double amount) { setPending(); - getMenu().startRequest(amount); + getMenu().sendRequest(amount); return false; } @@ -468,7 +467,11 @@ public void previewChanged(@Nullable final AutocraftingPreview preview) { } @Override - public void requestRemoved(final AutocraftingRequest request) { + public void requestRemoved(final AutocraftingRequest request, final boolean last) { + if (last) { + close(); + return; + } requestButtons.removeIf(requestButton -> requestButton.getRequest() == request); updateRequestsScrollbar(); for (int i = 0; i < requestButtons.size(); ++i) { @@ -490,10 +493,4 @@ private void updateRequestsScrollbar() { requestButtonsScrollbar.setEnabled(maxOffset > 0); requestButtonsScrollbar.setMaxOffset(maxOffset); } - - public void responseReceived(final UUID id, final boolean started) { - if (started && getMenu().requestStarted(id)) { - close(); - } - } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequest.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequest.java index f93798dd7..d761a33bd 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequest.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequest.java @@ -30,11 +30,11 @@ public static AutocraftingRequest of(final ResourceAmount resourceAmount) { return new AutocraftingRequest(UUID.randomUUID(), resourceAmount.resource(), displayAmount); } - boolean trySendRequest(final double amountRequested) { + boolean sendPreviewRequest(final double previewAmount) { if (!(resource instanceof PlatformResourceKey resourceKey)) { return false; } - final long normalizedAmount = resourceKey.getResourceType().normalizeAmount(amountRequested); + final long normalizedAmount = resourceKey.getResourceType().normalizeAmount(previewAmount); if (normalizedAmount == pendingPreviewAmount) { return false; } @@ -44,7 +44,12 @@ boolean trySendRequest(final double amountRequested) { return true; } - void start(final double amountRequested) { + void previewResponseReceived(final AutocraftingPreview previewReceived) { + this.pendingPreviewAmount = 0; + this.preview = previewReceived; + } + + void sendRequest(final double amountRequested) { if (!(resource instanceof PlatformResourceKey resourceKey)) { return; } @@ -52,6 +57,10 @@ void start(final double amountRequested) { C2SPackets.sendAutocraftingRequest(id, resourceKey, normalizedAmount); } + UUID getId() { + return id; + } + ResourceKey getResource() { return resource; } @@ -65,21 +74,8 @@ AutocraftingPreview getPreview() { return preview; } - boolean previewReceived(final UUID idReceived, final AutocraftingPreview previewReceived) { - if (id.equals(idReceived)) { - pendingPreviewAmount = 0; - preview = previewReceived; - return true; - } - return false; - } - void clearPreview() { - pendingPreviewAmount = 0; - preview = null; - } - - boolean isStarted(final UUID startedId) { - return id.equals(startedId); + this.pendingPreviewAmount = 0; + this.preview = null; } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/DefaultEnergyUsage.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/DefaultEnergyUsage.java index 594b16f5b..300aa23a8 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/DefaultEnergyUsage.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/content/DefaultEnergyUsage.java @@ -23,6 +23,7 @@ public final class DefaultEnergyUsage { public static final long RELAY_INPUT_NETWORK = 8; public static final long RELAY_OUTPUT_NETWORK = 8; public static final long AUTOCRAFTER = 4; + public static final long AUTOCRAFTER_PER_PATTERN = 2; public static final long CONTROLLER_CAPACITY = 1000; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridBlockEntity.java index b845dcf99..ded8da906 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridBlockEntity.java @@ -108,12 +108,12 @@ public Optional getPreview(final ResourceKey resource, fina } @Override - public boolean start(final ResourceKey resource, final long amount) { + public boolean startTask(final ResourceKey resource, final long amount) { final Network network = mainNetworkNode.getNetwork(); if (network == null) { return false; } - return network.getComponent(AutocraftingNetworkComponent.class).start(resource, amount); + return network.getComponent(AutocraftingNetworkComponent.class).startTask(resource, amount); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java index 68225b188..a89a4178f 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java @@ -494,8 +494,8 @@ public Optional getPreview(final ResourceKey resource, fina } @Override - public boolean start(final ResourceKey resource, final long amount) { - return requireNonNull(grid).start(resource, amount); + public boolean startTask(final ResourceKey resource, final long amount) { + return requireNonNull(grid).startTask(resource, amount); } public boolean isLargeSlot(final Slot slot) { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AutocraftableResourceHint.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AutocraftableResourceHint.java index 8760cce8d..363f1bdfc 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AutocraftableResourceHint.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AutocraftableResourceHint.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage.common.grid; public enum AutocraftableResourceHint { - AUTOCRAFTABLE(0xBF9F7F50), - PATTERN_IN_INVENTORY(0xBFFFD9A8); + AUTOCRAFTABLE(0x80FFA500), + PATTERN_IN_INVENTORY(0x7FFFFFFF); private final int color; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridContainerMenu.java index 880b98f84..0473d87b6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridContainerMenu.java @@ -4,7 +4,6 @@ import com.refinedmods.refinedstorage.api.grid.view.GridView; import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.api.resource.list.MutableResourceList; -import com.refinedmods.refinedstorage.api.resource.list.ResourceList; import com.refinedmods.refinedstorage.common.content.Menus; import com.refinedmods.refinedstorage.common.grid.view.ItemGridResource; import com.refinedmods.refinedstorage.common.support.RedstoneMode; @@ -128,7 +127,7 @@ public void clear(final boolean toPlayerInventory) { } @API(status = API.Status.INTERNAL) - public ResourceList getAvailableListForRecipeTransfer() { + public MutableResourceList getAvailableListForRecipeTransfer() { final MutableResourceList available = getView().copyBackingList(); addContainerToList(craftingGrid.getCraftingMatrix(), available); addContainerToList(gridPlayer.getInventory(), available); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/WirelessGrid.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/WirelessGrid.java index c9dbe75e0..aea58f720 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/WirelessGrid.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/WirelessGrid.java @@ -112,9 +112,9 @@ public Optional getPreview(final ResourceKey resource, fina } @Override - public boolean start(final ResourceKey resource, final long amount) { + public boolean startTask(final ResourceKey resource, final long amount) { return context.resolveNetwork() - .map(network -> network.getComponent(AutocraftingNetworkComponent.class).start(resource, amount)) + .map(network -> network.getComponent(AutocraftingNetworkComponent.class).startTask(resource, amount)) .orElse(false); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java index 9b6514190..633d7a46e 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java @@ -278,13 +278,13 @@ private void renderSlot(final GuiGraphics graphics, } } - private void tryRenderAutocraftableResourceHintBackground(final GuiGraphics guiGraphics, final Slot slot) { + private void tryRenderAutocraftableResourceHintBackground(final GuiGraphics graphics, final Slot slot) { if (!slot.isHighlightable() || !slot.isActive()) { return; } final AutocraftableResourceHint hint = getMenu().getAutocraftableResourceHint(slot); if (hint != null) { - renderCraftableBackground(guiGraphics, slot.x, slot.y, getMenu().isLargeSlot(slot), hint.getColor()); + renderSlotBackground(graphics, slot.x, slot.y, getMenu().isLargeSlot(slot), hint.getColor()); } } @@ -293,8 +293,21 @@ private void renderResourceWithAmount(final GuiGraphics graphics, final int slotY, final GridResource resource) { if (resource.isAutocraftable()) { - renderCraftableBackground(graphics, slotX, slotY, false, - AutocraftableResourceHint.AUTOCRAFTABLE.getColor()); + renderSlotBackground( + graphics, + slotX, + slotY, + false, + AutocraftableResourceHint.AUTOCRAFTABLE.getColor() + ); + } else if (resource.getAmount(getMenu().getView()) == 0) { + renderSlotBackground( + graphics, + slotX, + slotY, + false, + 0x66FF0000 + ); } if (resource instanceof PlatformGridResource platformResource) { platformResource.render(graphics, slotX, slotY); @@ -302,14 +315,19 @@ private void renderResourceWithAmount(final GuiGraphics graphics, renderAmount(graphics, slotX, slotY, resource); } - public static void renderCraftableBackground(final GuiGraphics graphics, - final int slotX, - final int slotY, - final boolean large, - final int color) { + public static void renderSlotBackground(final GuiGraphics graphics, + final int slotX, + final int slotY, + final boolean large, + final int color) { final int offset = large ? 4 : 0; - graphics.fill(slotX - offset, slotY - offset, slotX + 16 + offset, slotY + 16 + offset, - color); + graphics.fill( + slotX - offset, + slotY - offset, + slotX + 16 + offset, + slotY + 16 + offset, + color + ); } private void renderAmount(final GuiGraphics graphics, @@ -512,21 +530,12 @@ public boolean mouseClicked(final double mouseX, final double mouseY, final int return super.mouseClicked(mouseX, mouseY, clickedButton); } - private static boolean tryStartAutocrafting(final PlatformGridResource resource) { + private boolean tryStartAutocrafting(final PlatformGridResource resource) { final ResourceAmount request = resource.getAutocraftingRequest(); if (request == null) { return false; } - final List requests = new ArrayList<>(); - requests.add(request); - // TODO: Remove - temporary code - if (hasShiftDown()) { - requests.add(new ResourceAmount(request.resource(), request.amount() * 2)); - requests.add(new ResourceAmount(request.resource(), request.amount() * 3)); - requests.add(new ResourceAmount(request.resource(), request.amount() * 4)); - requests.add(new ResourceAmount(request.resource(), request.amount() * 4)); - } - RefinedStorageApi.INSTANCE.openCraftingPreview(requests); + RefinedStorageApi.INSTANCE.openAutocraftingPreview(List.of(request), this); return true; } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java index 7285521de..24a84c0ef 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java @@ -45,6 +45,7 @@ public class RelayBlockEntity extends AbstractBaseNetworkNodeContainerBlockEntit private static final String TAG_PASS_ENERGY = "passenergy"; private static final String TAG_PASS_SECURITY = "passsecurity"; private static final String TAG_PASS_STORAGE = "passstorage"; + private static final String TAG_PASS_AUTOCRAFTING = "passautocrafting"; private static final String TAG_FILTER_MODE = "fim"; private static final String TAG_ACCESS_MODE = "am"; private static final String TAG_PRIORITY = "pri"; @@ -157,6 +158,15 @@ void setPassSecurity(final boolean passSecurity) { setChanged(); } + boolean isPassAutocrafting() { + return mainNetworkNode.hasComponentType(RelayComponentType.AUTOCRAFTING); + } + + void setPassAutocrafting(final boolean passAutocrafting) { + mainNetworkNode.updateComponentType(RelayComponentType.AUTOCRAFTING, passAutocrafting); + setChanged(); + } + boolean isPassThrough() { return passThrough; } @@ -221,6 +231,7 @@ public void writeConfiguration(final CompoundTag tag, final HolderLookup.Provide tag.putBoolean(TAG_PASS_ENERGY, mainNetworkNode.hasComponentType(RelayComponentType.ENERGY)); tag.putBoolean(TAG_PASS_STORAGE, mainNetworkNode.hasComponentType(RelayComponentType.STORAGE)); tag.putBoolean(TAG_PASS_SECURITY, mainNetworkNode.hasComponentType(RelayComponentType.SECURITY)); + tag.putBoolean(TAG_PASS_AUTOCRAFTING, mainNetworkNode.hasComponentType(RelayComponentType.AUTOCRAFTING)); tag.putInt(TAG_ACCESS_MODE, AccessModeSettings.getAccessMode(accessMode)); tag.putInt(TAG_PRIORITY, priority); } @@ -247,8 +258,8 @@ public void readConfiguration(final CompoundTag tag, final HolderLookup.Provider mainNetworkNode.setPriority(priority); } - private Set getComponentTypes(final CompoundTag tag) { - final Set types = new HashSet<>(); + private Set> getComponentTypes(final CompoundTag tag) { + final Set> types = new HashSet<>(); if (tag.getBoolean(TAG_PASS_ENERGY)) { types.add(RelayComponentType.ENERGY); } @@ -258,6 +269,9 @@ private Set getComponentTypes(final CompoundTag tag) { if (tag.getBoolean(TAG_PASS_STORAGE)) { types.add(RelayComponentType.STORAGE); } + if (tag.getBoolean(TAG_PASS_AUTOCRAFTING)) { + types.add(RelayComponentType.AUTOCRAFTING); + } return types; } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayContainerMenu.java index d56e2f116..cf0cf88e6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayContainerMenu.java @@ -64,7 +64,8 @@ protected void onChangedOnClient(final Boolean newValue) { if (passThroughListener != null) { passThroughListener.passThroughChanged( Boolean.TRUE.equals(newValue), - Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_STORAGE).getValue()) + Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_STORAGE).getValue()), + Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_AUTOCRAFTING).getValue()) ); } } @@ -77,12 +78,26 @@ protected void onChangedOnClient(final Boolean newValue) { if (passThroughListener != null) { passThroughListener.passThroughChanged( Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_THROUGH).getValue()), - Boolean.TRUE.equals(newValue) + Boolean.TRUE.equals(newValue), + Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_AUTOCRAFTING).getValue()) ); } } }); registerProperty(new ClientProperty<>(RelayPropertyTypes.PASS_SECURITY, false)); + registerProperty(new ClientProperty<>(RelayPropertyTypes.PASS_AUTOCRAFTING, false) { + @Override + protected void onChangedOnClient(final Boolean newValue) { + super.onChangedOnClient(newValue); + if (passThroughListener != null) { + passThroughListener.passThroughChanged( + Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_THROUGH).getValue()), + Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_STORAGE).getValue()), + Boolean.TRUE.equals(newValue) + ); + } + } + }); registerProperty(new ClientProperty<>(PropertyTypes.FILTER_MODE, FilterMode.BLOCK)); registerProperty(new ClientProperty<>(StoragePropertyTypes.ACCESS_MODE, AccessMode.INSERT_EXTRACT)); registerProperty(new ClientProperty<>(StoragePropertyTypes.PRIORITY, 0)); @@ -116,6 +131,11 @@ protected void registerServerProperties(final RelayBlockEntity blockEntity) { blockEntity::isPassSecurity, blockEntity::setPassSecurity )); + registerProperty(new ServerProperty<>( + RelayPropertyTypes.PASS_AUTOCRAFTING, + blockEntity::isPassAutocrafting, + blockEntity::setPassAutocrafting + )); registerProperty(new ServerProperty<>( PropertyTypes.FILTER_MODE, blockEntity::getFilterMode, @@ -146,11 +166,15 @@ boolean isPassStorage() { return Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_STORAGE).getValue()); } + boolean isPassAutocrafting() { + return Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_AUTOCRAFTING).getValue()); + } + void setPassThroughListener(final PassThroughListener passThroughListener) { this.passThroughListener = passThroughListener; } interface PassThroughListener { - void passThroughChanged(boolean passThrough, boolean passStorage); + void passThroughChanged(boolean passThrough, boolean passStorage, boolean passAutocrafting); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayPassAutocraftingSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayPassAutocraftingSideButtonWidget.java new file mode 100644 index 000000000..164b51815 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayPassAutocraftingSideButtonWidget.java @@ -0,0 +1,30 @@ +package com.refinedmods.refinedstorage.common.networking; + +import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage.common.support.widget.AbstractYesNoSideButtonWidget; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; + +class RelayPassAutocraftingSideButtonWidget extends AbstractYesNoSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "relay.pass_autocrafting"); + private static final MutableComponent HELP = createTranslation("gui", "relay.pass_autocrafting.help"); + private static final ResourceLocation YES = createIdentifier("widget/side_button/relay/pass_autocrafting/yes"); + private static final ResourceLocation NO = createIdentifier("widget/side_button/relay/pass_autocrafting/no"); + + RelayPassAutocraftingSideButtonWidget(final ClientProperty property) { + super(property, TITLE, YES, NO); + } + + @Nullable + @Override + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayPropertyTypes.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayPropertyTypes.java index d39d23bd7..54ac381d8 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayPropertyTypes.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayPropertyTypes.java @@ -18,6 +18,9 @@ final class RelayPropertyTypes { static final PropertyType PASS_SECURITY = PropertyTypes.createBooleanProperty( createIdentifier("pass_security") ); + static final PropertyType PASS_AUTOCRAFTING = PropertyTypes.createBooleanProperty( + createIdentifier("pass_autocrafting") + ); private RelayPropertyTypes() { } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayScreen.java index 18dc2aa37..848997dca 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayScreen.java @@ -37,6 +37,8 @@ public class RelayScreen extends AbstractFilterScreen @Nullable private AbstractSideButtonWidget passStorageButton; @Nullable + private AbstractSideButtonWidget passAutocraftingButton; + @Nullable private AbstractSideButtonWidget filterModeButton; @Nullable private AbstractSideButtonWidget fuzzyModeButton; @@ -62,6 +64,7 @@ protected void init() { addSideButton(new RelayPassThroughSideButtonWidget(getMenu().getProperty(RelayPropertyTypes.PASS_THROUGH))); final boolean visible = !getMenu().isPassThrough(); addPassButtons(visible); + addFilterButtons(visible && (getMenu().isPassStorage() || getMenu().isPassAutocrafting())); addStorageButtons(visible && getMenu().isPassStorage()); } @@ -76,6 +79,12 @@ private void addPassButtons(final boolean visible) { passSecurityButton.visible = visible; addSideButton(passSecurityButton); + passAutocraftingButton = new RelayPassAutocraftingSideButtonWidget( + getMenu().getProperty(RelayPropertyTypes.PASS_AUTOCRAFTING) + ); + passAutocraftingButton.visible = visible; + addSideButton(passAutocraftingButton); + passStorageButton = new RelayPassStorageSideButtonWidget( getMenu().getProperty(RelayPropertyTypes.PASS_STORAGE) ); @@ -83,7 +92,7 @@ private void addPassButtons(final boolean visible) { addSideButton(passStorageButton); } - private void addStorageButtons(final boolean visible) { + private void addFilterButtons(final boolean visible) { filterModeButton = new FilterModeSideButtonWidget( getMenu().getProperty(PropertyTypes.FILTER_MODE), ALLOW_FILTER_MODE_HELP, @@ -98,7 +107,9 @@ private void addStorageButtons(final boolean visible) { ); fuzzyModeButton.visible = visible; addSideButton(fuzzyModeButton); + } + private void addStorageButtons(final boolean visible) { accessModeButton = new AccessModeSideButtonWidget(getMenu().getProperty(StoragePropertyTypes.ACCESS_MODE)); accessModeButton.visible = visible; addSideButton(accessModeButton); @@ -113,9 +124,12 @@ private void addStorageButtons(final boolean visible) { } @Override - public void passThroughChanged(final boolean passThrough, final boolean passStorage) { + public void passThroughChanged(final boolean passThrough, + final boolean passStorage, + final boolean passAutocrafting) { updatePassButtons(passThrough); - updateStorageButtons(passThrough, passStorage); + updateFilterButtons(!passThrough && (passStorage || passAutocrafting)); + updateStorageButtons(!passThrough && passStorage); } private void updatePassButtons(final boolean passThrough) { @@ -128,20 +142,26 @@ private void updatePassButtons(final boolean passThrough) { if (passStorageButton != null) { passStorageButton.visible = !passThrough; } + if (passAutocraftingButton != null) { + passAutocraftingButton.visible = !passThrough; + } } - private void updateStorageButtons(final boolean passThrough, final boolean passStorage) { + private void updateFilterButtons(final boolean visible) { if (filterModeButton != null) { - filterModeButton.visible = !passThrough && passStorage; + filterModeButton.visible = visible; } if (fuzzyModeButton != null) { - fuzzyModeButton.visible = !passThrough && passStorage; + fuzzyModeButton.visible = visible; } + } + + private void updateStorageButtons(final boolean visible) { if (accessModeButton != null) { - accessModeButton.visible = !passThrough && passStorage; + accessModeButton.visible = visible; } if (priorityButton != null) { - priorityButton.visible = !passThrough && passStorage; + priorityButton.visible = visible; } } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/portablegrid/PortableGrid.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/portablegrid/PortableGrid.java index 90d45792b..d636764ab 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/portablegrid/PortableGrid.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/portablegrid/PortableGrid.java @@ -136,7 +136,7 @@ public Optional getPreview(final ResourceKey resource, fina } @Override - public boolean start(final ResourceKey resource, final long amount) { + public boolean startTask(final ResourceKey resource, final long amount) { return false; } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/AutocraftingStorageMonitorContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/AutocraftingStorageMonitorContainerMenu.java index 5cb83aa86..156f18540 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/AutocraftingStorageMonitorContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/AutocraftingStorageMonitorContainerMenu.java @@ -44,7 +44,7 @@ public Optional getPreview(final ResourceKey resource, fina } @Override - public boolean start(final ResourceKey resource, final long amount) { - return requireNonNull(storageMonitor).start(resource, amount); + public boolean startTask(final ResourceKey resource, final long amount) { + return requireNonNull(storageMonitor).startTask(resource, amount); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntity.java index ec255feac..6018c945b 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntity.java @@ -374,11 +374,11 @@ public Optional getPreview(final ResourceKey resource, fina } @Override - public boolean start(final ResourceKey resource, final long amount) { + public boolean startTask(final ResourceKey resource, final long amount) { final Network network = mainNetworkNode.getNetwork(); if (network == null) { return false; } - return network.getComponent(AutocraftingNetworkComponent.class).start(resource, amount); + return network.getComponent(AutocraftingNetworkComponent.class).startTask(resource, amount); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingRequestPacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingRequestPacket.java index 18ba3b302..f4fc8c825 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingRequestPacket.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingRequestPacket.java @@ -34,7 +34,7 @@ public record AutocraftingRequestPacket(UUID id, public static void handle(final AutocraftingRequestPacket packet, final PacketContext ctx) { if (ctx.getPlayer().containerMenu instanceof AutocraftingPreviewProvider provider) { - final boolean started = provider.start(packet.resource(), packet.amount()); + final boolean started = provider.startTask(packet.resource(), packet.amount()); S2CPackets.sendAutocraftingResponse((ServerPlayer) ctx.getPlayer(), packet.id, started); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/util/ClientPlatformUtil.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/util/ClientPlatformUtil.java index 8d3f95629..25b475b21 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/util/ClientPlatformUtil.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/util/ClientPlatformUtil.java @@ -1,15 +1,20 @@ package com.refinedmods.refinedstorage.common.util; import com.refinedmods.refinedstorage.api.autocrafting.AutocraftingPreview; +import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingPreviewScreen; +import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingRequest; +import java.util.List; import java.util.UUID; import javax.annotation.Nullable; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.toasts.SystemToast; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.level.Level; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; @@ -43,7 +48,20 @@ public static void autocraftingPreviewResponseReceived(final UUID id, final Auto public static void autocraftingResponseReceived(final UUID id, final boolean started) { if (Minecraft.getInstance().screen instanceof AutocraftingPreviewScreen screen) { - screen.responseReceived(id, started); + screen.getMenu().responseReceived(id, started); } } + + public static void openCraftingPreview(final List requests, @Nullable final Object parentScreen) { + final Minecraft minecraft = Minecraft.getInstance(); + if ((!(parentScreen instanceof Screen) && minecraft.screen == null) || minecraft.player == null) { + return; + } + final Inventory inventory = minecraft.player.getInventory(); + minecraft.setScreen(new AutocraftingPreviewScreen( + parentScreen instanceof Screen castedParentScreen ? castedParentScreen : minecraft.screen, + inventory, + requests.stream().map(AutocraftingRequest::of).toList() + )); + } } diff --git a/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json b/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json index aa062d858..df57807b1 100644 --- a/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json +++ b/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json @@ -171,7 +171,7 @@ "gui.refinedstorage.security_manager.redstone_mode_help": "When this device is inactive, the network will not be protected.", "gui.refinedstorage.security_manager.fallback_security_card_slot_hint": "Slot for a Fallback Security Card.", "gui.refinedstorage.security_manager.no_fallback_security_card_consequence": "Add a Fallback Security Card to this slot to set permissions for every player without a Security Card. By default, all actions are denied.", - "gui.refinedstorage.relay.filter_help": "Resources which should be exposed from the input network to the output network if the Relay isn't in pass-through mode.", + "gui.refinedstorage.relay.filter_help": "Resources and patterns which should be exposed from the input network to the output network if the Relay isn't in pass-through mode.", "gui.refinedstorage.relay.pass_through": "Pass-through", "gui.refinedstorage.relay.pass_through.help": "Whether this device should pass-through the entire input network signal as-is. Turn this off to selectively expose components to the output network.", "gui.refinedstorage.relay.pass_energy": "Pass energy", @@ -180,6 +180,8 @@ "gui.refinedstorage.relay.pass_storage.help": "Whether this device should pass the storage from the input network to the output network.", "gui.refinedstorage.relay.pass_security": "Pass security", "gui.refinedstorage.relay.pass_security.help": "Whether this device should pass the security settings from the input network to the output network.", + "gui.refinedstorage.relay.pass_autocrafting": "Pass autocrafting", + "gui.refinedstorage.relay.pass_autocrafting.help": "Whether this device should pass the autocrafting patterns from the input network to the output network.", "gui.refinedstorage.relay.filter_mode.allow.help": "Only expose resources from the input network to the output network that are configured in the filters.", "gui.refinedstorage.relay.filter_mode.block.help": "Don't expose resources from the input network to the output network that are configured in the filters.", "gui.refinedstorage.disk_interface.filter_mode.allow.help": "Only allow resources into the storage disks or into the network that are configured in the filters.", @@ -593,6 +595,8 @@ "text.autoconfig.refinedstorage.option.autocrafter.tooltip": "Configuration for the Autocrafter.", "text.autoconfig.refinedstorage.option.autocrafter.energyUsage": "Energy usage", "text.autoconfig.refinedstorage.option.autocrafter.energyUsage.tooltip": "The energy used by the Autocrafter.", + "text.autoconfig.refinedstorage.option.autocrafter.energyUsagePerPattern": "Energy usage per pattern", + "text.autoconfig.refinedstorage.option.autocrafter.energyUsagePerPattern.tooltip": "The additional energy used per pattern.", "advancements.refinedstorage.root.description": "Use one or multiple Controllers in a storage network to provide your network with energy", "advancements.refinedstorage.connecting": "Connecting", "advancements.refinedstorage.connecting.description": "Use Cable to connect devices with each other, or place devices against each other", diff --git a/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/relay/pass_autocrafting/no.png b/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/relay/pass_autocrafting/no.png new file mode 100644 index 000000000..eb3202c06 Binary files /dev/null and b/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/relay/pass_autocrafting/no.png differ diff --git a/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/relay/pass_autocrafting/yes.png b/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/relay/pass_autocrafting/yes.png new file mode 100644 index 000000000..ba3740ef0 Binary files /dev/null and b/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/relay/pass_autocrafting/yes.png differ diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ConfigImpl.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ConfigImpl.java index ed77c12bf..91d5d7024 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ConfigImpl.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ConfigImpl.java @@ -120,9 +120,7 @@ public class ConfigImpl implements ConfigData, com.refinedmods.refinedstorage.co private RelayEntryImpl relay = new RelayEntryImpl(); @ConfigEntry.Gui.CollapsibleObject - private SimpleEnergyUsageEntryImpl autocrafter = new SimpleEnergyUsageEntryImpl( - DefaultEnergyUsage.AUTOCRAFTER - ); + private AutocrafterEntryImpl autocrafter = new AutocrafterEntryImpl(); public static ConfigImpl get() { return AutoConfig.getConfigHolder(ConfigImpl.class).getConfig(); @@ -285,7 +283,7 @@ public RelayEntry getRelay() { } @Override - public SimpleEnergyUsageEntry getAutocrafter() { + public AutocrafterEntry getAutocrafter() { return autocrafter; } @@ -725,4 +723,20 @@ public long getOutputNetworkEnergyUsage() { return outputNetworkEnergyUsage; } } + + private static class AutocrafterEntryImpl implements AutocrafterEntry { + private long energyUsage = DefaultEnergyUsage.AUTOCRAFTER; + + private long energyUsagePerPattern = DefaultEnergyUsage.AUTOCRAFTER_PER_PATTERN; + + @Override + public long getEnergyUsagePerPattern() { + return energyUsagePerPattern; + } + + @Override + public long getEnergyUsage() { + return energyUsage; + } + } } diff --git a/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/query/GridQueryParserImplTest.java b/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/query/GridQueryParserImplTest.java index e2853833a..7ec393bf3 100644 --- a/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/query/GridQueryParserImplTest.java +++ b/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/query/GridQueryParserImplTest.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage.api.grid.query; -import com.refinedmods.refinedstorage.api.grid.view.FakeGridResourceAttributeKeys; import com.refinedmods.refinedstorage.api.grid.view.GridResource; import com.refinedmods.refinedstorage.api.grid.view.GridResourceAttributeKey; +import com.refinedmods.refinedstorage.api.grid.view.GridResourceAttributeKeys; import com.refinedmods.refinedstorage.api.grid.view.GridResourceImpl; import com.refinedmods.refinedstorage.api.grid.view.GridView; import com.refinedmods.refinedstorage.api.grid.view.GridViewImpl; @@ -30,7 +30,7 @@ class GridQueryParserImplTest { private final GridQueryParser queryParser = new GridQueryParserImpl( LexerTokenMappings.DEFAULT_MAPPINGS, ParserOperatorMappings.DEFAULT_MAPPINGS, - FakeGridResourceAttributeKeys.UNARY_OPERATOR_TO_ATTRIBUTE_KEY_MAPPING + GridResourceAttributeKeys.UNARY_OPERATOR_TO_ATTRIBUTE_KEY_MAPPING ); private final GridView view = new GridViewImpl( @@ -297,9 +297,9 @@ private static class R implements GridResource { this.name = name; this.amount = amount; this.attributes = Map.of( - FakeGridResourceAttributeKeys.MOD_ID, Set.of(modId), - FakeGridResourceAttributeKeys.MOD_NAME, Set.of(modName), - FakeGridResourceAttributeKeys.TAGS, tags + GridResourceAttributeKeys.MOD_ID, Set.of(modId), + GridResourceAttributeKeys.MOD_NAME, Set.of(modName), + GridResourceAttributeKeys.TAGS, tags ); } diff --git a/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/FakeGridResourceAttributeKeys.java b/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/GridResourceAttributeKeys.java similarity index 80% rename from refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/FakeGridResourceAttributeKeys.java rename to refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/GridResourceAttributeKeys.java index 4a8b7a59e..63c69d395 100644 --- a/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/FakeGridResourceAttributeKeys.java +++ b/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/GridResourceAttributeKeys.java @@ -3,7 +3,7 @@ import java.util.Map; import java.util.Set; -public enum FakeGridResourceAttributeKeys implements GridResourceAttributeKey { +public enum GridResourceAttributeKeys implements GridResourceAttributeKey { MOD_ID, MOD_NAME, TAGS; diff --git a/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/GridResourceImpl.java b/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/GridResourceImpl.java index 64d8c216a..d7ca8774b 100644 --- a/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/GridResourceImpl.java +++ b/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/view/GridResourceImpl.java @@ -20,8 +20,8 @@ public GridResourceImpl(final ResourceKey resource) { public GridResourceImpl(final ResourceKey resource, final boolean autocraftable) { this.resource = resource; this.attributes = Map.of( - FakeGridResourceAttributeKeys.MOD_ID, Set.of(resource.toString()), - FakeGridResourceAttributeKeys.MOD_NAME, Set.of(resource.toString()) + GridResourceAttributeKeys.MOD_ID, Set.of(resource.toString()), + GridResourceAttributeKeys.MOD_NAME, Set.of(resource.toString()) ); this.autocraftable = autocraftable; } diff --git a/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/watcher/GridWatcherManagerImplTest.java b/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/watcher/GridWatcherManagerImplTest.java index c7c8ecb91..e6bae7f70 100644 --- a/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/watcher/GridWatcherManagerImplTest.java +++ b/refinedstorage-grid-api/src/test/java/com/refinedmods/refinedstorage/api/grid/watcher/GridWatcherManagerImplTest.java @@ -37,11 +37,11 @@ void setUp() { void shouldAddWatcherAndNotifyOfChanges() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - rootStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); + rootStorage.insert(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); // Act - sut.addWatcher(watcher, FakeActor.class, rootStorage); - rootStorage.insert(B, 5, Action.EXECUTE, FakeActor.INSTANCE); + sut.addWatcher(watcher, ActorFixture.class, rootStorage); + rootStorage.insert(B, 5, Action.EXECUTE, ActorFixture.INSTANCE); // Assert verify(watcher, times(1)).onChanged(B, 5, null); @@ -52,12 +52,12 @@ void shouldAddWatcherAndNotifyOfChanges() { void shouldNotAddDuplicateWatcher() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - sut.addWatcher(watcher, FakeActor.class, rootStorage); + sut.addWatcher(watcher, ActorFixture.class, rootStorage); // Act & assert assertThrows( IllegalArgumentException.class, - () -> sut.addWatcher(watcher, FakeActor.class, rootStorage), + () -> sut.addWatcher(watcher, ActorFixture.class, rootStorage), "Watcher is already registered" ); } @@ -66,12 +66,12 @@ void shouldNotAddDuplicateWatcher() { void shouldRemoveWatcher() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - rootStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - sut.addWatcher(watcher, FakeActor.class, rootStorage); + rootStorage.insert(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); + sut.addWatcher(watcher, ActorFixture.class, rootStorage); // Act sut.removeWatcher(watcher, rootStorage); - rootStorage.insert(B, 5, Action.EXECUTE, FakeActor.INSTANCE); + rootStorage.insert(B, 5, Action.EXECUTE, ActorFixture.INSTANCE); // Assert verifyNoInteractions(watcher); @@ -94,15 +94,15 @@ void shouldNotRemoveWatcherThatIsNotRegistered() { void shouldAddAndRemoveAndAddWatcherAgain() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - rootStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); + rootStorage.insert(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); // Act - sut.addWatcher(watcher, FakeActor.class, rootStorage); - rootStorage.insert(B, 5, Action.EXECUTE, FakeActor.INSTANCE); + sut.addWatcher(watcher, ActorFixture.class, rootStorage); + rootStorage.insert(B, 5, Action.EXECUTE, ActorFixture.INSTANCE); sut.removeWatcher(watcher, rootStorage); - rootStorage.insert(C, 4, Action.EXECUTE, FakeActor.INSTANCE); - sut.addWatcher(watcher, FakeActor.class, rootStorage); - rootStorage.insert(D, 3, Action.EXECUTE, FakeActor.INSTANCE); + rootStorage.insert(C, 4, Action.EXECUTE, ActorFixture.INSTANCE); + sut.addWatcher(watcher, ActorFixture.class, rootStorage); + rootStorage.insert(D, 3, Action.EXECUTE, ActorFixture.INSTANCE); // Assert verify(watcher, times(1)).onChanged(B, 5, null); @@ -114,15 +114,15 @@ void shouldAddAndRemoveAndAddWatcherAgain() { void shouldDetachAll() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - rootStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - sut.addWatcher(watcher, FakeActor.class, rootStorage); + rootStorage.insert(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); + sut.addWatcher(watcher, ActorFixture.class, rootStorage); // Act sut.detachAll(rootStorage); - rootStorage.insert(B, 10, Action.EXECUTE, FakeActor.INSTANCE); + rootStorage.insert(B, 10, Action.EXECUTE, ActorFixture.INSTANCE); assertThrows(IllegalArgumentException.class, () -> sut.addWatcher( watcher, - FakeActor.class, + ActorFixture.class, rootStorage ), "Watcher is already registered"); @@ -134,14 +134,14 @@ void shouldDetachAll() { void shouldAttachAll() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - rootStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - sut.addWatcher(watcher, FakeActor.class, rootStorage); + rootStorage.insert(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); + sut.addWatcher(watcher, ActorFixture.class, rootStorage); sut.detachAll(rootStorage); - rootStorage.insert(B, 5, Action.EXECUTE, FakeActor.INSTANCE); + rootStorage.insert(B, 5, Action.EXECUTE, ActorFixture.INSTANCE); // Act sut.attachAll(rootStorage); - rootStorage.insert(C, 4, Action.EXECUTE, FakeActor.INSTANCE); + rootStorage.insert(C, 4, Action.EXECUTE, ActorFixture.INSTANCE); // Assert final InOrder inOrder = inOrder(watcher); @@ -157,7 +157,7 @@ void shouldNotifyAboutActivenessChange() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); sut.activeChanged(true); - sut.addWatcher(watcher, FakeActor.class, rootStorage); + sut.addWatcher(watcher, ActorFixture.class, rootStorage); // Act sut.activeChanged(false); @@ -170,10 +170,10 @@ void shouldNotifyAboutActivenessChange() { inOrder.verifyNoMoreInteractions(); } - private static class FakeActor implements Actor { - public static final FakeActor INSTANCE = new FakeActor(); + private static class ActorFixture implements Actor { + public static final ActorFixture INSTANCE = new ActorFixture(); - private FakeActor() { + private ActorFixture() { } @Override diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ConfigImpl.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ConfigImpl.java index ec2a356bc..96fa0e471 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ConfigImpl.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ConfigImpl.java @@ -52,7 +52,7 @@ public class ConfigImpl implements Config { private final SimpleEnergyUsageEntry fallbackSecurityCard; private final SimpleEnergyUsageEntry securityManager; private final RelayEntry relay; - private final SimpleEnergyUsageEntry autocrafter; + private final AutocrafterEntryImpl autocrafter; public ConfigImpl() { screenSize = builder @@ -97,7 +97,7 @@ public ConfigImpl() { ); securityManager = new SimpleEnergyUsageEntryImpl("securityManager", DefaultEnergyUsage.SECURITY_MANAGER); relay = new RelayEntryImpl(); - autocrafter = new SimpleEnergyUsageEntryImpl("autocrafter", DefaultEnergyUsage.AUTOCRAFTER); + autocrafter = new AutocrafterEntryImpl(); spec = builder.build(); } @@ -264,7 +264,7 @@ public RelayEntry getRelay() { } @Override - public SimpleEnergyUsageEntry getAutocrafter() { + public AutocrafterEntryImpl getAutocrafter() { return autocrafter; } @@ -925,4 +925,30 @@ public long getOutputNetworkEnergyUsage() { return outputNetworkEnergyUsage.get(); } } + + private class AutocrafterEntryImpl implements AutocrafterEntry { + private final ModConfigSpec.LongValue energyUsage; + private final ModConfigSpec.LongValue energyUsagePerPattern; + + AutocrafterEntryImpl() { + builder.translation(translationKey("autocrafter")).push("autocrafter"); + energyUsage = builder + .translation(translationKey("autocrafter." + ENERGY_USAGE)) + .defineInRange(ENERGY_USAGE, DefaultEnergyUsage.AUTOCRAFTER, 0, Long.MAX_VALUE); + energyUsagePerPattern = builder + .translation(translationKey("autocrafter.energyUsagePerPattern")) + .defineInRange("energyUsagePerPattern", DefaultEnergyUsage.AUTOCRAFTER_PER_PATTERN, 0, Long.MAX_VALUE); + builder.pop(); + } + + @Override + public long getEnergyUsagePerPattern() { + return energyUsagePerPattern.get(); + } + + @Override + public long getEnergyUsage() { + return energyUsage.get(); + } + } } diff --git a/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/AutocraftingNetworkComponent.java b/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/AutocraftingNetworkComponent.java index 8bca0a60a..9cd137fc8 100644 --- a/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/AutocraftingNetworkComponent.java +++ b/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/AutocraftingNetworkComponent.java @@ -1,11 +1,23 @@ package com.refinedmods.refinedstorage.api.network.autocrafting; import com.refinedmods.refinedstorage.api.autocrafting.AutocraftingPreviewProvider; -import com.refinedmods.refinedstorage.api.autocrafting.PatternRepository; +import com.refinedmods.refinedstorage.api.autocrafting.Pattern; import com.refinedmods.refinedstorage.api.network.NetworkComponent; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; + +import java.util.Set; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.4.8") -public interface AutocraftingNetworkComponent extends NetworkComponent, PatternRepository, AutocraftingPreviewProvider { +public interface AutocraftingNetworkComponent extends NetworkComponent, AutocraftingPreviewProvider { + void addListener(PatternListener listener); + + void removeListener(PatternListener listener); + + Set getPatterns(); + + Set getOutputs(); + + boolean contains(AutocraftingNetworkComponent component); } diff --git a/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/ParentContainer.java b/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/ParentContainer.java new file mode 100644 index 000000000..0c8d73264 --- /dev/null +++ b/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/ParentContainer.java @@ -0,0 +1,12 @@ +package com.refinedmods.refinedstorage.api.network.autocrafting; + +import com.refinedmods.refinedstorage.api.autocrafting.Pattern; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.8") +public interface ParentContainer { + void add(Pattern pattern); + + void remove(Pattern pattern); +} diff --git a/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/PatternListener.java b/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/PatternListener.java new file mode 100644 index 000000000..37e5f23c7 --- /dev/null +++ b/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/PatternListener.java @@ -0,0 +1,12 @@ +package com.refinedmods.refinedstorage.api.network.autocrafting; + +import com.refinedmods.refinedstorage.api.autocrafting.Pattern; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.8") +public interface PatternListener { + void onAdded(Pattern pattern); + + void onRemoved(Pattern pattern); +} diff --git a/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/PatternProvider.java b/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/PatternProvider.java index 0b229b584..0cfaa1052 100644 --- a/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/PatternProvider.java +++ b/refinedstorage-network-api/src/main/java/com/refinedmods/refinedstorage/api/network/autocrafting/PatternProvider.java @@ -1,13 +1,14 @@ package com.refinedmods.refinedstorage.api.network.autocrafting; -import com.refinedmods.refinedstorage.api.autocrafting.Pattern; - -import java.util.Set; - import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.4.8") -@FunctionalInterface public interface PatternProvider { - Set getPatterns(); + void onAddedIntoContainer(ParentContainer parentContainer); + + void onRemovedFromContainer(ParentContainer parentContainer); + + default boolean contains(AutocraftingNetworkComponent component) { + return false; + } } diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/NetworkTestExtension.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/NetworkTestExtension.java index 916b06bc0..17e9b8e0e 100644 --- a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/NetworkTestExtension.java +++ b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/NetworkTestExtension.java @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage.api.network.node.NetworkNode; import com.refinedmods.refinedstorage.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage.network.test.fixtures.NetworkTestFixtures; import com.refinedmods.refinedstorage.network.test.nodefactory.NetworkNodeFactory; import java.lang.annotation.Annotation; diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeActor.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeActor.java deleted file mode 100644 index 8cc2bb82a..000000000 --- a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeActor.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.refinedmods.refinedstorage.network.test.fake; - -import com.refinedmods.refinedstorage.api.storage.Actor; - -public final class FakeActor implements Actor { - public static final FakeActor INSTANCE = new FakeActor(); - - private FakeActor() { - } - - @Override - public String getName() { - return "Fake"; - } -} diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakePermissions.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakePermissions.java deleted file mode 100644 index ce1cd2fbf..000000000 --- a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakePermissions.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.refinedmods.refinedstorage.network.test.fake; - -import com.refinedmods.refinedstorage.api.network.security.Permission; - -public enum FakePermissions implements Permission { - ALLOW_BY_DEFAULT, OTHER, OTHER2 -} diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeSecurityActors.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeSecurityActors.java deleted file mode 100644 index cff73542a..000000000 --- a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeSecurityActors.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.refinedmods.refinedstorage.network.test.fake; - -import com.refinedmods.refinedstorage.api.network.security.SecurityActor; - -public enum FakeSecurityActors implements SecurityActor { - A, B, C -} diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/ActorFixture.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/ActorFixture.java new file mode 100644 index 000000000..6523160cf --- /dev/null +++ b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/ActorFixture.java @@ -0,0 +1,15 @@ +package com.refinedmods.refinedstorage.network.test.fixtures; + +import com.refinedmods.refinedstorage.api.storage.Actor; + +public final class ActorFixture implements Actor { + public static final ActorFixture INSTANCE = new ActorFixture(); + + private ActorFixture() { + } + + @Override + public String getName() { + return "Fake"; + } +} diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/NetworkTestFixtures.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/NetworkTestFixtures.java similarity index 87% rename from refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/NetworkTestFixtures.java rename to refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/NetworkTestFixtures.java index 3d79eb28f..7be2b7176 100644 --- a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/NetworkTestFixtures.java +++ b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/NetworkTestFixtures.java @@ -1,6 +1,5 @@ -package com.refinedmods.refinedstorage.network.test; +package com.refinedmods.refinedstorage.network.test.fixtures; -import com.refinedmods.refinedstorage.api.autocrafting.PatternRepositoryImpl; import com.refinedmods.refinedstorage.api.core.component.ComponentMapFactory; import com.refinedmods.refinedstorage.api.network.Network; import com.refinedmods.refinedstorage.api.network.NetworkComponent; @@ -16,7 +15,6 @@ import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy; import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage.api.resource.list.MutableResourceListImpl; -import com.refinedmods.refinedstorage.network.test.fake.FakePermissions; public final class NetworkTestFixtures { public static final ComponentMapFactory NETWORK_COMPONENT_MAP_FACTORY = @@ -37,11 +35,11 @@ public final class NetworkTestFixtures { ); NETWORK_COMPONENT_MAP_FACTORY.addFactory( SecurityNetworkComponent.class, - network -> new SecurityNetworkComponentImpl(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) + network -> new SecurityNetworkComponentImpl(SecurityPolicy.of(PermissionFixtures.ALLOW_BY_DEFAULT)) ); NETWORK_COMPONENT_MAP_FACTORY.addFactory( AutocraftingNetworkComponent.class, - network -> new AutocraftingNetworkComponentImpl(new PatternRepositoryImpl()) + network -> new AutocraftingNetworkComponentImpl() ); } diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/PermissionFixtures.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/PermissionFixtures.java new file mode 100644 index 000000000..f31ec81cd --- /dev/null +++ b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/PermissionFixtures.java @@ -0,0 +1,7 @@ +package com.refinedmods.refinedstorage.network.test.fixtures; + +import com.refinedmods.refinedstorage.api.network.security.Permission; + +public enum PermissionFixtures implements Permission { + ALLOW_BY_DEFAULT, OTHER, OTHER2 +} diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeResources.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/ResourceFixtures.java similarity index 56% rename from refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeResources.java rename to refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/ResourceFixtures.java index ad0726c6f..2c72110d7 100644 --- a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/FakeResources.java +++ b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/ResourceFixtures.java @@ -1,8 +1,8 @@ -package com.refinedmods.refinedstorage.network.test.fake; +package com.refinedmods.refinedstorage.network.test.fixtures; import com.refinedmods.refinedstorage.api.resource.ResourceKey; -public enum FakeResources implements ResourceKey { +public enum ResourceFixtures implements ResourceKey { A, A_ALTERNATIVE, A_ALTERNATIVE2, diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/SecurityActorFixtures.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/SecurityActorFixtures.java new file mode 100644 index 000000000..8a5eccf7d --- /dev/null +++ b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/SecurityActorFixtures.java @@ -0,0 +1,7 @@ +package com.refinedmods.refinedstorage.network.test.fixtures; + +import com.refinedmods.refinedstorage.api.network.security.SecurityActor; + +public enum SecurityActorFixtures implements SecurityActor { + A, B, C +} diff --git a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/package-info.java b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/package-info.java similarity index 77% rename from refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/package-info.java rename to refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/package-info.java index 99740d1a9..0eab2d668 100644 --- a/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fake/package-info.java +++ b/refinedstorage-network-test/src/main/java/com/refinedmods/refinedstorage/network/test/fixtures/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage.network.test.fake; +package com.refinedmods.refinedstorage.network.test.fixtures; import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImpl.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImpl.java index 0e7fe1329..399e3ed9b 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImpl.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImpl.java @@ -4,45 +4,50 @@ import com.refinedmods.refinedstorage.api.autocrafting.AutocraftingPreviewItem; import com.refinedmods.refinedstorage.api.autocrafting.AutocraftingPreviewType; import com.refinedmods.refinedstorage.api.autocrafting.Pattern; -import com.refinedmods.refinedstorage.api.autocrafting.PatternRepository; +import com.refinedmods.refinedstorage.api.autocrafting.PatternRepositoryImpl; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.autocrafting.ParentContainer; +import com.refinedmods.refinedstorage.api.network.autocrafting.PatternListener; import com.refinedmods.refinedstorage.api.network.autocrafting.PatternProvider; import com.refinedmods.refinedstorage.api.network.node.container.NetworkNodeContainer; import com.refinedmods.refinedstorage.api.resource.ResourceKey; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; -public class AutocraftingNetworkComponentImpl implements AutocraftingNetworkComponent { - private final PatternRepository patternRepository; - - public AutocraftingNetworkComponentImpl(final PatternRepository patternRepository) { - this.patternRepository = patternRepository; - } +public class AutocraftingNetworkComponentImpl implements AutocraftingNetworkComponent, ParentContainer { + private final Set providers = new HashSet<>(); + private final Set listeners = new HashSet<>(); + private final PatternRepositoryImpl patternRepository = new PatternRepositoryImpl(); @Override public void onContainerAdded(final NetworkNodeContainer container) { if (container.getNode() instanceof PatternProvider provider) { - provider.getPatterns().forEach(patternRepository::add); + provider.onAddedIntoContainer(this); + providers.add(provider); } } @Override public void onContainerRemoved(final NetworkNodeContainer container) { if (container.getNode() instanceof PatternProvider provider) { - provider.getPatterns().forEach(patternRepository::remove); + provider.onRemovedFromContainer(this); + providers.remove(provider); } } @Override public void add(final Pattern pattern) { patternRepository.add(pattern); + listeners.forEach(listener -> listener.onAdded(pattern)); } @Override public void remove(final Pattern pattern) { + listeners.forEach(listener -> listener.onRemoved(pattern)); patternRepository.remove(pattern); } @@ -51,6 +56,11 @@ public Set getOutputs() { return patternRepository.getOutputs(); } + @Override + public boolean contains(final AutocraftingNetworkComponent component) { + return providers.stream().anyMatch(provider -> provider.contains(component)); + } + @Override public Optional getPreview(final ResourceKey resource, final long amount) { final List items = new ArrayList<>(); @@ -69,7 +79,22 @@ public Optional getPreview(final ResourceKey resource, fina } @Override - public boolean start(final ResourceKey resource, final long amount) { + public boolean startTask(final ResourceKey resource, final long amount) { return true; } + + @Override + public void addListener(final PatternListener listener) { + listeners.add(listener); + } + + @Override + public void removeListener(final PatternListener listener) { + listeners.remove(listener); + } + + @Override + public Set getPatterns() { + return patternRepository.getAll(); + } } diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/patternprovider/PatternProviderNetworkNode.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/patternprovider/PatternProviderNetworkNode.java index 7a74782a1..ef2f103db 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/patternprovider/PatternProviderNetworkNode.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/patternprovider/PatternProviderNetworkNode.java @@ -1,18 +1,17 @@ package com.refinedmods.refinedstorage.api.network.impl.node.patternprovider; import com.refinedmods.refinedstorage.api.autocrafting.Pattern; -import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.autocrafting.ParentContainer; import com.refinedmods.refinedstorage.api.network.autocrafting.PatternProvider; import com.refinedmods.refinedstorage.api.network.impl.node.SimpleNetworkNode; -import java.util.Arrays; -import java.util.Objects; +import java.util.HashSet; import java.util.Set; -import java.util.stream.Collectors; import javax.annotation.Nullable; public class PatternProviderNetworkNode extends SimpleNetworkNode implements PatternProvider { private final Pattern[] patterns; + private final Set parents = new HashSet<>(); public PatternProviderNetworkNode(final long energyUsage, final int patterns) { super(energyUsage); @@ -21,37 +20,50 @@ public PatternProviderNetworkNode(final long energyUsage, final int patterns) { public void setPattern(final int index, @Nullable final Pattern pattern) { final Pattern oldPattern = patterns[index]; - if (oldPattern != null && network != null) { - network.getComponent(AutocraftingNetworkComponent.class).remove(oldPattern); + if (oldPattern != null) { + parents.forEach(parent -> parent.remove(oldPattern)); } patterns[index] = pattern; - if (pattern != null && network != null) { - network.getComponent(AutocraftingNetworkComponent.class).add(pattern); + if (pattern != null) { + parents.forEach(parent -> parent.add(pattern)); } } @Override protected void onActiveChanged(final boolean newActive) { super.onActiveChanged(newActive); - if (!newActive && network != null) { - final AutocraftingNetworkComponent component = network.getComponent(AutocraftingNetworkComponent.class); + if (!newActive) { for (final Pattern pattern : patterns) { if (pattern != null) { - component.remove(pattern); + parents.forEach(parent -> parent.remove(pattern)); } } - } else if (newActive && network != null) { - final AutocraftingNetworkComponent component = network.getComponent(AutocraftingNetworkComponent.class); - for (final Pattern pattern : patterns) { - if (pattern != null) { - component.add(pattern); - } + return; + } + for (final Pattern pattern : patterns) { + if (pattern != null) { + parents.forEach(parent -> parent.add(pattern)); } } } @Override - public Set getPatterns() { - return Arrays.stream(patterns).filter(Objects::nonNull).collect(Collectors.toSet()); + public void onAddedIntoContainer(final ParentContainer parentContainer) { + parents.add(parentContainer); + for (final Pattern pattern : patterns) { + if (pattern != null) { + parentContainer.add(pattern); + } + } + } + + @Override + public void onRemovedFromContainer(final ParentContainer parentContainer) { + parents.remove(parentContainer); + for (final Pattern pattern : patterns) { + if (pattern != null) { + parentContainer.remove(pattern); + } + } } } diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayComponentType.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayComponentType.java index 5366e818d..4e6751d22 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayComponentType.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayComponentType.java @@ -1,7 +1,50 @@ package com.refinedmods.refinedstorage.api.network.impl.node.relay; -public enum RelayComponentType { - ENERGY, - SECURITY, - STORAGE +import com.refinedmods.refinedstorage.api.core.NullableType; +import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; + +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Function; + +public class RelayComponentType { + public static final RelayComponentType ENERGY = new RelayComponentType<>( + network -> network.getComponent(EnergyNetworkComponent.class), + output -> output::setEnergyDelegate + ); + public static final RelayComponentType SECURITY = new RelayComponentType<>( + network -> network.getComponent(SecurityNetworkComponent.class), + output -> output::setSecurityDelegate + ); + public static final RelayComponentType STORAGE = new RelayComponentType<>( + network -> network.getComponent(StorageNetworkComponent.class), + output -> output::setStorageDelegate + ); + public static final RelayComponentType AUTOCRAFTING = new RelayComponentType<>( + network -> network.getComponent(AutocraftingNetworkComponent.class), + output -> output::setAutocraftingDelegate + ); + public static final Set> ALL = Set.of(ENERGY, SECURITY, STORAGE, AUTOCRAFTING); + + private final Function componentProvider; + private final Function> componentApplier; + + private RelayComponentType(final Function componentProvider, + final Function> componentApplier) { + this.componentProvider = componentProvider; + this.componentApplier = componentApplier; + } + + void apply(final Network network, final RelayOutputNetworkNode output) { + final T component = componentProvider.apply(network); + componentApplier.apply(output).accept(component); + } + + void remove(final RelayOutputNetworkNode output) { + componentApplier.apply(output).accept(null); + } } diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayInputNetworkNode.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayInputNetworkNode.java index cdca4d326..734b82bff 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayInputNetworkNode.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayInputNetworkNode.java @@ -1,10 +1,7 @@ package com.refinedmods.refinedstorage.api.network.impl.node.relay; import com.refinedmods.refinedstorage.api.network.Network; -import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; -import com.refinedmods.refinedstorage.api.network.security.SecurityNetworkComponent; -import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage.api.storage.AccessMode; @@ -16,7 +13,7 @@ public class RelayInputNetworkNode extends AbstractNetworkNode { private final long energyUsage; - private final Set componentTypes = new HashSet<>(); + private final Set> componentTypes = new HashSet<>(); @Nullable private RelayOutputNetworkNode outputNode; @@ -41,13 +38,13 @@ public void setOutputNode(@Nullable final RelayOutputNetworkNode outputNode) { this.outputNode = outputNode; } - public void setComponentTypes(final Set componentTypes) { + public void setComponentTypes(final Set> componentTypes) { this.componentTypes.clear(); this.componentTypes.addAll(componentTypes); updateComponents(); } - public void updateComponentType(final RelayComponentType componentType, final boolean enabled) { + public void updateComponentType(final RelayComponentType componentType, final boolean enabled) { if (enabled) { componentTypes.add(componentType); } else { @@ -61,18 +58,13 @@ private void updateComponents() { return; } final boolean valid = network != null && isActive(); - final boolean hasEnergy = componentTypes.contains(RelayComponentType.ENERGY); - outputNode.setEnergyDelegate(valid && hasEnergy - ? network.getComponent(EnergyNetworkComponent.class) - : null); - final boolean hasSecurity = componentTypes.contains(RelayComponentType.SECURITY); - outputNode.setSecurityDelegate(valid && hasSecurity - ? network.getComponent(SecurityNetworkComponent.class) - : null); - final boolean hasStorage = componentTypes.contains(RelayComponentType.STORAGE); - outputNode.setStorageDelegate(valid && hasStorage - ? network.getComponent(StorageNetworkComponent.class) - : null); + for (final RelayComponentType componentType : RelayComponentType.ALL) { + if (!componentTypes.contains(componentType) || !valid) { + componentType.remove(outputNode); + } else { + componentType.apply(network, outputNode); + } + } } public void setAccessMode(final AccessMode accessMode) { @@ -105,7 +97,7 @@ public void setFilterNormalizer(final UnaryOperator normalizer) { } } - public boolean hasComponentType(final RelayComponentType componentType) { + public boolean hasComponentType(final RelayComponentType componentType) { return componentTypes.contains(componentType); } diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputNetworkNode.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputNetworkNode.java index 6e7b6e7c1..a4ef2b8a2 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputNetworkNode.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputNetworkNode.java @@ -1,5 +1,8 @@ package com.refinedmods.refinedstorage.api.network.impl.node.relay; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.autocrafting.ParentContainer; +import com.refinedmods.refinedstorage.api.network.autocrafting.PatternProvider; import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.energy.EnergyProvider; import com.refinedmods.refinedstorage.api.network.impl.node.AbstractNetworkNode; @@ -20,9 +23,10 @@ import javax.annotation.Nullable; public class RelayOutputNetworkNode extends AbstractNetworkNode - implements EnergyProvider, SecurityDecisionProvider, StorageProvider { + implements EnergyProvider, SecurityDecisionProvider, StorageProvider, PatternProvider { private final long energyUsage; private final RelayOutputStorage storage = new RelayOutputStorage(); + private final RelayOutputPatternProvider patternProvider = new RelayOutputPatternProvider(); @Nullable private EnergyNetworkComponent energyDelegate; @@ -45,6 +49,10 @@ void setStorageDelegate(@Nullable final StorageNetworkComponent storageDelegate) this.storage.setDelegate(storageDelegate); } + void setAutocraftingDelegate(@Nullable final AutocraftingNetworkComponent autocraftingDelegate) { + this.patternProvider.setDelegate(autocraftingDelegate); + } + void setAccessMode(final AccessMode accessMode) { this.storage.setAccessMode(accessMode); } @@ -58,19 +66,25 @@ void setPriority(final int priority) { void setFilters(final Set filters) { this.storage.setFilters(filters); + this.patternProvider.setFilters(filters); } void setFilterMode(final FilterMode filterMode) { this.storage.setFilterMode(filterMode); + this.patternProvider.setFilterMode(filterMode); } void setFilterNormalizer(final UnaryOperator normalizer) { this.storage.setFilterNormalizer(normalizer); + this.patternProvider.setFilterNormalizer(normalizer); } @Override public long getEnergyUsage() { - if (energyDelegate != null || securityDelegate != null || storage.hasDelegate()) { + if (energyDelegate != null + || securityDelegate != null + || storage.hasDelegate() + || patternProvider.hasDelegate()) { return energyUsage; } return 0; @@ -103,6 +117,11 @@ public boolean contains(final SecurityNetworkComponent securityComponent) { || (securityDelegate != null && securityDelegate.contains(securityComponent)); } + @Override + public boolean contains(final AutocraftingNetworkComponent component) { + return patternProvider.contains(component); + } + @Override public SecurityDecision isAllowed(final Permission permission, final SecurityActor actor) { if (securityDelegate == null || securityDelegate.contains(securityDelegate)) { @@ -120,4 +139,14 @@ public boolean isProviderActive() { public Storage getStorage() { return storage; } + + @Override + public void onAddedIntoContainer(final ParentContainer parentContainer) { + patternProvider.onAddedIntoContainer(parentContainer); + } + + @Override + public void onRemovedFromContainer(final ParentContainer parentContainer) { + patternProvider.onRemovedFromContainer(parentContainer); + } } diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputPatternProvider.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputPatternProvider.java new file mode 100644 index 000000000..83cd64107 --- /dev/null +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputPatternProvider.java @@ -0,0 +1,107 @@ +package com.refinedmods.refinedstorage.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage.api.autocrafting.Pattern; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.network.autocrafting.ParentContainer; +import com.refinedmods.refinedstorage.api.network.autocrafting.PatternListener; +import com.refinedmods.refinedstorage.api.network.autocrafting.PatternProvider; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.api.resource.filter.Filter; +import com.refinedmods.refinedstorage.api.resource.filter.FilterMode; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +class RelayOutputPatternProvider implements PatternProvider, PatternListener { + private final Filter filter = new Filter(); + private final Set parents = new HashSet<>(); + @Nullable + private AutocraftingNetworkComponent delegate; + + void setFilters(final Set filters) { + reset(() -> filter.setFilters(filters)); + } + + void setFilterMode(final FilterMode filterMode) { + reset(() -> filter.setMode(filterMode)); + } + + void setFilterNormalizer(final UnaryOperator normalizer) { + reset(() -> filter.setNormalizer(normalizer)); + } + + private void reset(final Runnable action) { + final AutocraftingNetworkComponent oldDelegate = delegate; + setDelegate(null); + action.run(); + setDelegate(oldDelegate); + } + + void setDelegate(@Nullable final AutocraftingNetworkComponent delegate) { + if (this.delegate != null) { + parents.forEach(parent -> getPatterns().forEach(parent::remove)); + this.delegate.removeListener(this); + } + this.delegate = delegate; + if (delegate != null) { + parents.forEach(parent -> getPatterns().forEach(parent::add)); + delegate.addListener(this); + } + } + + boolean hasDelegate() { + return delegate != null; + } + + private Set getPatterns() { + if (delegate == null) { + return Collections.emptySet(); + } + return delegate.getPatterns().stream().filter(this::isPatternAllowed).collect(Collectors.toSet()); + } + + private boolean isPatternAllowed(final Pattern pattern) { + return pattern.getOutputResources().stream().anyMatch(filter::isAllowed); + } + + @Override + public void onAdded(final Pattern pattern) { + if (delegate == null || !isPatternAllowed(pattern) || delegate.contains(delegate)) { + return; + } + parents.forEach(parent -> parent.add(pattern)); + } + + @Override + public void onRemoved(final Pattern pattern) { + if (delegate == null || !isPatternAllowed(pattern) || delegate.contains(delegate)) { + return; + } + parents.forEach(parent -> parent.remove(pattern)); + } + + @Override + public boolean contains(final AutocraftingNetworkComponent component) { + return component == delegate || (delegate != null && delegate.contains(component)); + } + + @Override + public void onAddedIntoContainer(final ParentContainer parentContainer) { + if (delegate != null) { + delegate.getPatterns().forEach(parentContainer::add); + } + parents.add(parentContainer); + } + + @Override + public void onRemovedFromContainer(final ParentContainer parentContainer) { + if (delegate != null) { + delegate.getPatterns().forEach(parentContainer::remove); + } + parents.remove(parentContainer); + } +} diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/AbstractNetworkBuilderImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/AbstractNetworkBuilderImplTest.java index b1baf2c3f..3dd8cb2de 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/AbstractNetworkBuilderImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/AbstractNetworkBuilderImplTest.java @@ -7,7 +7,7 @@ import com.refinedmods.refinedstorage.api.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage.api.network.node.NetworkNode; import com.refinedmods.refinedstorage.api.network.node.container.NetworkNodeContainer; -import com.refinedmods.refinedstorage.network.test.NetworkTestFixtures; +import com.refinedmods.refinedstorage.network.test.fixtures.NetworkTestFixtures; import java.util.ArrayList; import java.util.List; diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/FakeConnectionProvider.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/ConnectionProviderImpl.java similarity index 91% rename from refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/FakeConnectionProvider.java rename to refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/ConnectionProviderImpl.java index 7d946a673..bcf97dfa5 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/FakeConnectionProvider.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/ConnectionProviderImpl.java @@ -14,18 +14,18 @@ import java.util.Set; import java.util.stream.Collectors; -public class FakeConnectionProvider implements ConnectionProvider { +public class ConnectionProviderImpl implements ConnectionProvider { private final Map> connections = new HashMap<>(); private final List allowed = new ArrayList<>(); - public FakeConnectionProvider with(final NetworkNodeContainer... containers) { + public ConnectionProviderImpl with(final NetworkNodeContainer... containers) { for (final NetworkNodeContainer container : containers) { with(container); } return this; } - public FakeConnectionProvider with(final NetworkNodeContainer container) { + public ConnectionProviderImpl with(final NetworkNodeContainer container) { if (allowed.contains(container)) { throw new IllegalArgumentException(); } @@ -33,7 +33,7 @@ public FakeConnectionProvider with(final NetworkNodeContainer container) { return this; } - public FakeConnectionProvider connect(final NetworkNodeContainer from, final NetworkNodeContainer to) { + public ConnectionProviderImpl connect(final NetworkNodeContainer from, final NetworkNodeContainer to) { if (!allowed.contains(from) || !allowed.contains(to)) { throw new IllegalArgumentException(); } diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/InitializeNetworkBuilderImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/InitializeNetworkBuilderImplTest.java index 71356d4df..b04e0eb5b 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/InitializeNetworkBuilderImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/InitializeNetworkBuilderImplTest.java @@ -12,7 +12,7 @@ class InitializeNetworkBuilderImplTest extends AbstractNetworkBuilderImplTest { @Test void shouldNotFormNetworkIfAlreadyFormed() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container = createContainerWithNetwork(); // Act @@ -25,7 +25,7 @@ void shouldNotFormNetworkIfAlreadyFormed() { @Test void shouldFormNetwork() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container = createContainer(); final NetworkNodeContainer unrelatedContainer = createContainerWithNetwork(); @@ -58,7 +58,7 @@ void shouldFormNetwork() { @Test void shouldJoinExistingNetwork() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer existingContainer1 = createContainerWithNetwork(); final NetworkNodeContainer existingContainer2 = @@ -111,7 +111,7 @@ void shouldJoinExistingNetwork() { @Test void shouldMergeWithExistingNetworks() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer existingContainer0 = createContainerWithNetwork(); final NetworkNodeContainer existingContainer1 = @@ -166,7 +166,7 @@ void shouldMergeWithExistingNetworks() { @Test void shouldFormNetworkIfThereAreNeighborsWithoutNetwork() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer unrelatedContainer = createContainerWithNetwork(); diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/PriorityNetworkBuilderImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/PriorityNetworkBuilderImplTest.java index 7b1ef3c53..65e1f920b 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/PriorityNetworkBuilderImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/PriorityNetworkBuilderImplTest.java @@ -11,7 +11,7 @@ import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.api.storage.EmptyActor; import com.refinedmods.refinedstorage.api.storage.StorageImpl; -import com.refinedmods.refinedstorage.network.test.fake.FakeActor; +import com.refinedmods.refinedstorage.network.test.fixtures.ActorFixture; import java.util.Optional; import java.util.function.Supplier; @@ -39,7 +39,7 @@ void shouldRespectPriorityWhenSplitting() { final NetworkSide slave = createNetworkSide(SLAVE, () -> originalNetwork); clearInvocations(master.watcher); - final ConnectionProvider connectionProvider = new FakeConnectionProvider() + final ConnectionProvider connectionProvider = new ConnectionProviderImpl() .with(master.a, master.b, slave.a, slave.b) .connect(master.a, master.b) .connect(slave.a, slave.b); @@ -78,7 +78,7 @@ void shouldRespectPriorityWhenMerging() { final NetworkNodeContainer connector = createContainer(); final NetworkSide slave = createNetworkSide(SLAVE, () -> new NetworkImpl(componentMapFactory)); - final ConnectionProvider connectionProvider = new FakeConnectionProvider() + final ConnectionProvider connectionProvider = new ConnectionProviderImpl() .with(master.a, master.b, connector, slave.a, slave.b) .connect(master.a, master.b) .connect(master.b, connector) @@ -118,7 +118,7 @@ private NetworkSide createNetworkSide(final MasterSlave side, final Supplier networkFactory) { final StorageNetworkNode nodeA = new StorageNetworkNode(0, 0, 1); final StorageImpl storage = new StorageImpl(); - storage.insert(side, 10, Action.EXECUTE, FakeActor.INSTANCE); + storage.insert(side, 10, Action.EXECUTE, ActorFixture.INSTANCE); nodeA.setProvider(index -> Optional.of(storage)); final NetworkNodeContainer a = createContainerWithNetwork( nodeA, diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/RemoveNetworkBuilderImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/RemoveNetworkBuilderImplTest.java index de75b6b9b..5b92977a9 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/RemoveNetworkBuilderImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/RemoveNetworkBuilderImplTest.java @@ -20,7 +20,7 @@ void shouldNotBeAbleToRemoveWithoutNetworkAssigned() { final NetworkNodeContainer container = createContainer(); // Act - final Executable action = () -> sut.remove(container, new FakeConnectionProvider()); + final Executable action = () -> sut.remove(container, new ConnectionProviderImpl()); // Assert assertThrows(IllegalStateException.class, action); @@ -29,7 +29,7 @@ void shouldNotBeAbleToRemoveWithoutNetworkAssigned() { @Test void shouldSplitNetwork() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container1 = createContainerWithNetwork(); final NetworkNodeContainer container2 = @@ -70,7 +70,7 @@ void shouldSplitNetwork() { @Test void shouldSplitNetworkInTwo() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container1 = createContainerWithNetwork(); final NetworkNodeContainer container2 = @@ -137,7 +137,7 @@ void shouldSplitNetworkInTwo() { @Test void shouldSplitNetworkInThree() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container1 = createContainerWithNetwork(); @@ -219,7 +219,7 @@ void shouldSplitNetworkInThree() { @Test void shouldRemoveNetwork() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container = createContainerWithNetwork(); final NetworkNodeContainer unrelatedContainer = createContainerWithNetwork(); diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/UpdateNetworkBuilderImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/UpdateNetworkBuilderImplTest.java index 429409722..bf521a6b5 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/UpdateNetworkBuilderImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/UpdateNetworkBuilderImplTest.java @@ -19,7 +19,7 @@ void shouldNotBeAbleToUpdateWithoutNetworkAssigned() { final NetworkNodeContainer container = createContainer(); // Act - final Executable action = () -> sut.update(container, new FakeConnectionProvider()); + final Executable action = () -> sut.update(container, new ConnectionProviderImpl()); // Assert assertThrows(IllegalStateException.class, action); @@ -28,7 +28,7 @@ void shouldNotBeAbleToUpdateWithoutNetworkAssigned() { @Test void shouldUpdateWithSoleContainer() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container1 = createContainerWithNetwork(); @@ -62,7 +62,7 @@ void shouldUpdateWithSoleContainer() { @Test void shouldSplitNetworkWhenUpdatingWithSoleContainerOnLeftSide() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container1 = createContainerWithNetwork(); final NetworkNodeContainer container2 = @@ -123,7 +123,7 @@ void shouldSplitNetworkWhenUpdatingWithSoleContainerOnLeftSide() { @Test void shouldSplitNetworkWhenUpdatingWithTwoContainersOnBothSides() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container1 = createContainerWithNetwork(); final NetworkNodeContainer container2 = @@ -187,7 +187,7 @@ void shouldSplitNetworkWhenUpdatingWithTwoContainersOnBothSides() { @Test void shouldSplitNetworkAndMergeAdditionalContainerWhenUpdating() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container1 = createContainerWithNetwork(); final NetworkNodeContainer container2 = createContainerWithNetwork(); @@ -257,7 +257,7 @@ void shouldSplitNetworkAndMergeAdditionalContainerWhenUpdating() { @Test void shouldNotUpdateAnythingWhenStateIsTheSame() { // Arrange - final FakeConnectionProvider connectionProvider = new FakeConnectionProvider(); + final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(); final NetworkNodeContainer container1 = createContainerWithNetwork(); final NetworkNodeContainer container2 = diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImplTest.java index 791020b50..cebdb63ee 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImplTest.java @@ -1,13 +1,12 @@ package com.refinedmods.refinedstorage.api.network.impl.autocrafting; -import com.refinedmods.refinedstorage.api.autocrafting.PatternRepositoryImpl; import com.refinedmods.refinedstorage.api.network.impl.node.patternprovider.PatternProviderNetworkNode; import com.refinedmods.refinedstorage.api.network.node.container.NetworkNodeContainer; -import com.refinedmods.refinedstorage.network.test.fake.FakeResources; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; import static org.assertj.core.api.Assertions.assertThat; class AutocraftingNetworkComponentImplTest { @@ -15,14 +14,14 @@ class AutocraftingNetworkComponentImplTest { @BeforeEach void setUp() { - sut = new AutocraftingNetworkComponentImpl(new PatternRepositoryImpl()); + sut = new AutocraftingNetworkComponentImpl(); } @Test void shouldAddPatternsFromPatternProvider() { // Arrange final PatternProviderNetworkNode provider = new PatternProviderNetworkNode(0, 5); - provider.setPattern(1, new SimplePattern(FakeResources.A)); + provider.setPattern(1, new SimplePattern(A)); final NetworkNodeContainer container = () -> provider; @@ -30,14 +29,14 @@ void shouldAddPatternsFromPatternProvider() { sut.onContainerAdded(container); // Assert - assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(FakeResources.A); + assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(A); } @Test void shouldRemovePatternsFromPatternProvider() { // Arrange final PatternProviderNetworkNode provider = new PatternProviderNetworkNode(0, 5); - provider.setPattern(1, new SimplePattern(FakeResources.A)); + provider.setPattern(1, new SimplePattern(A)); final NetworkNodeContainer container = () -> provider; sut.onContainerAdded(container); @@ -52,19 +51,19 @@ void shouldRemovePatternsFromPatternProvider() { @Test void shouldAddPatternManually() { // Arrange - final SimplePattern pattern = new SimplePattern(FakeResources.A); + final SimplePattern pattern = new SimplePattern(A); // Act sut.add(pattern); // Assert - assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(FakeResources.A); + assertThat(sut.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(A); } @Test void shouldRemovePatternManually() { // Arrange - final SimplePattern pattern = new SimplePattern(FakeResources.A); + final SimplePattern pattern = new SimplePattern(A); sut.add(pattern); // Act @@ -75,12 +74,12 @@ void shouldRemovePatternManually() { } @Test - void shouldStart() { - sut.start(FakeResources.A, 10); + void shouldStartTask() { + sut.startTask(A, 10); } @Test void shouldGetPreview() { - sut.getPreview(FakeResources.A, 10); + sut.getPreview(A, 10); } } diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/GraphNetworkComponentImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/GraphNetworkComponentImplTest.java index a8432d265..41235a4b6 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/GraphNetworkComponentImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/GraphNetworkComponentImplTest.java @@ -4,7 +4,7 @@ import com.refinedmods.refinedstorage.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage.api.network.node.NetworkNode; import com.refinedmods.refinedstorage.api.network.node.container.NetworkNodeContainer; -import com.refinedmods.refinedstorage.network.test.NetworkTestFixtures; +import com.refinedmods.refinedstorage.network.test.fixtures.NetworkTestFixtures; import java.util.Set; diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/detector/DetectorNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/detector/DetectorNetworkNodeTest.java index bce2d6535..685efa5a9 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/detector/DetectorNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/detector/DetectorNetworkNodeTest.java @@ -19,7 +19,7 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java index 83c5c4023..c0d5f8ede 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java @@ -24,9 +24,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/DefaultExporterNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/DefaultExporterNetworkNodeTest.java index aefed2b8b..cc1ee51ab 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/DefaultExporterNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/DefaultExporterNetworkNodeTest.java @@ -20,9 +20,9 @@ import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; import static org.assertj.core.api.Assertions.assertThat; class DefaultExporterNetworkNodeTest extends AbstractExporterNetworkNodeTest { diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java index e83190d85..e7b312bae 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java @@ -15,8 +15,8 @@ import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; import static org.assertj.core.api.Assertions.assertThat; class RandomExporterNetworkNodeTest extends AbstractExporterNetworkNodeTest { diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java index 30c056623..a7f2f3b5c 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java @@ -16,10 +16,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.D; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.D; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java index 1f52e431f..f0cbd3de8 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java @@ -18,7 +18,7 @@ import com.refinedmods.refinedstorage.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage.network.test.NetworkTest; import com.refinedmods.refinedstorage.network.test.SetupNetwork; -import com.refinedmods.refinedstorage.network.test.fake.FakeActor; +import com.refinedmods.refinedstorage.network.test.fixtures.ActorFixture; import java.util.Optional; import java.util.Set; @@ -30,9 +30,9 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; import static com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -50,8 +50,8 @@ class ExternalStorageNetworkNodeTest { @Test void testInitialState(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Act - final long inserted = networkStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - final long extracted = networkStorage.extract(A, 10, Action.EXECUTE, FakeActor.INSTANCE); + final long inserted = networkStorage.insert(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); + final long extracted = networkStorage.extract(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); // Assert assertThat(inserted).isZero(); @@ -62,7 +62,7 @@ void testInitialState(@InjectNetworkStorageComponent final StorageNetworkCompone assertThat(sut.getStorageConfiguration().getFilterMode()).isEqualTo(FilterMode.BLOCK); assertThat(networkStorage.getAll()).isEmpty(); assertThat(networkStorage.getStored()).isZero(); - assertThat(networkStorage.findTrackedResourceByActorType(A, FakeActor.class)).isEmpty(); + assertThat(networkStorage.findTrackedResourceByActorType(A, ActorFixture.class)).isEmpty(); } @Test @@ -484,17 +484,17 @@ void shouldTrackChangesWhenExtracting( ); // Act - final long extracted = networkStorage.extract(A, 7, action, FakeActor.INSTANCE); + final long extracted = networkStorage.extract(A, 7, action, ActorFixture.INSTANCE); // Assert assertThat(extracted).isEqualTo(7); final Optional trackedResource = networkStorage.findTrackedResourceByActorType( A, - FakeActor.class + ActorFixture.class ); if (action == Action.EXECUTE) { assertThat(trackedResource).get().usingRecursiveComparison().isEqualTo(new TrackedResource( - FakeActor.INSTANCE.getName(), + ActorFixture.INSTANCE.getName(), 0 )); assertThat(trackedResourceWasPresent).describedAs("tracked resource was present").isTrue(); @@ -516,13 +516,13 @@ void shouldNotTrackChangesWhenExtractionFailed( sut.initialize(new ExternalStorageProviderFactoryImpl(provider)); // Act - final long extracted = networkStorage.extract(A, 7, action, FakeActor.INSTANCE); + final long extracted = networkStorage.extract(A, 7, action, ActorFixture.INSTANCE); // Assert assertThat(extracted).isZero(); final Optional trackedResource = networkStorage.findTrackedResourceByActorType( A, - FakeActor.class + ActorFixture.class ); assertThat(trackedResource).isEmpty(); } @@ -544,17 +544,17 @@ void shouldTrackChangesWhenInserting( ); // Act - final long inserted = networkStorage.insert(A, 10, action, FakeActor.INSTANCE); + final long inserted = networkStorage.insert(A, 10, action, ActorFixture.INSTANCE); // Assert assertThat(inserted).isEqualTo(10); final Optional trackedResource = networkStorage.findTrackedResourceByActorType( A, - FakeActor.class + ActorFixture.class ); if (action == Action.EXECUTE) { assertThat(trackedResource).get().usingRecursiveComparison().isEqualTo(new TrackedResource( - FakeActor.INSTANCE.getName(), + ActorFixture.INSTANCE.getName(), 0 )); assertThat(trackedResourceWasPresent).describedAs("tracked resource was present").isTrue(); @@ -576,13 +576,13 @@ void shouldNotTrackChangesWhenInsertionFailed( sut.initialize(new ExternalStorageProviderFactoryImpl(provider)); // Act - final long inserted = networkStorage.insert(A, 10, action, FakeActor.INSTANCE); + final long inserted = networkStorage.insert(A, 10, action, ActorFixture.INSTANCE); // Assert assertThat(inserted).isZero(); final Optional trackedResource = networkStorage.findTrackedResourceByActorType( A, - FakeActor.class + ActorFixture.class ); assertThat(trackedResource).isEmpty(); } @@ -593,7 +593,7 @@ private AtomicBoolean trackWhetherResourceHasChangedAndTrackedResourceIsAvailabl final AtomicBoolean found = new AtomicBoolean(); networkStorage.addListener(change -> { if (change.resource().equals(A)) { - found.set(networkStorage.findTrackedResourceByActorType(A, FakeActor.class).isPresent()); + found.set(networkStorage.findTrackedResourceByActorType(A, ActorFixture.class).isPresent()); } }); return found; diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/grid/GridNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/grid/GridNetworkNodeTest.java index 9223a2105..a25f7cbde 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/grid/GridNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/grid/GridNetworkNodeTest.java @@ -16,17 +16,17 @@ import com.refinedmods.refinedstorage.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage.network.test.NetworkTest; import com.refinedmods.refinedstorage.network.test.SetupNetwork; -import com.refinedmods.refinedstorage.network.test.fake.FakeActor; +import com.refinedmods.refinedstorage.network.test.fixtures.ActorFixture; import com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.D; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.D; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyLong; @@ -89,13 +89,13 @@ void shouldNotifyWatchersOfStorageChanges( ) { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - sut.addWatcher(watcher, FakeActor.class); + sut.addWatcher(watcher, ActorFixture.class); // Act networkStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - networkStorage.insert(A, 1, Action.EXECUTE, FakeActor.INSTANCE); + networkStorage.insert(A, 1, Action.EXECUTE, ActorFixture.INSTANCE); sut.removeWatcher(watcher); - networkStorage.insert(A, 1, Action.EXECUTE, FakeActor.INSTANCE); + networkStorage.insert(A, 1, Action.EXECUTE, ActorFixture.INSTANCE); // Assert final ArgumentCaptor resources = ArgumentCaptor.forClass(ResourceKey.class); @@ -128,7 +128,7 @@ void shouldNotBeAbleToAddDuplicateWatcher() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); final Class actorType1 = EmptyActor.class; - final Class actorType2 = FakeActor.class; + final Class actorType2 = ActorFixture.class; sut.addWatcher(watcher, actorType1); @@ -146,22 +146,22 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( ) { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - sut.addWatcher(watcher, FakeActor.class); + sut.addWatcher(watcher, ActorFixture.class); // Act // This one shouldn't be ignored! - otherStorage.insert(C, 10, Action.EXECUTE, FakeActor.INSTANCE); + otherStorage.insert(C, 10, Action.EXECUTE, ActorFixture.INSTANCE); sut.setNetwork(otherNetwork); network.removeContainer(() -> sut); otherNetwork.addContainer(() -> sut); // these one shouldn't be ignored either - otherStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); + otherStorage.insert(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); otherStorage.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); // these should be ignored - storage.insert(B, 10, Action.EXECUTE, FakeActor.INSTANCE); + storage.insert(B, 10, Action.EXECUTE, ActorFixture.INSTANCE); storage.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); // Assert @@ -175,7 +175,7 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( ); assertThat(trackedResources1.getAllValues()) .hasSize(1) - .allMatch(t -> FakeActor.INSTANCE.getName().equals(t.getSourceName())); + .allMatch(t -> ActorFixture.INSTANCE.getName().equals(t.getSourceName())); final ArgumentCaptor trackedResources2 = ArgumentCaptor.forClass(TrackedResource.class); verify(watcher, times(1)).onChanged( @@ -185,7 +185,7 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( ); assertThat(trackedResources2.getAllValues()) .hasSize(1) - .allMatch(t -> FakeActor.INSTANCE.getName().equals(t.getSourceName())); + .allMatch(t -> ActorFixture.INSTANCE.getName().equals(t.getSourceName())); verify(watcher, times(1)).onChanged( eq(D), diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java index 39c114372..ae9fe2b33 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java @@ -12,8 +12,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java index 73200d251..bbe45befb 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java @@ -13,10 +13,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/InterfaceExportStateImpl.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/InterfaceExportStateImpl.java index 115fd22b2..ed872ff95 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/InterfaceExportStateImpl.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/InterfaceExportStateImpl.java @@ -13,9 +13,9 @@ import java.util.Map; import javax.annotation.Nullable; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE2; public class InterfaceExportStateImpl implements InterfaceExportState { private final Map requested = new HashMap<>(); diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/InterfaceNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/InterfaceNetworkNodeTest.java index 365c23c95..d6241274b 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/InterfaceNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/InterfaceNetworkNodeTest.java @@ -15,7 +15,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java index f9f4b7540..6ac9f30e4 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java @@ -14,10 +14,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java index 17e285368..f0283bc69 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java @@ -18,8 +18,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java index 2119d07e7..e3f07a268 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java @@ -21,7 +21,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java index 441fb5c0b..8bb892d8a 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java @@ -14,7 +14,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/ImporterNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/ImporterNetworkNodeTest.java index c37a31d61..ad776e235 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/ImporterNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/ImporterNetworkNodeTest.java @@ -23,11 +23,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -91,7 +91,7 @@ void shouldNotWorkOrExtractEnergyWithoutBeingActive( // Arrange storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(A, B) + final ImporterSourceImpl source = new ImporterSourceImpl(A, B) .add(A, 100) .add(B, 100); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); @@ -115,7 +115,7 @@ void testTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent s // Arrange storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(A, B, A) + final ImporterSourceImpl source = new ImporterSourceImpl(A, B, A) .add(A, 100) .add(B, 100); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); @@ -141,10 +141,10 @@ void shouldUseFirstSuccessfulTransferStrategy( // Arrange storage.addSource(new StorageImpl()); - final FakeImporterSource emptySource = new FakeImporterSource(); - final FakeImporterSource outdatedSource = new FakeImporterSource(C) + final ImporterSourceImpl emptySource = new ImporterSourceImpl(); + final ImporterSourceImpl outdatedSource = new ImporterSourceImpl(C) .add(C, 100); - final FakeImporterSource source = new FakeImporterSource(A, B, A) + final ImporterSourceImpl source = new ImporterSourceImpl(A, B, A) .add(A, 100) .add(B, 100); @@ -178,7 +178,7 @@ void shouldNotTransferIfThereIsNoSpaceInTheNetwork( storage.addSource(new LimitedStorageImpl(100)); storage.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); - final FakeImporterSource source = new FakeImporterSource(A, B) + final ImporterSourceImpl source = new ImporterSourceImpl(A, B) .add(A, 100) .add(B, 100); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); @@ -204,7 +204,7 @@ void testTransferDifferentResourceOverMultipleSlots( // Arrange storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(A, B, A, B) + final ImporterSourceImpl source = new ImporterSourceImpl(A, B, A, B) .add(A, 11) .add(B, 6); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); @@ -230,7 +230,7 @@ void testTransferSameResourceOverMultipleSlots( // Arrange storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(A, A, A, B) + final ImporterSourceImpl source = new ImporterSourceImpl(A, A, A, B) .add(A, 20) .add(B, 5); @@ -265,7 +265,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a } }); - final FakeImporterSource source = new FakeImporterSource(A, B, B, B) + final ImporterSourceImpl source = new ImporterSourceImpl(A, B, B, B) .add(A, 8) .add(B, 11); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); @@ -291,7 +291,7 @@ void testTransferWithoutAnyResourcesInSource( // Arrange storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(); + final ImporterSourceImpl source = new ImporterSourceImpl(); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); sut.setTransferStrategies(List.of(strategy)); @@ -311,7 +311,7 @@ void shouldRespectAllowlist(@InjectNetworkStorageComponent final StorageNetworkC storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(B, A) + final ImporterSourceImpl source = new ImporterSourceImpl(B, A) .add(B, 10) .add(A, 10); @@ -347,7 +347,7 @@ void shouldRespectAllowlistWithNormalizer( storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(B, A_ALTERNATIVE, A_ALTERNATIVE2) + final ImporterSourceImpl source = new ImporterSourceImpl(B, A_ALTERNATIVE, A_ALTERNATIVE2) .add(B, 10) .add(A_ALTERNATIVE, 1) .add(A_ALTERNATIVE2, 1); @@ -379,7 +379,7 @@ void shouldRespectAllowlistWithoutAlternative( storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(B) + final ImporterSourceImpl source = new ImporterSourceImpl(B) .add(B, 10); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); @@ -403,7 +403,7 @@ void shouldRespectEmptyAllowlist(@InjectNetworkStorageComponent final StorageNet storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(B, A) + final ImporterSourceImpl source = new ImporterSourceImpl(B, A) .add(B, 10) .add(A, 10); @@ -429,7 +429,7 @@ void shouldRespectBlocklist(@InjectNetworkStorageComponent final StorageNetworkC storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(A, B) + final ImporterSourceImpl source = new ImporterSourceImpl(A, B) .add(A, 10) .add(B, 10); @@ -459,7 +459,7 @@ void shouldRespectBlocklistWithoutAlternative( storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(A) + final ImporterSourceImpl source = new ImporterSourceImpl(A) .add(A, 10); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); @@ -483,7 +483,7 @@ void shouldRespectEmptyBlocklist(@InjectNetworkStorageComponent final StorageNet storage.addSource(new StorageImpl()); - final FakeImporterSource source = new FakeImporterSource(A, B) + final ImporterSourceImpl source = new ImporterSourceImpl(A, B) .add(A, 10) .add(B, 10); diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/FakeImporterSource.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/ImporterSourceImpl.java similarity index 85% rename from refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/FakeImporterSource.java rename to refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/ImporterSourceImpl.java index 4a2f4419b..b35fdd166 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/FakeImporterSource.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/ImporterSourceImpl.java @@ -12,15 +12,15 @@ import java.util.Iterator; import java.util.List; -public class FakeImporterSource implements ImporterSource { +class ImporterSourceImpl implements ImporterSource { private final List resources; private final StorageImpl storage = new StorageImpl(); - public FakeImporterSource(final ResourceKey... resources) { + ImporterSourceImpl(final ResourceKey... resources) { this.resources = Arrays.stream(resources).toList(); } - public FakeImporterSource add(final ResourceKey resource, final long amount) { + ImporterSourceImpl add(final ResourceKey resource, final long amount) { storage.insert(resource, amount, Action.EXECUTE, EmptyActor.INSTANCE); return this; } @@ -36,7 +36,7 @@ public long extract(final ResourceKey resource, final long amount, final Action return storage.extract(resource, Math.min(amount, 5), action, actor); } - public Collection getAll() { + Collection getAll() { return storage.getAll(); } diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/patternprovider/PatternProviderNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/patternprovider/PatternProviderNetworkNodeTest.java index 1c9412b48..a8c39a174 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/patternprovider/PatternProviderNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/patternprovider/PatternProviderNetworkNodeTest.java @@ -6,11 +6,12 @@ import com.refinedmods.refinedstorage.network.test.InjectNetworkAutocraftingComponent; import com.refinedmods.refinedstorage.network.test.NetworkTest; import com.refinedmods.refinedstorage.network.test.SetupNetwork; -import com.refinedmods.refinedstorage.network.test.fake.FakeResources; import com.refinedmods.refinedstorage.network.test.nodefactory.PatternProviderNetworkNodeFactory; import org.junit.jupiter.api.Test; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -26,7 +27,6 @@ void testDefaultState( @InjectNetworkAutocraftingComponent final AutocraftingNetworkComponent autocrafting ) { // Assert - assertThat(sut.getPatterns()).isEmpty(); assertThat(autocrafting.getOutputs()).isEmpty(); } @@ -35,12 +35,11 @@ void shouldSetPatternAndNotifyNetwork( @InjectNetworkAutocraftingComponent final AutocraftingNetworkComponent autocrafting ) { // Act - final SimplePattern pattern = new SimplePattern(FakeResources.A); + final SimplePattern pattern = new SimplePattern(A); sut.setPattern(0, pattern); // Assert - assertThat(sut.getPatterns()).containsExactly(pattern); - assertThat(autocrafting.getOutputs()).containsExactly(FakeResources.A); + assertThat(autocrafting.getOutputs()).containsExactly(A); } @Test @@ -48,14 +47,13 @@ void shouldRemovePatternAndNotifyNetwork( @InjectNetworkAutocraftingComponent final AutocraftingNetworkComponent autocrafting ) { // Arrange - final SimplePattern pattern = new SimplePattern(FakeResources.A); + final SimplePattern pattern = new SimplePattern(A); sut.setPattern(0, pattern); // Act sut.setPattern(0, null); // Assert - assertThat(sut.getPatterns()).isEmpty(); assertThat(autocrafting.getOutputs()).isEmpty(); } @@ -64,16 +62,15 @@ void shouldReplacePatternAndNotifyNetwork( @InjectNetworkAutocraftingComponent final AutocraftingNetworkComponent autocrafting ) { // Arrange - final SimplePattern pattern = new SimplePattern(FakeResources.A); + final SimplePattern pattern = new SimplePattern(A); sut.setPattern(0, pattern); // Act - final SimplePattern replacedPattern = new SimplePattern(FakeResources.B); + final SimplePattern replacedPattern = new SimplePattern(B); sut.setPattern(0, replacedPattern); // Assert - assertThat(sut.getPatterns()).containsExactly(replacedPattern); - assertThat(autocrafting.getOutputs()).containsExactly(FakeResources.B); + assertThat(autocrafting.getOutputs()).containsExactly(B); } @Test @@ -81,14 +78,13 @@ void shouldRemovePatternsFromNetworkWhenInactive( @InjectNetworkAutocraftingComponent final AutocraftingNetworkComponent autocrafting ) { // Arrange - final SimplePattern pattern = new SimplePattern(FakeResources.A); + final SimplePattern pattern = new SimplePattern(A); sut.setPattern(0, pattern); // Act sut.setActive(false); // Assert - assertThat(sut.getPatterns()).containsExactly(pattern); assertThat(autocrafting.getOutputs()).isEmpty(); } @@ -97,7 +93,7 @@ void shouldAddPatternsFromNetworkWhenActive( @InjectNetworkAutocraftingComponent final AutocraftingNetworkComponent autocrafting ) { // Arrange - final SimplePattern pattern = new SimplePattern(FakeResources.A); + final SimplePattern pattern = new SimplePattern(A); sut.setPattern(0, pattern); sut.setActive(false); @@ -105,7 +101,6 @@ void shouldAddPatternsFromNetworkWhenActive( sut.setActive(true); // Assert - assertThat(sut.getPatterns()).containsExactly(pattern); - assertThat(autocrafting.getOutputs()).containsExactly(FakeResources.A); + assertThat(autocrafting.getOutputs()).containsExactly(A); } } diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayAutocraftingNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayAutocraftingNetworkNodeTest.java new file mode 100644 index 000000000..0aebeaab4 --- /dev/null +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayAutocraftingNetworkNodeTest.java @@ -0,0 +1,325 @@ +package com.refinedmods.refinedstorage.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; +import com.refinedmods.refinedstorage.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage.network.test.AddNetworkNode; +import com.refinedmods.refinedstorage.network.test.InjectNetwork; +import com.refinedmods.refinedstorage.network.test.InjectNetworkAutocraftingComponent; +import com.refinedmods.refinedstorage.network.test.NetworkTest; +import com.refinedmods.refinedstorage.network.test.SetupNetwork; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static com.refinedmods.refinedstorage.api.network.impl.node.relay.RelayNetworkNodeTest.addPattern; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.D; +import static com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; +import static org.assertj.core.api.Assertions.assertThat; + +@NetworkTest +@SetupNetwork(id = "input") +@SetupNetwork(id = "output", setupEnergy = false) +class RelayAutocraftingNetworkNodeTest { + @SuppressWarnings("DefaultAnnotationParam") + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ACTIVE, boolValue = false) + }, networkId = "input") + private RelayInputNetworkNode input; + + @AddNetworkNode(networkId = "output") + private RelayOutputNetworkNode output; + + @Test + void shouldPassAutocraftingComponent( + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addPattern(inputAutocrafting, A); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.AUTOCRAFTING)); + + final var removeB = addPattern(inputAutocrafting, B); + removeB.run(); + + addPattern(inputAutocrafting, C); + + // Assert + assertThat(inputAutocrafting.getOutputs()).containsExactlyInAnyOrder(A, C); + assertThat(outputAutocrafting.getOutputs()).containsExactlyInAnyOrder(A, C); + assertThat(input.hasComponentType(RelayComponentType.AUTOCRAFTING)).isTrue(); + } + + @Test + void shouldRemovePatternsWhenNetworkIsRemoved( + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addPattern(inputAutocrafting, A); + + // Act + input.setNetwork(null); + + addPattern(inputAutocrafting, B); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, B); + assertThat(outputAutocrafting.getOutputs()).isEmpty(); + } + + @Test + @SetupNetwork(id = "input_alt") + void shouldNoLongerReceiveNotificationsFromOldInputNetwork( + @InjectNetwork("input") final Network inputNetwork, + @InjectNetwork("input_alt") final Network inputAlternativeNetwork, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetworkAutocraftingComponent(networkId = "input_alt") + final AutocraftingNetworkComponent inputAlternativeAutocrafting, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addPattern(inputAutocrafting, A); + input.setComponentTypes(Set.of(RelayComponentType.AUTOCRAFTING)); + + // Act + inputNetwork.removeContainer(() -> input); + inputAlternativeNetwork.addContainer(() -> input); + input.setNetwork(inputAlternativeNetwork); + + addPattern(inputAlternativeAutocrafting, B); + addPattern(inputAutocrafting, C); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, C); + assertThat(inputAlternativeAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactly(B); + assertThat(outputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(B); + } + + @Test + @SetupNetwork(id = "output_alt") + void shouldNotNotifyOldOutputNetworkWhenOutputNetworkHasChanged( + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetwork("output") final Network outputNetwork, + @InjectNetworkAutocraftingComponent(networkId = "output_alt") + final AutocraftingNetworkComponent outputAlternativeAutocrafting, + @InjectNetwork("output_alt") final Network outputAlternativeNetwork, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addPattern(inputAutocrafting, A); + input.setComponentTypes(Set.of(RelayComponentType.AUTOCRAFTING)); + + // Act + outputNetwork.removeContainer(() -> output); + outputAlternativeNetwork.addContainer(() -> output); + output.setNetwork(outputAlternativeNetwork); + + addPattern(inputAutocrafting, B); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, B); + assertThat(outputAlternativeAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, B); + assertThat(outputAutocrafting.getOutputs()).isEmpty(); + } + + @Test + @SetupNetwork(id = "output_alt") + void shouldAddPatternsToNewOutputNetworkIfTheOutputNetworkChanges( + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetwork("output") final Network outputNetwork, + @InjectNetworkAutocraftingComponent(networkId = "output_alt") + final AutocraftingNetworkComponent outputAlternativeAutocrafting, + @InjectNetwork("output_alt") final Network outputAlternativeNetwork, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addPattern(inputAutocrafting, A); + input.setComponentTypes(Set.of(RelayComponentType.AUTOCRAFTING)); + + // Act + outputNetwork.removeContainer(() -> output); + outputAlternativeNetwork.addContainer(() -> output); + output.setNetwork(outputAlternativeNetwork); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactly(A); + assertThat(outputAlternativeAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactly(A); + assertThat(outputAutocrafting.getOutputs()).isEmpty(); + } + + @Test + void shouldRespectAllowlistFilter( + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A, C)); + input.setFilterMode(FilterMode.ALLOW); + + addPattern(inputAutocrafting, A); + addPattern(inputAutocrafting, B); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.AUTOCRAFTING)); + + // This update should arrive. + addPattern(inputAutocrafting, C); + // This one shouldn't. + addPattern(inputAutocrafting, D); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, B, C, D); + assertThat(outputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, C); + } + + @Test + void shouldRespectFilterNormalizer( + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A, B)); + input.setFilterMode(FilterMode.ALLOW); + input.setFilterNormalizer(resource -> { + if (resource == A_ALTERNATIVE) { + return A; + } + return resource; + }); + + addPattern(inputAutocrafting, A); + addPattern(inputAutocrafting, C); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.AUTOCRAFTING)); + + // These updates should arrive. + addPattern(inputAutocrafting, A_ALTERNATIVE); + addPattern(inputAutocrafting, B); + // This one shouldn't. + addPattern(inputAutocrafting, D); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, B, C, A_ALTERNATIVE, D); + assertThat(outputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, A_ALTERNATIVE, B); + } + + @Test + void shouldUpdateOutputPatternsWhenFiltersAreChanged( + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A)); + input.setFilterMode(FilterMode.BLOCK); + + addPattern(inputAutocrafting, A); + addPattern(inputAutocrafting, B); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.AUTOCRAFTING)); + input.setFilters(Set.of(B)); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, B); + assertThat(outputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactly(A); + } + + @Test + void shouldUpdateOutputPatternsWhenFilterModeIsChanged( + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A)); + input.setFilterMode(FilterMode.BLOCK); + + addPattern(inputAutocrafting, A); + addPattern(inputAutocrafting, B); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.AUTOCRAFTING)); + input.setFilterMode(FilterMode.ALLOW); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(A, B); + assertThat(outputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator() + .containsExactly(A); + } + + @Test + @SetupNetwork(id = "cycle_input", energyStored = 1, energyCapacity = 2) + @SetupNetwork(id = "cycle_input_alt", energyStored = 3, energyCapacity = 4) + void shouldDetectCycles( + @InjectNetwork("cycle_input") final Network inputNetwork, + @InjectNetworkAutocraftingComponent(networkId = "cycle_input") + final AutocraftingNetworkComponent inputAutocrafting, + @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, + @InjectNetworkAutocraftingComponent(networkId = "cycle_input_alt") + final AutocraftingNetworkComponent inputAlternativeAutocrafting + ) { + // Act + final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); + cycleOutput.setAutocraftingDelegate(inputAlternativeAutocrafting); + cycleOutput.setNetwork(inputNetwork); + inputNetwork.addContainer(() -> cycleOutput); + + final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); + cycleOutputAlternative.setAutocraftingDelegate(inputAutocrafting); + cycleOutputAlternative.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + + addPattern(inputAutocrafting, A); + final Runnable removeB = addPattern(inputAutocrafting, B); + removeB.run(); + + // Assert + assertThat(inputAutocrafting.getOutputs()).usingRecursiveFieldByFieldElementComparator().containsExactly(A); + assertThat(inputAlternativeAutocrafting.getOutputs()).isEmpty(); + } +} diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java index 99c619d3e..15705f567 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java @@ -13,8 +13,8 @@ import com.refinedmods.refinedstorage.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage.network.test.NetworkTest; import com.refinedmods.refinedstorage.network.test.SetupNetwork; -import com.refinedmods.refinedstorage.network.test.fake.FakePermissions; -import com.refinedmods.refinedstorage.network.test.fake.FakeSecurityActors; +import com.refinedmods.refinedstorage.network.test.fixtures.PermissionFixtures; +import com.refinedmods.refinedstorage.network.test.fixtures.SecurityActorFixtures; import java.util.Set; @@ -22,7 +22,7 @@ import static com.refinedmods.refinedstorage.api.network.impl.node.relay.RelayNetworkNodeTest.addSecurityPolicy; import static com.refinedmods.refinedstorage.api.network.impl.node.relay.RelayNetworkNodeTest.addStorageSource; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; import static com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; import static org.assertj.core.api.Assertions.assertThat; @@ -52,7 +52,7 @@ void shouldPassEnergyComponent( input.setActive(true); input.setOutputNode(output); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); addStorageSource(inputStorage); final long originalStored = inputEnergy.getStored(); @@ -65,8 +65,8 @@ void shouldPassEnergyComponent( assertThat(extracted).isEqualTo(10); assertThat(outputEnergy.getCapacity()).isEqualTo(inputEnergy.getCapacity()); assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 10); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); assertThat(outputStorage.getAll()).isEmpty(); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); assertThat(input.hasComponentType(RelayComponentType.ENERGY)).isTrue(); diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java index 7a396353a..133a1c205 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java @@ -1,36 +1,44 @@ package com.refinedmods.refinedstorage.api.network.impl.node.relay; +import com.refinedmods.refinedstorage.api.autocrafting.Pattern; import com.refinedmods.refinedstorage.api.core.Action; import com.refinedmods.refinedstorage.api.network.Network; +import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage.api.network.impl.autocrafting.SimplePattern; +import com.refinedmods.refinedstorage.api.network.impl.node.patternprovider.PatternProviderNetworkNode; import com.refinedmods.refinedstorage.api.network.impl.security.SecurityDecisionProviderImpl; +import com.refinedmods.refinedstorage.api.network.node.container.NetworkNodeContainer; import com.refinedmods.refinedstorage.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy; import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; import com.refinedmods.refinedstorage.api.storage.AccessMode; import com.refinedmods.refinedstorage.api.storage.EmptyActor; import com.refinedmods.refinedstorage.api.storage.StorageImpl; import com.refinedmods.refinedstorage.network.test.AddNetworkNode; import com.refinedmods.refinedstorage.network.test.InjectNetwork; +import com.refinedmods.refinedstorage.network.test.InjectNetworkAutocraftingComponent; import com.refinedmods.refinedstorage.network.test.InjectNetworkEnergyComponent; import com.refinedmods.refinedstorage.network.test.InjectNetworkSecurityComponent; import com.refinedmods.refinedstorage.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage.network.test.NetworkTest; import com.refinedmods.refinedstorage.network.test.SetupNetwork; -import com.refinedmods.refinedstorage.network.test.fake.FakePermissions; -import com.refinedmods.refinedstorage.network.test.fake.FakeSecurityActors; +import com.refinedmods.refinedstorage.network.test.fixtures.PermissionFixtures; +import com.refinedmods.refinedstorage.network.test.fixtures.SecurityActorFixtures; import java.util.Set; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.MethodSource; import static com.refinedmods.refinedstorage.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode.activeSecurityDecisionProvider; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; import static com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; import static com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -64,15 +72,18 @@ void testInitialState() { void shouldNotPassComponentsIfOutputNodeIsNotSet( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, - @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting ) { // Arrange input.setActive(true); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); addStorageSource(inputStorage); + addPattern(inputAutocrafting, A); input.setAccessMode(AccessMode.INSERT_EXTRACT); input.setPriority(5); @@ -82,18 +93,21 @@ void shouldNotPassComponentsIfOutputNodeIsNotSet( input.setComponentTypes(Set.of( RelayComponentType.ENERGY, RelayComponentType.SECURITY, - RelayComponentType.STORAGE + RelayComponentType.STORAGE, + RelayComponentType.AUTOCRAFTING )); // Assert assertThat(outputEnergy.getCapacity()).isZero(); assertThat(outputEnergy.getStored()).isZero(); assertThat(outputEnergy.extract(1)).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); assertThat(outputStorage.getAll()).isEmpty(); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputAutocrafting.getOutputs()).isEmpty(); + assertThat(outputAutocrafting.getPatterns()).isEmpty(); assertThat(output.getEnergyUsage()).isZero(); } @@ -101,32 +115,38 @@ void shouldNotPassComponentsIfOutputNodeIsNotSet( void shouldNotPassComponentsIfInactive( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, - @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting ) { // Arrange input.setOutputNode(output); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); addStorageSource(inputStorage); + addPattern(inputAutocrafting, A); // Act input.setComponentTypes(Set.of( RelayComponentType.ENERGY, RelayComponentType.SECURITY, - RelayComponentType.STORAGE + RelayComponentType.STORAGE, + RelayComponentType.AUTOCRAFTING )); // Assert assertThat(outputEnergy.getCapacity()).isZero(); assertThat(outputEnergy.getStored()).isZero(); assertThat(outputEnergy.extract(1)).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); assertThat(outputStorage.getAll()).isEmpty(); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputAutocrafting.getOutputs()).isEmpty(); + assertThat(outputAutocrafting.getPatterns()).isEmpty(); assertThat(output.getEnergyUsage()).isZero(); } @@ -134,34 +154,40 @@ void shouldNotPassComponentsIfInactive( void shouldNotPassComponentsIfNoNetworkIsSet( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, - @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting ) { // Arrange input.setActive(true); input.setNetwork(null); input.setOutputNode(output); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); addStorageSource(inputStorage); + addPattern(inputAutocrafting, A); // Act input.setComponentTypes(Set.of( RelayComponentType.ENERGY, RelayComponentType.SECURITY, - RelayComponentType.STORAGE + RelayComponentType.STORAGE, + RelayComponentType.AUTOCRAFTING )); // Assert assertThat(outputEnergy.getCapacity()).isZero(); assertThat(outputEnergy.getStored()).isZero(); assertThat(outputEnergy.extract(1)).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); assertThat(outputStorage.getAll()).isEmpty(); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputAutocrafting.getOutputs()).isEmpty(); + assertThat(outputAutocrafting.getPatterns()).isEmpty(); assertThat(output.getEnergyUsage()).isZero(); } @@ -169,9 +195,11 @@ void shouldNotPassComponentsIfNoNetworkIsSet( void shouldResetComponentsIfBecomingInactive( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, - @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting ) { // Arrange input.setActive(true); @@ -179,11 +207,13 @@ void shouldResetComponentsIfBecomingInactive( input.setComponentTypes(Set.of( RelayComponentType.ENERGY, RelayComponentType.SECURITY, - RelayComponentType.STORAGE + RelayComponentType.STORAGE, + RelayComponentType.AUTOCRAFTING )); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); addStorageSource(inputStorage); + addPattern(inputAutocrafting, A); // Act input.setActive(false); @@ -192,11 +222,13 @@ void shouldResetComponentsIfBecomingInactive( assertThat(outputEnergy.getCapacity()).isZero(); assertThat(outputEnergy.getStored()).isZero(); assertThat(outputEnergy.extract(1)).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); assertThat(outputStorage.getAll()).isEmpty(); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputAutocrafting.getOutputs()).isEmpty(); + assertThat(outputAutocrafting.getPatterns()).isEmpty(); assertThat(output.getEnergyUsage()).isZero(); } @@ -204,9 +236,11 @@ void shouldResetComponentsIfBecomingInactive( void shouldResetComponentsIfNetworkIsRemoved( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, - @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting ) { // Arrange input.setActive(true); @@ -214,11 +248,13 @@ void shouldResetComponentsIfNetworkIsRemoved( input.setComponentTypes(Set.of( RelayComponentType.ENERGY, RelayComponentType.SECURITY, - RelayComponentType.STORAGE + RelayComponentType.STORAGE, + RelayComponentType.AUTOCRAFTING )); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); addStorageSource(inputStorage); + addPattern(inputAutocrafting, A); // Act input.setNetwork(null); @@ -227,11 +263,13 @@ void shouldResetComponentsIfNetworkIsRemoved( assertThat(outputEnergy.getCapacity()).isZero(); assertThat(outputEnergy.getStored()).isZero(); assertThat(outputEnergy.extract(1)).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); assertThat(outputStorage.getAll()).isEmpty(); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputAutocrafting.getOutputs()).isEmpty(); + assertThat(outputAutocrafting.getPatterns()).isEmpty(); assertThat(output.getEnergyUsage()).isZero(); } @@ -241,14 +279,18 @@ void shouldResetComponentsIfNetworkIsChanged( @InjectNetwork("input") final Network inputNetwork, @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, @InjectNetwork("input_alt") final Network inputAlternativeNetwork, @InjectNetworkEnergyComponent(networkId = "input_alt") final EnergyNetworkComponent inputAlternativeEnergy, @InjectNetworkSecurityComponent(networkId = "input_alt") final SecurityNetworkComponent inputAlternativeSecurity, @InjectNetworkStorageComponent(networkId = "input_alt") final StorageNetworkComponent inputAlternativeStorage, + @InjectNetworkAutocraftingComponent(networkId = "input_alt") + final AutocraftingNetworkComponent inputAlternativeAutocrafting, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, - @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting ) { // Arrange input.setActive(true); @@ -256,7 +298,8 @@ void shouldResetComponentsIfNetworkIsChanged( input.setComponentTypes(Set.of( RelayComponentType.ENERGY, RelayComponentType.SECURITY, - RelayComponentType.STORAGE + RelayComponentType.STORAGE, + RelayComponentType.AUTOCRAFTING )); inputStorage.addSource(new StorageImpl()); @@ -267,8 +310,11 @@ void shouldResetComponentsIfNetworkIsChanged( inputAlternativeStorage.addSource(new StorageImpl()); inputAlternativeStorage.insert(A, 33, Action.EXECUTE, EmptyActor.INSTANCE); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); - addSecurityPolicy(inputAlternativeSecurity, FakePermissions.OTHER2); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); + addSecurityPolicy(inputAlternativeSecurity, PermissionFixtures.OTHER2); + + addPattern(inputAutocrafting, A); + addPattern(inputAlternativeAutocrafting, B); // Act inputNetwork.removeContainer(() -> input); @@ -288,14 +334,16 @@ void shouldResetComponentsIfNetworkIsChanged( assertThat(outputEnergy.getCapacity()).isEqualTo(inputAlternativeEnergy.getCapacity()); assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 1); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isTrue(); assertThat(outputStorage.getStored()).isEqualTo(33); assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 32), new ResourceAmount(C, 1) ); + assertThat(outputAutocrafting.getOutputs()).containsExactly(B); + assertThat(outputAutocrafting.getPatterns()).allMatch(p -> p.getOutputResources().contains(B)); assertThat(inputAlternativeStorage.getAll()).usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder(new ResourceAmount(A, 32), new ResourceAmount(C, 1)); assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator() @@ -308,20 +356,24 @@ void shouldResetComponentsWhenComponentTypeIsEnabled( @InjectNetworkEnergyComponent(networkId = "input") final EnergyNetworkComponent inputEnergy, @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, - @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting ) { // Arrange input.setActive(true); input.setOutputNode(output); input.setComponentTypes(Set.of( RelayComponentType.SECURITY, - RelayComponentType.STORAGE + RelayComponentType.STORAGE, + RelayComponentType.AUTOCRAFTING )); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); addStorageSource(inputStorage); + addPattern(inputAutocrafting, A); // Act final long originalStored = inputEnergy.getStored(); @@ -332,13 +384,15 @@ void shouldResetComponentsWhenComponentTypeIsEnabled( assertThat(outputEnergy.getCapacity()).isEqualTo(inputEnergy.getCapacity()); assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 10); assertThat(extracted).isEqualTo(10); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isTrue(); assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(outputAutocrafting.getOutputs()).containsExactly(A); + assertThat(outputAutocrafting.getPatterns()).allMatch(p -> p.getOutputResources().contains(A)); assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); } @@ -346,20 +400,24 @@ void shouldResetComponentsWhenComponentTypeIsEnabled( void shouldResetComponentsWhenComponentTypeIsDisabled( @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkAutocraftingComponent(networkId = "input") final AutocraftingNetworkComponent inputAutocrafting, @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, - @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage, + @InjectNetworkAutocraftingComponent(networkId = "output") final AutocraftingNetworkComponent outputAutocrafting ) { // Arrange input.setActive(true); input.setOutputNode(output); input.setComponentTypes(Set.of( RelayComponentType.SECURITY, - RelayComponentType.STORAGE + RelayComponentType.STORAGE, + RelayComponentType.AUTOCRAFTING )); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); addStorageSource(inputStorage); + addPattern(inputAutocrafting, A); // Act input.updateComponentType(RelayComponentType.ENERGY, false); @@ -369,19 +427,25 @@ void shouldResetComponentsWhenComponentTypeIsDisabled( assertThat(outputEnergy.getCapacity()).isZero(); assertThat(outputEnergy.getStored()).isZero(); assertThat(extracted).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isTrue(); assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(outputAutocrafting.getOutputs()).containsExactly(A); + assertThat(outputAutocrafting.getPatterns()).allMatch(p -> p.getOutputResources().contains(A)); assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); } + private static Stream> provideComponentTypes() { + return RelayComponentType.ALL.stream(); + } + @ParameterizedTest - @EnumSource(RelayComponentType.class) - void shouldUseEnergyWhenAtLeastOneComponentIsActive(final RelayComponentType type) { + @MethodSource("provideComponentTypes") + void shouldUseEnergyWhenAtLeastOneComponentIsActive(final RelayComponentType type) { // Arrange input.setActive(true); input.setOutputNode(output); @@ -393,9 +457,9 @@ void shouldUseEnergyWhenAtLeastOneComponentIsActive(final RelayComponentType typ assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); } - static void addSecurityPolicy(final SecurityNetworkComponent security, final FakePermissions permission) { + static void addSecurityPolicy(final SecurityNetworkComponent security, final PermissionFixtures permission) { security.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(permission)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(permission)) )); } @@ -403,4 +467,13 @@ static void addStorageSource(final StorageNetworkComponent storage) { storage.addSource(new StorageImpl()); storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); } + + static Runnable addPattern(final AutocraftingNetworkComponent component, final ResourceKey output) { + final Pattern pattern = new SimplePattern(output); + final PatternProviderNetworkNode patternProvider = new PatternProviderNetworkNode(0, 1); + patternProvider.setPattern(0, pattern); + final NetworkNodeContainer container = () -> patternProvider; + component.onContainerAdded(container); + return () -> component.onContainerRemoved(container); + } } diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java index c07572fb3..52c69c6d4 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java @@ -15,8 +15,8 @@ import com.refinedmods.refinedstorage.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage.network.test.NetworkTest; import com.refinedmods.refinedstorage.network.test.SetupNetwork; -import com.refinedmods.refinedstorage.network.test.fake.FakePermissions; -import com.refinedmods.refinedstorage.network.test.fake.FakeSecurityActors; +import com.refinedmods.refinedstorage.network.test.fixtures.PermissionFixtures; +import com.refinedmods.refinedstorage.network.test.fixtures.SecurityActorFixtures; import java.util.Set; @@ -24,7 +24,7 @@ import static com.refinedmods.refinedstorage.api.network.impl.node.relay.RelayNetworkNodeTest.addStorageSource; import static com.refinedmods.refinedstorage.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode.activeSecurityDecisionProvider; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; import static com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; import static org.assertj.core.api.Assertions.assertThat; @@ -55,8 +55,8 @@ void shouldPassSecurityComponent( inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) - .setPolicy(FakeSecurityActors.B, SecurityPolicy.of(FakePermissions.OTHER)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.ALLOW_BY_DEFAULT)) + .setPolicy(SecurityActorFixtures.B, SecurityPolicy.of(PermissionFixtures.OTHER)) )); addStorageSource(inputStorage); @@ -68,10 +68,10 @@ void shouldPassSecurityComponent( assertThat(outputEnergy.getCapacity()).isZero(); assertThat(outputEnergy.getStored()).isZero(); assertThat(outputEnergy.extract(1)).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isFalse(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.B)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.B)).isTrue(); assertThat(outputStorage.getAll()).isEmpty(); assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); @@ -90,7 +90,7 @@ void shouldNotActAsSecurityDecisionProviderIfOutputIsDisabled( input.setOutputNode(output); inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER)) )); input.setComponentTypes(Set.of(RelayComponentType.SECURITY)); @@ -99,8 +99,8 @@ void shouldNotActAsSecurityDecisionProviderIfOutputIsDisabled( output.setActive(false); // Assert - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); } @Test @@ -113,15 +113,15 @@ void shouldNotActAsSecurityDecisionProviderIfSecurityIsNotPassed( input.setOutputNode(output); inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER)) )); // Act input.setComponentTypes(Set.of()); // Assert - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); } @Test @@ -137,12 +137,12 @@ void shouldDetectSecurityCycles( // Arrange inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER)) )); inputAlternativeSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER2)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER2)) )); // Act @@ -157,10 +157,10 @@ void shouldDetectSecurityCycles( inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); // Assert - assertThat(inputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); - assertThat(inputSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + assertThat(inputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isTrue(); + assertThat(inputSecurity.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isFalse(); - assertThat(inputAlternativeSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(inputAlternativeSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); + assertThat(inputAlternativeSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); + assertThat(inputAlternativeSecurity.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isTrue(); } } diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java index f7f095ff8..538df1919 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java @@ -20,18 +20,18 @@ import com.refinedmods.refinedstorage.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage.network.test.NetworkTest; import com.refinedmods.refinedstorage.network.test.SetupNetwork; -import com.refinedmods.refinedstorage.network.test.fake.FakePermissions; -import com.refinedmods.refinedstorage.network.test.fake.FakeSecurityActors; +import com.refinedmods.refinedstorage.network.test.fixtures.PermissionFixtures; +import com.refinedmods.refinedstorage.network.test.fixtures.SecurityActorFixtures; import java.util.Set; import org.junit.jupiter.api.Test; import static com.refinedmods.refinedstorage.api.network.impl.node.relay.RelayNetworkNodeTest.addSecurityPolicy; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; import static com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; import static org.assertj.core.api.Assertions.assertThat; @@ -60,7 +60,7 @@ void shouldPassStorageComponent( input.setActive(true); input.setOutputNode(output); - addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputSecurity, PermissionFixtures.OTHER); inputStorage.addSource(new StorageImpl()); inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); @@ -74,8 +74,8 @@ void shouldPassStorageComponent( // Assert assertThat(outputEnergy.getCapacity()).isZero(); assertThat(outputEnergy.getStored()).isZero(); - assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(outputSecurity.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 10), @@ -591,7 +591,7 @@ void shouldUpdateOutputStorageWhenFilterModeIsChanged( @Test @SetupNetwork(id = "cycle_input", energyStored = 1, energyCapacity = 2) @SetupNetwork(id = "cycle_input_alt", energyStored = 3, energyCapacity = 4) - void shouldDetectStorageCycles( + void shouldDetectCycles( @InjectNetwork("cycle_input") final Network inputNetwork, @InjectNetworkStorageComponent(networkId = "cycle_input") final StorageNetworkComponent inputStorage, @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/PriorityStorageNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/PriorityStorageNetworkNodeTest.java index b2ec65662..63ddf20b3 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/PriorityStorageNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/PriorityStorageNetworkNodeTest.java @@ -15,7 +15,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/StorageNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/StorageNetworkNodeTest.java index 7e21a3da7..f89ea30f5 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/StorageNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/StorageNetworkNodeTest.java @@ -19,7 +19,7 @@ import com.refinedmods.refinedstorage.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage.network.test.NetworkTest; import com.refinedmods.refinedstorage.network.test.SetupNetwork; -import com.refinedmods.refinedstorage.network.test.fake.FakeActor; +import com.refinedmods.refinedstorage.network.test.fixtures.ActorFixture; import java.util.Collection; import java.util.HashSet; @@ -31,12 +31,12 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B_ALTERNATIVE; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; import static com.refinedmods.refinedstorage.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static com.refinedmods.refinedstorage.network.test.nodefactory.StorageNetworkNodeFactory.PROPERTY_ENERGY_USAGE_PER_STORAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -666,11 +666,11 @@ void shouldTrackChanges(@InjectNetworkStorageComponent final StorageNetworkCompo initializeAndActivate(); // Act - final long inserted = networkStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); + final long inserted = networkStorage.insert(A, 10, Action.EXECUTE, ActorFixture.INSTANCE); // Assert assertThat(inserted).isEqualTo(10); - assertThat(networkStorage.findTrackedResourceByActorType(A, FakeActor.class)).isNotEmpty(); + assertThat(networkStorage.findTrackedResourceByActorType(A, ActorFixture.class)).isNotEmpty(); } @Test @@ -686,7 +686,7 @@ void shouldNotifyListenerWhenStateChanges( initializeAndActivate(); // Act - networkStorage.insert(A, 75, Action.EXECUTE, FakeActor.INSTANCE); + networkStorage.insert(A, 75, Action.EXECUTE, ActorFixture.INSTANCE); // Assert verify(listener, times(1)).onStorageStateChanged(); diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storagetransfer/StorageTransferNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storagetransfer/StorageTransferNetworkNodeTest.java index 782b0d833..67aef880c 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storagetransfer/StorageTransferNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storagetransfer/StorageTransferNetworkNodeTest.java @@ -24,11 +24,11 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.C; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.D; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.C; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.D; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/security/SecurityNetworkComponentImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/security/SecurityNetworkComponentImplTest.java index 9a1ffdb86..933726352 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/security/SecurityNetworkComponentImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/security/SecurityNetworkComponentImplTest.java @@ -3,8 +3,8 @@ import com.refinedmods.refinedstorage.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode; import com.refinedmods.refinedstorage.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy; -import com.refinedmods.refinedstorage.network.test.fake.FakePermissions; -import com.refinedmods.refinedstorage.network.test.fake.FakeSecurityActors; +import com.refinedmods.refinedstorage.network.test.fixtures.PermissionFixtures; +import com.refinedmods.refinedstorage.network.test.fixtures.SecurityActorFixtures; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -19,7 +19,7 @@ class SecurityNetworkComponentImplTest { @BeforeEach void setUp() { - sut = new SecurityNetworkComponentImpl(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)); + sut = new SecurityNetworkComponentImpl(SecurityPolicy.of(PermissionFixtures.ALLOW_BY_DEFAULT)); securityDecisionProvider = new SecurityDecisionProviderImpl(); node = activeSecurityDecisionProvider(securityDecisionProvider); } @@ -27,13 +27,13 @@ void setUp() { @Test void shouldUseDefaultPolicyIfNoSecurityDecisionProvidersArePresent() { // Act & assert - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.B)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.B)).isFalse(); } @Test @@ -42,138 +42,138 @@ void shouldDenyAllIfAtLeastOneSecurityDecisionProviderIsPresent() { sut.onContainerAdded(() -> node); // Act & assert - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.B)).isFalse(); } @Test void shouldUseDefaultPolicyIfAllSecurityDecisionProvidersAreInactive() { // Arrange sut.onContainerAdded(() -> new SecurityDecisionProviderProxyNetworkNode(0, new SecurityDecisionProviderImpl() - .setDefaultPolicy(SecurityPolicy.of(FakePermissions.OTHER)))); + .setDefaultPolicy(SecurityPolicy.of(PermissionFixtures.OTHER)))); // Act & assert - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.B)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.B)).isFalse(); } @Test void shouldAllowOrDeny() { // Arrange - securityDecisionProvider.setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)); + securityDecisionProvider.setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER)); sut.onContainerAdded(() -> node); // Act & assert - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.B)).isFalse(); } @Test void shouldOnlyAllowIfAllSecurityDecisionProvidersAllow() { // Arrange sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER)) )); sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER2)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER2)) )); sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.B, SecurityPolicy.of(FakePermissions.OTHER)) + .setPolicy(SecurityActorFixtures.B, SecurityPolicy.of(PermissionFixtures.OTHER)) )); sut.onContainerAdded(() -> new SecurityDecisionProviderProxyNetworkNode(0, new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) - .setDefaultPolicy(SecurityPolicy.of(FakePermissions.OTHER, FakePermissions.OTHER2)))); + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.ALLOW_BY_DEFAULT)) + .setDefaultPolicy(SecurityPolicy.of(PermissionFixtures.OTHER, PermissionFixtures.OTHER2)))); // Act & assert - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.B)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.C)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.C)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.C)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.C)).isFalse(); } @Test void shouldUseDefaultPolicyOfSecurityDecisionProviderIfAllProvidersPassDecision() { // Arrange sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) - .setDefaultPolicy(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER)) + .setDefaultPolicy(SecurityPolicy.of(PermissionFixtures.ALLOW_BY_DEFAULT)) )); sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) - .setDefaultPolicy(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT, FakePermissions.OTHER2)) + .setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER)) + .setDefaultPolicy(SecurityPolicy.of(PermissionFixtures.ALLOW_BY_DEFAULT, PermissionFixtures.OTHER2)) )); sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setPolicy(FakeSecurityActors.C, SecurityPolicy.of(FakePermissions.OTHER)) + .setPolicy(SecurityActorFixtures.C, SecurityPolicy.of(PermissionFixtures.OTHER)) )); // Act & assert - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.B)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.B)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.B)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.C)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.C)).isTrue(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.C)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.C)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.C)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.C)).isFalse(); } @Test void shouldRemoveContainer() { // Arrange sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setDefaultPolicy(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) + .setDefaultPolicy(SecurityPolicy.of(PermissionFixtures.ALLOW_BY_DEFAULT)) )); final var removedNode = activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() - .setDefaultPolicy(SecurityPolicy.of(FakePermissions.OTHER))); + .setDefaultPolicy(SecurityPolicy.of(PermissionFixtures.OTHER))); sut.onContainerAdded(() -> removedNode); // Act sut.onContainerRemoved(() -> removedNode); // Assert - assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.ALLOW_BY_DEFAULT, SecurityActorFixtures.A)).isTrue(); } @Test void shouldClearPolicies() { // Arrange sut.onContainerAdded(() -> node); - securityDecisionProvider.setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)); - securityDecisionProvider.setDefaultPolicy(SecurityPolicy.of(FakePermissions.OTHER2)); + securityDecisionProvider.setPolicy(SecurityActorFixtures.A, SecurityPolicy.of(PermissionFixtures.OTHER)); + securityDecisionProvider.setDefaultPolicy(SecurityPolicy.of(PermissionFixtures.OTHER2)); // Act securityDecisionProvider.clearPolicies(); // Assert - assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER, SecurityActorFixtures.A)).isFalse(); + assertThat(sut.isAllowed(PermissionFixtures.OTHER2, SecurityActorFixtures.A)).isTrue(); } } diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/storage/StorageNetworkComponentImplTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/storage/StorageNetworkComponentImplTest.java index 4e5784a06..60ac5c247 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/storage/StorageNetworkComponentImplTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/storage/StorageNetworkComponentImplTest.java @@ -12,7 +12,7 @@ import com.refinedmods.refinedstorage.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage.api.storage.tracked.TrackedStorageImpl; -import com.refinedmods.refinedstorage.network.test.NetworkTestFixtures; +import com.refinedmods.refinedstorage.network.test.fixtures.NetworkTestFixtures; import java.util.Collection; import java.util.HashSet; @@ -22,8 +22,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.A; -import static com.refinedmods.refinedstorage.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.A; +import static com.refinedmods.refinedstorage.network.test.fixtures.ResourceFixtures.B; import static org.assertj.core.api.Assertions.assertThat; class StorageNetworkComponentImplTest { diff --git a/refinedstorage-resource-api/src/test/java/com/refinedmods/refinedstorage/api/resource/list/listenable/ListenableResourceListTest.java b/refinedstorage-resource-api/src/test/java/com/refinedmods/refinedstorage/api/resource/list/listenable/ListenableResourceListTest.java index 2f4094cae..ab930fa0e 100644 --- a/refinedstorage-resource-api/src/test/java/com/refinedmods/refinedstorage/api/resource/list/listenable/ListenableResourceListTest.java +++ b/refinedstorage-resource-api/src/test/java/com/refinedmods/refinedstorage/api/resource/list/listenable/ListenableResourceListTest.java @@ -14,13 +14,13 @@ import static org.assertj.core.api.Assertions.assertThat; class ListenableResourceListTest { - private FakeResourceListListener listener; + private ResourceListListenerStub listener; private MutableResourceListImpl list; private ListenableResourceList sut; @BeforeEach void setUp() { - listener = new FakeResourceListListener(); + listener = new ResourceListListenerStub(); list = MutableResourceListImpl.create(); sut = new ListenableResourceList(list); } @@ -129,7 +129,7 @@ void shouldBeAbleToRemoveListener() { assertThat(listener.changes).hasSize(1); } - private static class FakeResourceListListener implements ResourceListListener { + private static class ResourceListListenerStub implements ResourceListListener { private final List changes = new ArrayList<>(); @Override diff --git a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/ActorFixtures.java b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/ActorFixtures.java new file mode 100644 index 000000000..420c04a91 --- /dev/null +++ b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/ActorFixtures.java @@ -0,0 +1,24 @@ +package com.refinedmods.refinedstorage.api.storage; + +public final class ActorFixtures { + private ActorFixtures() { + } + + public static final class ActorFixture1 implements Actor { + public static final Actor INSTANCE = new ActorFixture1(); + + @Override + public String getName() { + return "Source1"; + } + } + + public static final class ActorFixture2 implements Actor { + public static final Actor INSTANCE = new ActorFixture2(); + + @Override + public String getName() { + return "Source2"; + } + } +} diff --git a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/FakeActors.java b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/FakeActors.java deleted file mode 100644 index 914cde273..000000000 --- a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/FakeActors.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.refinedmods.refinedstorage.api.storage; - -public final class FakeActors { - private FakeActors() { - } - - public static final class FakeActor1 implements Actor { - public static final Actor INSTANCE = new FakeActor1(); - - @Override - public String getName() { - return "Source1"; - } - } - - public static final class FakeActor2 implements Actor { - public static final Actor INSTANCE = new FakeActor2(); - - @Override - public String getName() { - return "Source2"; - } - } -} diff --git a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImplTest.java b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImplTest.java index a3875a85e..638b30d27 100644 --- a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImplTest.java +++ b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImplTest.java @@ -3,8 +3,8 @@ import com.refinedmods.refinedstorage.api.core.Action; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; import com.refinedmods.refinedstorage.api.resource.list.MutableResourceListImpl; +import com.refinedmods.refinedstorage.api.storage.ActorFixtures; import com.refinedmods.refinedstorage.api.storage.EmptyActor; -import com.refinedmods.refinedstorage.api.storage.FakeActors; import com.refinedmods.refinedstorage.api.storage.Storage; import com.refinedmods.refinedstorage.api.storage.StorageImpl; import com.refinedmods.refinedstorage.api.storage.limited.LimitedStorageImpl; @@ -214,24 +214,24 @@ void shouldFindMostRecentChange() { final TrackedStorage b = new TrackedStorageImpl(new StorageImpl(), clock::get); // Test if it uses the latest across 2 different storages - a.insert(A, 1, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + a.insert(A, 1, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(1L); - b.insert(A, 1, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + b.insert(A, 1, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); // Test if it differentiates between source types properly clock.set(2L); - b.insert(B, 1, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + b.insert(B, 1, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(3L); - b.insert(B, 1, Action.EXECUTE, FakeActors.FakeActor2.INSTANCE); + b.insert(B, 1, Action.EXECUTE, ActorFixtures.ActorFixture2.INSTANCE); sut.addSource(a); sut.addSource(b); // Act - final var oneOne = sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); - final var oneTwo = sut.findTrackedResourceByActorType(A, FakeActors.FakeActor2.class); - final var twoOne = sut.findTrackedResourceByActorType(B, FakeActors.FakeActor1.class); - final var twoTwo = sut.findTrackedResourceByActorType(B, FakeActors.FakeActor2.class); + final var oneOne = sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); + final var oneTwo = sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture2.class); + final var twoOne = sut.findTrackedResourceByActorType(B, ActorFixtures.ActorFixture1.class); + final var twoTwo = sut.findTrackedResourceByActorType(B, ActorFixtures.ActorFixture2.class); // Assert assertThat(oneOne).get().usingRecursiveComparison().isEqualTo(new TrackedResource("Source1", 1L)); diff --git a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/tracked/TrackedStorageImplTest.java b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/tracked/TrackedStorageImplTest.java index c876a5500..a4e88bcc5 100644 --- a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/tracked/TrackedStorageImplTest.java +++ b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/tracked/TrackedStorageImplTest.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage.api.storage.tracked; import com.refinedmods.refinedstorage.api.core.Action; +import com.refinedmods.refinedstorage.api.storage.ActorFixtures; import com.refinedmods.refinedstorage.api.storage.EmptyActor; -import com.refinedmods.refinedstorage.api.storage.FakeActors; import com.refinedmods.refinedstorage.api.storage.limited.LimitedStorageImpl; import java.util.Optional; @@ -73,15 +73,15 @@ class InitialTrackTest { @Test void shouldNotFindUntrackedResource() { // Act - sut.insert(B, 100, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.insert(B, 100, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); // Assert final Optional resourceA1 = sut.findTrackedResourceByActorType(A, EmptyActor.class); final Optional resourceA2 = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); final Optional resourceB1 = sut.findTrackedResourceByActorType(B, EmptyActor.class); final Optional resourceB2 = - sut.findTrackedResourceByActorType(B, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(B, ActorFixtures.ActorFixture1.class); assertThat(resourceA1).isEmpty(); assertThat(resourceA2).isEmpty(); @@ -96,13 +96,13 @@ void shouldTrackResourceByInserting(final Action action) { clock.set(1L); // Act - final long inserted = sut.insert(A, 100, action, FakeActors.FakeActor1.INSTANCE); + final long inserted = sut.insert(A, 100, action, ActorFixtures.ActorFixture1.INSTANCE); // Assert assertThat(inserted).isEqualTo(100); final Optional trackedResource = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); if (action == Action.EXECUTE) { assertThat(trackedResource).isPresent(); @@ -124,13 +124,13 @@ void shouldNotTrackResourceByInsertingToAlreadyFullStorage(final Action action) backed.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); // Act - final long inserted = sut.insert(A, 1, action, FakeActors.FakeActor1.INSTANCE); + final long inserted = sut.insert(A, 1, action, ActorFixtures.ActorFixture1.INSTANCE); // Assert assertThat(inserted).isZero(); final Optional resource = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); assertThat(resource).isEmpty(); } @@ -142,13 +142,13 @@ void shouldTrackResourceByExtracting(final Action action) { backed.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); // Act - final long extracted = sut.extract(A, 10, action, FakeActors.FakeActor1.INSTANCE); + final long extracted = sut.extract(A, 10, action, ActorFixtures.ActorFixture1.INSTANCE); // Assert assertThat(extracted).isEqualTo(10); final Optional trackedResource = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); if (action == Action.EXECUTE) { assertThat(trackedResource).get().usingRecursiveComparison() @@ -162,13 +162,13 @@ void shouldTrackResourceByExtracting(final Action action) { @EnumSource(Action.class) void shouldNotTrackResourceByExtractingNothing(final Action action) { // Act - final long extracted = sut.extract(A, 1, action, FakeActors.FakeActor1.INSTANCE); + final long extracted = sut.extract(A, 1, action, ActorFixtures.ActorFixture1.INSTANCE); // Assert assertThat(extracted).isZero(); final Optional trackedResource = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); assertThat(trackedResource).isEmpty(); } @@ -176,15 +176,15 @@ void shouldNotTrackResourceByExtractingNothing(final Action action) { @SuppressWarnings("AssertBetweenInconvertibleTypes") void shouldTrackMultipleResources() { // Act - sut.insert(A, 1, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.insert(A, 1, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(1); - sut.insert(B, 1, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.insert(B, 1, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); // Assert final Optional resourceA = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); final Optional resourceB = - sut.findTrackedResourceByActorType(B, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(B, ActorFixtures.ActorFixture1.class); assertThat(resourceA).get().usingRecursiveComparison().isEqualTo(new TrackedResource("Source1", 0)); assertThat(resourceB).get().usingRecursiveComparison().isEqualTo(new TrackedResource("Source1", 1)); @@ -198,13 +198,13 @@ class UpdateTrackedResourceTest { @SuppressWarnings("AssertBetweenInconvertibleTypes") void shouldUpdateTrackedResourceByInserting(final Action action) { // Act - sut.insert(A, 50, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.insert(A, 50, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(10); - sut.insert(A, 60, action, FakeActors.FakeActor1.INSTANCE); + sut.insert(A, 60, action, ActorFixtures.ActorFixture1.INSTANCE); // Assert final Optional trackedResource = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); if (action == Action.EXECUTE) { assertThat(trackedResource).get().usingRecursiveComparison() @@ -220,13 +220,13 @@ void shouldUpdateTrackedResourceByInserting(final Action action) { @SuppressWarnings("AssertBetweenInconvertibleTypes") void shouldNotUpdateTrackedResourceByInsertingToAnAlreadyFullStorage(final Action action) { // Act - sut.insert(A, 100, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.insert(A, 100, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(10); - sut.insert(A, 1, action, FakeActors.FakeActor1.INSTANCE); + sut.insert(A, 1, action, ActorFixtures.ActorFixture1.INSTANCE); // Assert final Optional trackedResource = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); assertThat(trackedResource).get().usingRecursiveComparison().isEqualTo(new TrackedResource("Source1", 0)); } @@ -238,13 +238,13 @@ void shouldUpdateTrackedResourceByExtracting(final Action action) { backed.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.extract(A, 50, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.extract(A, 50, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(10); - sut.extract(A, 60, action, FakeActors.FakeActor1.INSTANCE); + sut.extract(A, 60, action, ActorFixtures.ActorFixture1.INSTANCE); // Assert final Optional trackedResource = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); if (action == Action.EXECUTE) { assertThat(trackedResource).get().usingRecursiveComparison() @@ -263,13 +263,13 @@ void shouldNotUpdateTrackedResourceByExtractingNothing(final Action action) { backed.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.extract(A, 100, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.extract(A, 100, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(10); - sut.extract(A, 1, action, FakeActors.FakeActor1.INSTANCE); + sut.extract(A, 1, action, ActorFixtures.ActorFixture1.INSTANCE); // Assert final Optional trackedResource = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); assertThat(trackedResource).get().usingRecursiveComparison().isEqualTo(new TrackedResource("Source1", 0)); } @@ -277,26 +277,26 @@ void shouldNotUpdateTrackedResourceByExtractingNothing(final Action action) { @SuppressWarnings("AssertBetweenInconvertibleTypes") void shouldBeAbleToUpdateMultipleTrackedResources() { // Act - sut.insert(A, 1, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.insert(A, 1, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(1); - sut.insert(B, 1, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.insert(B, 1, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(2); - sut.insert(A, 1, Action.EXECUTE, FakeActors.FakeActor1.INSTANCE); + sut.insert(A, 1, Action.EXECUTE, ActorFixtures.ActorFixture1.INSTANCE); clock.set(3); - sut.insert(B, 1, Action.EXECUTE, FakeActors.FakeActor2.INSTANCE); + sut.insert(B, 1, Action.EXECUTE, ActorFixtures.ActorFixture2.INSTANCE); // Assert final Optional resourceAWithSource1 = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture1.class); final Optional resourceAWithSource2 = - sut.findTrackedResourceByActorType(A, FakeActors.FakeActor2.class); + sut.findTrackedResourceByActorType(A, ActorFixtures.ActorFixture2.class); final Optional resourceBWithSource1 = - sut.findTrackedResourceByActorType(B, FakeActors.FakeActor1.class); + sut.findTrackedResourceByActorType(B, ActorFixtures.ActorFixture1.class); final Optional resourceBWithSource2 = - sut.findTrackedResourceByActorType(B, FakeActors.FakeActor2.class); + sut.findTrackedResourceByActorType(B, ActorFixtures.ActorFixture2.class); assertThat(resourceAWithSource1).get().usingRecursiveComparison() .isEqualTo(new TrackedResource("Source1", 2));