diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/UnitTestsInitializer.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/AbstractTransferApiTest.java similarity index 54% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/UnitTestsInitializer.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/AbstractTransferApiTest.java index b91d4b2138..8105fab053 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/UnitTestsInitializer.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/AbstractTransferApiTest.java @@ -16,24 +16,12 @@ package net.fabricmc.fabric.test.transfer.unittests; -import org.slf4j.LoggerFactory; +import net.minecraft.Bootstrap; +import net.minecraft.SharedConstants; -import net.fabricmc.api.ModInitializer; - -public class UnitTestsInitializer implements ModInitializer { - @Override - public void onInitialize() { - AttributeTests.run(); - BaseStorageTests.run(); - FluidItemTests.run(); - FluidTests.run(); - FluidVariantTests.run(); - ItemTests.run(); - PlayerInventoryStorageTests.run(); - SingleVariantItemStorageTests.run(); - TransactionStateTests.run(); - UnderlyingViewTests.run(); - - LoggerFactory.getLogger("fabric-transfer-api-v1 testmod").info("Transfer API unit tests successful."); +public abstract class AbstractTransferApiTest { + protected static void bootstrap() { + SharedConstants.createGameVersion(); + Bootstrap.initialize(); } } diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/AttributeTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/AttributeTests.java similarity index 86% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/AttributeTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/AttributeTests.java index 2151afa313..1857621639 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/AttributeTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/AttributeTests.java @@ -16,7 +16,10 @@ package net.fabricmc.fabric.test.transfer.unittests; -import static net.fabricmc.fabric.test.transfer.unittests.TestUtil.assertEquals; +import static net.fabricmc.fabric.test.transfer.TestUtil.assertEquals; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import net.minecraft.fluid.Fluids; import net.minecraft.sound.SoundEvents; @@ -28,13 +31,14 @@ /** * Test that fluid attributes for vanilla fluids have the correct values. */ -public class AttributeTests { - public static void run() { - testWater(); - testLava(); +public class AttributeTests extends AbstractTransferApiTest { + @BeforeAll + static void beforeAll() { + bootstrap(); } - private static void testWater() { + @Test + public void testWater() { FluidVariant water = FluidVariant.of(Fluids.WATER); assertEquals(SoundEvents.ITEM_BUCKET_FILL, FluidVariantAttributes.getFillSound(water)); @@ -45,7 +49,8 @@ private static void testWater() { assertEquals(false, FluidVariantAttributes.isLighterThanAir(water)); } - private static void testLava() { + @Test + public void testLava() { FluidVariant lava = FluidVariant.of(Fluids.LAVA); assertEquals(SoundEvents.ITEM_BUCKET_FILL_LAVA, FluidVariantAttributes.getFillSound(lava)); diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/BaseStorageTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/BaseStorageTests.java similarity index 92% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/BaseStorageTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/BaseStorageTests.java index 1f39a034f0..0935d1e627 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/BaseStorageTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/BaseStorageTests.java @@ -17,10 +17,13 @@ package net.fabricmc.fabric.test.transfer.unittests; import static net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants.BUCKET; -import static net.fabricmc.fabric.test.transfer.unittests.TestUtil.assertEquals; +import static net.fabricmc.fabric.test.transfer.TestUtil.assertEquals; import java.util.Iterator; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import net.minecraft.fluid.Fluids; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; @@ -32,13 +35,14 @@ import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; -public class BaseStorageTests { - public static void run() { - testFilteringStorage(); - testNonEmptyIteratorWithModifiedView(); +public class BaseStorageTests extends AbstractTransferApiTest { + @BeforeAll + static void beforeAll() { + bootstrap(); } - private static void testFilteringStorage() { + @Test + public void testFilteringStorage() { SingleVariantStorage storage = new SingleVariantStorage<>() { @Override protected FluidVariant getBlankVariant() { @@ -102,7 +106,8 @@ protected boolean canInsert(FluidVariant resource) { * Regression test for * {@code nonEmptyIterator} not handling views that become empty during iteration correctly. */ - private static void testNonEmptyIteratorWithModifiedView() { + @Test + public void testNonEmptyIteratorWithModifiedView() { SingleVariantStorage storage = SingleFluidStorage.withFixedCapacity(BUCKET, () -> { }); storage.variant = FluidVariant.of(Fluids.WATER); diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidItemTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidItemTests.java similarity index 95% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidItemTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidItemTests.java index ff472132a1..2a1d8bbe79 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidItemTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidItemTests.java @@ -18,11 +18,13 @@ import static net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants.BOTTLE; import static net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants.BUCKET; -import static net.fabricmc.fabric.test.transfer.unittests.TestUtil.assertEquals; +import static net.fabricmc.fabric.test.transfer.TestUtil.assertEquals; import java.util.List; import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.PotionContentsComponent; @@ -48,17 +50,14 @@ import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -class FluidItemTests { - public static void run() { - testFluidItemApi(); - testWaterPotion(); - testSimpleContentsQuery(); - - // Ensure this doesn't throw an error due to the empty stack. - assertEquals(null, ContainerItemContext.withConstant(ItemStack.EMPTY).find(FluidStorage.ITEM)); +class FluidItemTests extends AbstractTransferApiTest { + @BeforeAll + static void beforeAll() { + bootstrap(); } - private static void testFluidItemApi() { + @Test + public void testFluidItemApi() { FluidVariant water = FluidVariant.of(Fluids.WATER); ItemVariant waterBucket = ItemVariant.of(Items.WATER_BUCKET); Inventory testInventory = new FluidItemTestInventory(ItemStack.EMPTY, new ItemStack(Items.BUCKET), new ItemStack(Items.WATER_BUCKET)); @@ -144,7 +143,8 @@ public List> getAdditionalSlots() { } } - private static void testWaterPotion() { + @Test + public void testWaterPotion() { FluidVariant water = FluidVariant.of(Fluids.WATER); Inventory testInventory = new SimpleInventory(new ItemStack(Items.GLASS_BOTTLE)); @@ -175,7 +175,8 @@ private static void testWaterPotion() { } } - private static void testSimpleContentsQuery() { + @Test + public void testSimpleContentsQuery() { assertEquals( new ResourceAmount<>(FluidVariant.of(Fluids.WATER), BUCKET), StorageUtil.findExtractableContent( @@ -194,6 +195,12 @@ private static void testSimpleContentsQuery() { ); } + @Test + public void testDoesNotThrow() { + // Ensure this doesn't throw an error due to the empty stack. + assertEquals(null, ContainerItemContext.withConstant(ItemStack.EMPTY).find(FluidStorage.ITEM)); + } + @Nullable public static RegistryEntry getPotion(ItemStack stack) { return stack.getOrDefault(DataComponentTypes.POTION_CONTENTS, PotionContentsComponent.DEFAULT).potion().orElse(null); diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidTests.java similarity index 92% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidTests.java index 452ab2c7ab..996342fbc2 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidTests.java @@ -18,6 +18,9 @@ import static net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants.BUCKET; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import net.minecraft.component.ComponentChanges; import net.minecraft.component.DataComponentType; import net.minecraft.fluid.Fluids; @@ -34,15 +37,10 @@ import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.test.transfer.ingame.TransferTestInitializer; -class FluidTests { - public static void run() { - testFluidStorage(); - } - - private static final FluidVariant TAGGED_WATER, TAGGED_WATER_2, WATER, LAVA; +class FluidTests extends AbstractTransferApiTest { + private static FluidVariant TAGGED_WATER, TAGGED_WATER_2, WATER, LAVA; private static int finalCommitCount = 0; - public static final DataComponentType TEST = Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(TransferTestInitializer.MOD_ID, "test"), - DataComponentType.builder().codec(Codecs.NONNEGATIVE_INT).packetCodec(PacketCodecs.VAR_INT).build()); + public static DataComponentType TEST; private static SingleSlotStorage createWaterStorage() { return new SingleVariantStorage<>() { @Override @@ -67,7 +65,10 @@ protected void onFinalCommit() { }; } - static { + @BeforeAll + static void beforeAll() { + bootstrap(); + ComponentChanges components = ComponentChanges.builder() .add(TEST, 1) .build(); @@ -75,9 +76,12 @@ protected void onFinalCommit() { TAGGED_WATER_2 = FluidVariant.of(Fluids.WATER, components); WATER = FluidVariant.of(Fluids.WATER); LAVA = FluidVariant.of(Fluids.LAVA); + TEST = Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(TransferTestInitializer.MOD_ID, "test"), + DataComponentType.builder().codec(Codecs.NONNEGATIVE_INT).packetCodec(PacketCodecs.VAR_INT).build()); } - private static void testFluidStorage() { + @Test + public void testFluidStorage() { SingleSlotStorage waterStorage = createWaterStorage(); // Test content diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidVariantTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidVariantTests.java similarity index 83% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidVariantTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidVariantTests.java index dd3b21b442..b7e1aec4d0 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/FluidVariantTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/FluidVariantTests.java @@ -16,19 +16,24 @@ package net.fabricmc.fabric.test.transfer.unittests; -import static net.fabricmc.fabric.test.transfer.unittests.TestUtil.assertEquals; +import static net.fabricmc.fabric.test.transfer.TestUtil.assertEquals; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; -class FluidVariantTests { - public static void run() { - testFlowing(); +class FluidVariantTests extends AbstractTransferApiTest { + @BeforeAll + static void beforeAll() { + bootstrap(); } - private static void testFlowing() { + @Test + public void testFlowing() { assertFluidEquals(Fluids.WATER, FluidVariant.of(Fluids.WATER), FluidVariant.of(Fluids.FLOWING_WATER)); assertFluidEquals(Fluids.LAVA, FluidVariant.of(Fluids.LAVA), FluidVariant.of(Fluids.FLOWING_LAVA)); assertEquals(FluidVariant.of(Fluids.WATER), FluidVariant.of(Fluids.FLOWING_WATER)); diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/ItemTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/ItemTests.java similarity index 92% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/ItemTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/ItemTests.java index 5168ec8b89..622e77d791 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/ItemTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/ItemTests.java @@ -16,11 +16,13 @@ package net.fabricmc.fabric.test.transfer.unittests; -import static net.fabricmc.fabric.test.transfer.unittests.TestUtil.assertEquals; +import static net.fabricmc.fabric.test.transfer.TestUtil.assertEquals; import java.util.stream.IntStream; import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import net.minecraft.component.ComponentChanges; import net.minecraft.component.DataComponentType; @@ -48,19 +50,18 @@ /** * Tests for the item transfer APIs. */ -class ItemTests { - public static final DataComponentType ENERGY = Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(TransferTestInitializer.MOD_ID, "energy"), - DataComponentType.builder().codec(Codecs.NONNEGATIVE_INT).packetCodec(PacketCodecs.VAR_INT).build()); - - public static void run() { - testStackReference(); - testInventoryWrappers(); - testLimitedStackCountInventory(); - testLimitedStackCountItem(); - testSimpleInventoryUpdates(); +class ItemTests extends AbstractTransferApiTest { + public static DataComponentType ENERGY; + + @BeforeAll + static void beforeAll() { + bootstrap(); + ENERGY = Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(TransferTestInitializer.MOD_ID, "energy"), + DataComponentType.builder().codec(Codecs.NONNEGATIVE_INT).packetCodec(PacketCodecs.VAR_INT).build()); } - private static void testStackReference() { + @Test + public void testStackReference() { // Ensure that Inventory wrappers will try to mutate the backing stack as much as possible. // In many cases, MC code captures a reference to the ItemStack so we want to edit that stack directly // and not a copy whenever we can. Obviously this can't be perfect, but we try to cover as many cases as possible. @@ -98,7 +99,8 @@ private static void testStackReference() { if (!stackEquals(stack, newVariant, 5)) throw new AssertionError("Failed to update stack NBT or count."); } - private static void testInventoryWrappers() { + @Test + public void testInventoryWrappers() { ItemVariant emptyBucket = ItemVariant.of(Items.BUCKET); TestSidedInventory testInventory = new TestSidedInventory(); checkComparatorOutput(testInventory); @@ -189,7 +191,8 @@ public boolean canExtract(int slot, ItemStack stack, Direction dir) { /** * Test insertion when {@link Inventory#getMaxCountPerStack()} is the bottleneck. */ - private static void testLimitedStackCountInventory() { + @Test + public void testLimitedStackCountInventory() { ItemVariant diamond = ItemVariant.of(Items.DIAMOND); LimitedStackCountInventory inventory = new LimitedStackCountInventory(diamond.toStack(), diamond.toStack(), diamond.toStack()); InventoryStorage wrapper = InventoryStorage.of(inventory, null); @@ -207,7 +210,8 @@ private static void testLimitedStackCountInventory() { /** * Test insertion when {@link Item#getMaxCount()} is the bottleneck. */ - private static void testLimitedStackCountItem() { + @Test + public void testLimitedStackCountItem() { ItemVariant diamondPickaxe = ItemVariant.of(Items.DIAMOND_PICKAXE); LimitedStackCountInventory inventory = new LimitedStackCountInventory(5); InventoryStorage wrapper = InventoryStorage.of(inventory, null); @@ -256,7 +260,8 @@ private static void checkComparatorOutput(Inventory inventory) { /** * Ensure that SimpleInventory only calls markDirty at the end of a successful transaction. */ - private static void testSimpleInventoryUpdates() { + @Test + public void testSimpleInventoryUpdates() { var simpleInventory = new SimpleInventory(2) { boolean throwOnMarkDirty = true; boolean markDirtyCalled = false; diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/PlayerInventoryStorageTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/PlayerInventoryStorageTests.java similarity index 88% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/PlayerInventoryStorageTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/PlayerInventoryStorageTests.java index ea92943b67..31af285209 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/PlayerInventoryStorageTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/PlayerInventoryStorageTests.java @@ -16,10 +16,13 @@ package net.fabricmc.fabric.test.transfer.unittests; -import static net.fabricmc.fabric.test.transfer.unittests.TestUtil.assertEquals; +import static net.fabricmc.fabric.test.transfer.TestUtil.assertEquals; import java.util.function.Function; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -29,15 +32,25 @@ import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -public class PlayerInventoryStorageTests { - public static void run() { +public class PlayerInventoryStorageTests extends AbstractTransferApiTest { + @BeforeAll + static void beforeAll() { + bootstrap(); + } + + @Test + public void testStackingOffer() { // Ensure that offer stacks as expected. testStacking(playerInv -> playerInv::offer); + } + + @Test + public void testStackingInser() { // Also test that the behavior of insert matches that of offer. testStacking(playerInv -> playerInv::insert); } - private static void testStacking(Function inserterBuilder) { + private void testStacking(Function inserterBuilder) { // A bit hacky... but nothing should try using the null player entity as long as we don't call drop. PlayerInventory inv = new PlayerInventory(null); InsertionFunction inserter = inserterBuilder.apply(PlayerInventoryStorage.of(inv)); diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/SingleVariantItemStorageTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/SingleVariantItemStorageTests.java similarity index 90% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/SingleVariantItemStorageTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/SingleVariantItemStorageTests.java index 52b629abd3..d8bb910625 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/SingleVariantItemStorageTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/SingleVariantItemStorageTests.java @@ -17,12 +17,14 @@ package net.fabricmc.fabric.test.transfer.unittests; import static net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants.BUCKET; -import static net.fabricmc.fabric.test.transfer.unittests.TestUtil.assertEquals; +import static net.fabricmc.fabric.test.transfer.TestUtil.assertEquals; import java.util.List; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import net.minecraft.component.ComponentChanges; import net.minecraft.component.DataComponentType; @@ -51,17 +53,22 @@ import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.fabricmc.fabric.test.transfer.ingame.TransferTestInitializer; -public class SingleVariantItemStorageTests { - private static final FluidVariant LAVA = FluidVariant.of(Fluids.LAVA); - public static final DataComponentType FLUID = Registry.register( - Registries.DATA_COMPONENT_TYPE, new Identifier(TransferTestInitializer.MOD_ID, "fluid"), - DataComponentType.builder().codec(FluidData.CODEC).packetCodec(FluidData.PACKET_CODEC).build()); +public class SingleVariantItemStorageTests extends AbstractTransferApiTest { + private static FluidVariant LAVA; + public static DataComponentType FLUID; - public static void run() { - testWaterTank(); + @BeforeAll + static void beforeAll() { + bootstrap(); + + LAVA = FluidVariant.of(Fluids.LAVA); + FLUID = Registry.register( + Registries.DATA_COMPONENT_TYPE, new Identifier(TransferTestInitializer.MOD_ID, "fluid"), + DataComponentType.builder().codec(FluidData.CODEC).packetCodec(FluidData.PACKET_CODEC).build()); } - private static void testWaterTank() { + @Test + public void testWaterTank() { SimpleInventory inv = new SimpleInventory(new ItemStack(Items.DIAMOND, 2), ItemStack.EMPTY); ContainerItemContext ctx = new InventoryContainerItemContext(inv); diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/TransactionStateTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/TransactionStateTests.java similarity index 90% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/TransactionStateTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/TransactionStateTests.java index 86a118b1e3..e9067027c4 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/TransactionStateTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/TransactionStateTests.java @@ -16,20 +16,25 @@ package net.fabricmc.fabric.test.transfer.unittests; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.fabricmc.fabric.test.transfer.TestUtil; -class TransactionStateTests { - public static void run() { - testTransactionExceptions(); - testTransactionLifecycle(); - } +class TransactionStateTests extends AbstractTransferApiTest { + private int callbacksInvoked = 0; - private static int callbacksInvoked = 0; + @BeforeAll + static void beforeAll() { + bootstrap(); + } /** * Make sure that transaction global state stays valid in case of exceptions. */ - private static void testTransactionExceptions() { + @Test + public void testTransactionExceptions() { // Test exception inside the try. ensureException(() -> { try (Transaction tx = Transaction.openOuter()) { @@ -96,7 +101,8 @@ private static void ensureException(Runnable runnable, String message) { } } - private static void testTransactionLifecycle() { + @Test + public void testTransactionLifecycle() { TestUtil.assertEquals(Transaction.Lifecycle.NONE, Transaction.getLifecycle()); try (Transaction transaction = Transaction.openOuter()) { diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/UnderlyingViewTests.java b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/UnderlyingViewTests.java similarity index 87% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/UnderlyingViewTests.java rename to fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/UnderlyingViewTests.java index 494dee84e0..d5b9c7cce0 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/UnderlyingViewTests.java +++ b/fabric-transfer-api-v1/src/test/java/net/fabricmc/fabric/test/transfer/unittests/UnderlyingViewTests.java @@ -21,6 +21,8 @@ import it.unimi.dsi.fastutil.Hash; import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenCustomHashMap; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import net.minecraft.block.Blocks; import net.minecraft.block.entity.FurnaceBlockEntity; @@ -30,16 +32,19 @@ import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; +import net.fabricmc.fabric.test.transfer.TestUtil; -public class UnderlyingViewTests { - public static void run() { - testFurnaceSides(); +public class UnderlyingViewTests extends AbstractTransferApiTest { + @BeforeAll + static void beforeAll() { + bootstrap(); } /** * Ensure that only 3 slots with different underlying view exist on all sides of a furnace combined. */ - private static void testFurnaceSides() { + @Test + public void testFurnaceSides() { FurnaceBlockEntity furnace = new FurnaceBlockEntity(BlockPos.ORIGIN, Blocks.FURNACE.getDefaultState()); Set> viewSet = Collections.newSetFromMap(new Reference2ReferenceOpenCustomHashMap<>(new Hash.Strategy<>() { diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/TestUtil.java b/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/TestUtil.java similarity index 94% rename from fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/TestUtil.java rename to fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/TestUtil.java index 5bdc5389ff..1a9df0dd94 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/unittests/TestUtil.java +++ b/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/TestUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.fabric.test.transfer.unittests; +package net.fabricmc.fabric.test.transfer; import java.util.Objects; diff --git a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/gametests/WorldDependentAttributesTest.java b/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/gametests/WorldDependentAttributesTest.java index 0a5232153b..91eb2b57c5 100644 --- a/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/gametests/WorldDependentAttributesTest.java +++ b/fabric-transfer-api-v1/src/testmod/java/net/fabricmc/fabric/test/transfer/gametests/WorldDependentAttributesTest.java @@ -16,7 +16,7 @@ package net.fabricmc.fabric.test.transfer.gametests; -import static net.fabricmc.fabric.test.transfer.unittests.TestUtil.assertEquals; +import static net.fabricmc.fabric.test.transfer.TestUtil.assertEquals; import net.minecraft.fluid.Fluids; import net.minecraft.server.world.ServerWorld;