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/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/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/AbstractModInitializer.java index c3347be1f..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; 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/autocrafting/AutocrafterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java index 37faee307..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,7 +40,6 @@ 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; @@ -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()) { 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/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/CraftingGridContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridContainerMenu.java index 72b5ef8ca..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; 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 4b84e266c..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 @@ -258,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); } 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 918e9e804..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 @@ -107,13 +107,13 @@ private void addFilterButtons(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); - } - private void addStorageButtons(final boolean visible) { priorityButton = PrioritySideButtonWidget.forStorage( getMenu().getProperty(StoragePropertyTypes.PRIORITY), playerInventory, @@ -154,12 +154,12 @@ private void updateFilterButtons(final boolean visible) { if (fuzzyModeButton != null) { fuzzyModeButton.visible = visible; } - if (accessModeButton != null) { - accessModeButton.visible = visible; - } } private void updateStorageButtons(final boolean visible) { + if (accessModeButton != null) { + accessModeButton.visible = visible; + } if (priorityButton != null) { priorityButton.visible = visible; } 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 6797e19e1..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 @@ -595,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-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/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 83664a049..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 @@ -5,11 +5,8 @@ import com.refinedmods.refinedstorage.api.network.autocrafting.PatternProvider; import com.refinedmods.refinedstorage.api.network.impl.node.SimpleNetworkNode; -import java.util.Arrays; import java.util.HashSet; -import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; import javax.annotation.Nullable; public class PatternProviderNetworkNode extends SimpleNetworkNode implements PatternProvider { 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 508b3fb97..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,8 +1,50 @@ package com.refinedmods.refinedstorage.api.network.impl.node.relay; -public enum RelayComponentType { - ENERGY, - SECURITY, - STORAGE, - AUTOCRAFTING +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 5d1d8b248..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,11 +1,7 @@ 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.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; @@ -17,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; @@ -42,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 { @@ -62,22 +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); - final boolean hasAutocrafting = componentTypes.contains(RelayComponentType.AUTOCRAFTING); - outputNode.setAutocraftingDelegate(valid && hasAutocrafting - ? network.getComponent(AutocraftingNetworkComponent.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) { @@ -110,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/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 4e8ef79f3..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 @@ -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) 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/node/importer/ImporterNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/importer/ImporterNetworkNodeTest.java index 3eb7ce89f..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 @@ -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/relay/RelayNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java index c2cfaa6a9..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 @@ -29,10 +29,11 @@ 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.fixtures.ResourceFixtures.A; @@ -438,9 +439,13 @@ void shouldResetComponentsWhenComponentTypeIsDisabled( 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); 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));