Skip to content

Commit 1bbe52a

Browse files
committed
Working on swapping to MCUnit integration tests
1 parent ed4ac19 commit 1bbe52a

19 files changed

+190
-212
lines changed

.github/workflows/ci-tests-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
run: chmod +x gradlew
5454

5555
- name: Test JAR with Gradle
56-
run: ./gradlew runUnitTests
56+
run: ./gradlew runUnitTestsCI
5757
env:
5858
GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }}
5959
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ sourceSets {
5757
compileClasspath += sourceSets.main.output
5858
runtimeClasspath += sourceSets.api.output
5959
runtimeClasspath += sourceSets.main.output
60+
61+
resources {
62+
srcDir "src/test/resources"
63+
}
6064
}
6165
}
6266

@@ -141,7 +145,6 @@ minecraft {
141145
environment 'MOD_MODULES', String.join(File.pathSeparator, "${mod_id}%%${project.name}.test")
142146
environment 'target', 'fmltestserver'
143147
environment 'targetModId', "${mod_id}"
144-
arg '--crashOnFailedTests'
145148
forceExit = false
146149
mods {
147150
compactcrafting {
@@ -151,6 +154,11 @@ minecraft {
151154
}
152155
}
153156
}
157+
158+
unitTestsCI {
159+
parent runs.unitTests
160+
arg '--crashOnFailedTests'
161+
}
154162
}
155163
}
156164

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package dev.compactmods.crafting.tests;
2+
3+
import dev.compactmods.crafting.CompactCrafting;
4+
import net.minecraft.server.MinecraftServer;
5+
import net.minecraftforge.eventbus.api.SubscribeEvent;
6+
import net.minecraftforge.fml.common.Mod;
7+
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
8+
9+
@Mod.EventBusSubscriber(modid = CompactCrafting.MOD_ID)
10+
public class ServerEventListener {
11+
@SubscribeEvent
12+
public static void onServerStarted(final FMLServerStartedEvent evt) {
13+
14+
final MinecraftServer server = evt.getServer();
15+
// final File root = server.getServerDirectory().getParentFile();
16+
// server.getPackRepository().addPackFinder(new FolderPackFinder());
17+
}
18+
19+
}

src/test/java/dev/compactmods/crafting/tests/recipes/layers/FilledLayerTests.java

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import java.util.Optional;
44
import java.util.Set;
55
import java.util.stream.Collectors;
6+
import com.alcatrazescapee.mcjunitlib.framework.IntegrationTest;
7+
import com.alcatrazescapee.mcjunitlib.framework.IntegrationTestClass;
8+
import com.alcatrazescapee.mcjunitlib.framework.IntegrationTestHelper;
69
import com.google.gson.JsonElement;
710
import com.mojang.serialization.JsonOps;
811
import dev.compactmods.crafting.api.field.MiniaturizationFieldSize;
@@ -11,14 +14,14 @@
1114
import dev.compactmods.crafting.recipes.layers.FilledComponentRecipeLayer;
1215
import dev.compactmods.crafting.tests.recipes.util.RecipeTestUtil;
1316
import dev.compactmods.crafting.tests.util.FileHelper;
14-
import dev.compactmods.crafting.tests.world.TestBlockReader;
1517
import dev.compactmods.crafting.util.BlockSpaceUtil;
1618
import net.minecraft.util.math.AxisAlignedBB;
1719
import net.minecraft.util.math.BlockPos;
1820
import org.junit.jupiter.api.Assertions;
1921
import org.junit.jupiter.api.Tag;
2022
import org.junit.jupiter.api.Test;
2123

24+
@IntegrationTestClass("layers")
2225
public class FilledLayerTests {
2326

2427
private FilledComponentRecipeLayer getLayerFromFile(String filename) {
@@ -92,7 +95,6 @@ void CanFetchComponentByPosition() {
9295
});
9396
}
9497

95-
@Test
9698
@Tag("minecraft")
9799
void ReturnsEmptyWhenFetchingOOBPosition() {
98100
final FilledComponentRecipeLayer layer = getLayerFromFile("layers/filled/basic.json");
@@ -103,15 +105,13 @@ void ReturnsEmptyWhenFetchingOOBPosition() {
103105
Assertions.assertFalse(componentForPosition.isPresent());
104106
}
105107

106-
@Test
107108
@Tag("minecraft")
108-
void FilledLayerMatchesWorldInExactMatchScenario() {
109-
final TestBlockReader reader = RecipeTestUtil.getBlockReader("worlds/single_layer_medium_filled_G.json");
109+
@IntegrationTest("medium_glass_filled")
110+
void FilledLayerMatchesWorldInExactMatchScenario(IntegrationTestHelper helper) {
110111
final MiniaturizationRecipeComponents components = RecipeTestUtil.getComponentsFromRecipeFile("worlds/single_layer_medium_filled_G.json");
111112

112-
Assertions.assertNotNull(reader);
113-
114-
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(reader, components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
113+
final AxisAlignedBB bounds = BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0).move(helper.relativePos(BlockPos.ZERO).orElse(BlockPos.ZERO));
114+
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(helper.getWorld(), components, bounds);
115115

116116
// Set up a 5x5x1 filled layer, using "G" component
117117
final FilledComponentRecipeLayer layer = new FilledComponentRecipeLayer("G");
@@ -121,15 +121,12 @@ void FilledLayerMatchesWorldInExactMatchScenario() {
121121
Assertions.assertTrue(matched);
122122
}
123123

124-
@Test
125124
@Tag("minecraft")
126-
void FailsMatchIfAllBlocksNotIdentified() {
127-
final TestBlockReader reader = RecipeTestUtil.getBlockReader("worlds/basic_mixed_medium_iron.json");
128-
final MiniaturizationRecipeComponents components = RecipeTestUtil.getComponentsFromRecipeFile("worlds/basic_mixed_medium_iron.json");
129-
130-
Assertions.assertNotNull(reader);
125+
@IntegrationTest("medium_glass_walls_obsidian_center")
126+
void FailsMatchIfAllBlocksNotIdentified(IntegrationTestHelper helper) {
127+
final MiniaturizationRecipeComponents components = RecipeTestUtil.getComponentsFromRecipeFile("recipes/basic_mixed_medium_iron.json");
131128

132-
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(reader, components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
129+
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(helper.getWorld(), components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
133130

134131
// Set up a 5x5x1 filled layer, using "G" component
135132
final FilledComponentRecipeLayer layer = new FilledComponentRecipeLayer("G");
@@ -139,15 +136,12 @@ void FailsMatchIfAllBlocksNotIdentified() {
139136
Assertions.assertFalse(matched);
140137
}
141138

142-
@Test
143139
@Tag("minecraft")
144-
void FailsMatchIfMoreThanOneBlockFound() {
145-
final TestBlockReader reader = RecipeTestUtil.getBlockReader("worlds/basic_harness_allmatched_5x.json");
140+
@IntegrationTest("medium_glass_walls_obsidian_center")
141+
void FailsMatchIfMoreThanOneBlockFound(IntegrationTestHelper helper) {
146142
final MiniaturizationRecipeComponents components = RecipeTestUtil.getComponentsFromRecipeFile("worlds/basic_harness_allmatched_5x.json");
147143

148-
Assertions.assertNotNull(reader);
149-
150-
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(reader, components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
144+
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(helper.getWorld(), components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
151145

152146
// Set up a 5x5x1 filled layer, using "G" component
153147
final FilledComponentRecipeLayer layer = new FilledComponentRecipeLayer("G");
@@ -157,21 +151,19 @@ void FailsMatchIfMoreThanOneBlockFound() {
157151
Assertions.assertFalse(matched);
158152
}
159153

160-
@Test
161154
@Tag("minecraft")
162-
void FailsMatchIfComponentKeyNotFound() {
163-
final TestBlockReader reader = RecipeTestUtil.getBlockReader("worlds/basic_filled_medium_glass_A.json");
155+
@IntegrationTest("medium_glass_filled")
156+
void FailsMatchIfComponentKeyNotFound(IntegrationTestHelper helper) {
164157
final MiniaturizationRecipeComponents components = RecipeTestUtil.getComponentsFromRecipeFile("worlds/basic_filled_medium_glass_A.json");
165158

166-
Assertions.assertNotNull(reader);
167-
168-
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(reader, components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
159+
final AxisAlignedBB bounds = RecipeTestUtil.getFloorLayerBounds(MiniaturizationFieldSize.MEDIUM, helper);
160+
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(helper.getWorld(), components, bounds);
169161

170162
// Set up a 5x5x1 filled layer, using "G" component
171163
final FilledComponentRecipeLayer layer = new FilledComponentRecipeLayer("G");
172164
layer.setRecipeDimensions(MiniaturizationFieldSize.MEDIUM);
173165

174166
boolean matched = Assertions.assertDoesNotThrow(() -> layer.matches(components, blocks));
175-
Assertions.assertFalse(matched);
167+
helper.assertTrue(() -> !matched, "Layer matched despite not having the required component defined.");
176168
}
177169
}

src/test/java/dev/compactmods/crafting/tests/recipes/layers/HollowLayerTests.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@
44
import java.util.Map;
55
import java.util.Optional;
66
import java.util.stream.Stream;
7+
import com.alcatrazescapee.mcjunitlib.framework.IntegrationTest;
8+
import com.alcatrazescapee.mcjunitlib.framework.IntegrationTestClass;
9+
import com.alcatrazescapee.mcjunitlib.framework.IntegrationTestHelper;
710
import com.google.gson.JsonElement;
811
import com.mojang.serialization.JsonOps;
912
import dev.compactmods.crafting.api.field.MiniaturizationFieldSize;
1013
import dev.compactmods.crafting.recipes.blocks.RecipeLayerBlocks;
14+
import dev.compactmods.crafting.recipes.components.BlockComponent;
1115
import dev.compactmods.crafting.recipes.components.MiniaturizationRecipeComponents;
1216
import dev.compactmods.crafting.recipes.layers.HollowComponentRecipeLayer;
1317
import dev.compactmods.crafting.tests.recipes.util.RecipeTestUtil;
1418
import dev.compactmods.crafting.tests.util.FileHelper;
15-
import dev.compactmods.crafting.tests.world.TestBlockReader;
1619
import dev.compactmods.crafting.util.BlockSpaceUtil;
1720
import net.minecraft.block.Blocks;
21+
import net.minecraft.util.math.AxisAlignedBB;
1822
import net.minecraft.util.math.BlockPos;
1923
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.DisplayName;
2025
import org.junit.jupiter.api.Tag;
2126
import org.junit.jupiter.api.Test;
2227

28+
@IntegrationTestClass("layers")
2329
public class HollowLayerTests {
2430

2531
private HollowComponentRecipeLayer getLayerFromFile(String filename) {
@@ -85,38 +91,38 @@ void HollowPositionalInquiries() {
8591
Assertions.assertEquals(0, xPositions.count());
8692
}
8793

88-
89-
@Test
9094
@Tag("minecraft")
91-
void HollowMatchesWorldDefinitionExactly() {
92-
String file = "worlds/basic_hollow_medium_glass_A.json";
93-
final TestBlockReader reader = RecipeTestUtil.getBlockReader(file);
94-
final MiniaturizationRecipeComponents components = RecipeTestUtil.getComponentsFromRecipeFile(file);
95+
@IntegrationTest("medium_glass_walls")
96+
void HollowMatchesWorldDefinitionExactly(IntegrationTestHelper helper) {
97+
final BlockPos zeroPoint = helper.relativePos(BlockPos.ZERO).orElse(BlockPos.ZERO);
98+
99+
final MiniaturizationRecipeComponents components = new MiniaturizationRecipeComponents();
100+
components.registerBlock("A", new BlockComponent(Blocks.GLASS));
95101

96-
Assertions.assertNotNull(reader);
102+
final AxisAlignedBB bounds = BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0).move(zeroPoint);
97103

98-
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(reader, components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
104+
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(helper.getWorld(), components, bounds);
99105

100106
HollowComponentRecipeLayer layer = new HollowComponentRecipeLayer("A");
101107
layer.setRecipeDimensions(MiniaturizationFieldSize.MEDIUM);
102108

103-
final boolean matches = layer.matches(components, blocks);
109+
boolean matched = layer.matches(components, blocks);
104110

105-
Assertions.assertTrue(matches, "Hollow did not pass perfect match.");
111+
if(!matched) {
112+
helper.fail("Hollow did not pass perfect match.");
113+
}
106114
}
107115

108-
@Test
109116
@Tag("minecraft")
110-
void HollowFailsIfWorldHasBadWallBlock() {
117+
@IntegrationTest("medium_glass_walls")
118+
@DisplayName("Hollow - Bad Wall Block")
119+
void HollowFailsIfWorldHasBadWallBlock(IntegrationTestHelper helper) {
111120
String file = "worlds/basic_hollow_medium_glass_A.json";
112-
final TestBlockReader reader = RecipeTestUtil.getBlockReader(file);
113121
final MiniaturizationRecipeComponents components = RecipeTestUtil.getComponentsFromRecipeFile(file);
114122

115-
Assertions.assertNotNull(reader);
116-
117-
reader.replaceBlock(BlockPos.ZERO, Blocks.GOLD_BLOCK.defaultBlockState());
123+
helper.setBlockState(BlockPos.ZERO, Blocks.GOLD_BLOCK.defaultBlockState());
118124

119-
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(reader, components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
125+
final RecipeLayerBlocks blocks = RecipeLayerBlocks.create(helper.getWorld(), components, BlockSpaceUtil.getLayerBounds(MiniaturizationFieldSize.MEDIUM, 0));
120126

121127
HollowComponentRecipeLayer layer = new HollowComponentRecipeLayer("A");
122128
layer.setRecipeDimensions(MiniaturizationFieldSize.MEDIUM);

0 commit comments

Comments
 (0)