Skip to content

Commit 42be514

Browse files
committed
to nobody's surprise, more test stuff
1 parent 89508cc commit 42be514

13 files changed

+414
-243
lines changed

src/test/java/dev/compactmods/crafting/tests/components/ComponentPositionLookupTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class ComponentPositionLookupTests {
1717

1818
@Test
19-
void CanCreate() {
19+
void CanCreatePosLookup() {
2020
ComponentPositionLookup lookup = new ComponentPositionLookup();
2121
Assertions.assertNotNull(lookup);
2222
}

src/test/java/dev/compactmods/crafting/tests/recipes/MiniaturizationRecipes.java

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import javax.annotation.Nullable;
44
import java.util.Map;
5+
import java.util.Objects;
56
import java.util.Optional;
67
import java.util.Set;
78
import java.util.stream.Collectors;
@@ -36,7 +37,7 @@ private static MiniaturizationRecipe getRecipe(GameTestHelper testHelper, String
3637
}
3738

3839
@Test
39-
void CanCreate() {
40+
void CanCreateRecipe() {
4041
MiniaturizationRecipe recipe = new MiniaturizationRecipe();
4142
Assertions.assertNotNull(recipe);
4243
}
@@ -62,20 +63,25 @@ void IsSpecialRecipe() {
6263

6364
// @StructureFile("ender_crystal")
6465
@GameTest(template = "recipes/ender_crystal", templateNamespace = CompactCrafting.MOD_ID)
65-
public static void FakesFakeInventories(final GameTestHelper helper) {
66+
public static void FakesFakeInventories(final GameTestHelper test) {
6667
MiniaturizationRecipe recipe = new MiniaturizationRecipe();
67-
Assertions.assertNotNull(recipe);
6868

69-
Assertions.assertDoesNotThrow(() -> {
70-
boolean matched = recipe.matches(new FakeInventory(), helper.getLevel());
71-
Assertions.assertTrue(matched);
72-
});
69+
try {
70+
boolean matched = recipe.matches(new FakeInventory(), test.getLevel());
71+
if(!matched)
72+
test.fail("Expected fake inventory to always match.");
73+
}
74+
75+
catch (Exception e) {
76+
test.fail(e.getMessage());
77+
}
78+
79+
test.succeed();
7380
}
7481

7582
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
7683
public static void FakesAssemble(final GameTestHelper test) {
7784
MiniaturizationRecipe recipe = new MiniaturizationRecipe();
78-
Assertions.assertNotNull(recipe);
7985

8086
try {
8187
ItemStack result = recipe.assemble(new FakeInventory());
@@ -104,40 +110,54 @@ void FakesCanCraftDimensions() {
104110
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
105111
public static void FakesResultItem(final GameTestHelper test) {
106112
MiniaturizationRecipe recipe = new MiniaturizationRecipe();
107-
Assertions.assertNotNull(recipe);
108113

109-
Assertions.assertDoesNotThrow(() -> {
114+
try{
110115
final ItemStack result = recipe.getResultItem();
111-
Assertions.assertTrue(result.isEmpty());
112-
});
116+
if(!result.isEmpty())
117+
test.fail("Expected recipe result to be empty.");
118+
}
119+
120+
catch(Exception e) {
121+
test.fail(e.getMessage());
122+
}
123+
124+
test.succeed();
113125
}
114126

115127
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
116128
public static void RecipeSuppliesBasicMinecraftRegistrationInfo(final GameTestHelper test) {
117129
final MiniaturizationRecipe enderCrystal = getRecipe(test, "ender_crystal");
118-
Assertions.assertNotNull(enderCrystal);
130+
if(enderCrystal == null)
131+
return;
119132

120-
final var serializer = Assertions.assertDoesNotThrow(enderCrystal::getSerializer);
121-
Assertions.assertNotNull(serializer);
133+
final var serializer = enderCrystal.getSerializer();
134+
if(serializer == null)
135+
test.fail("Did not get a recipe serializer from the recipe class.");
122136

123-
final var type = Assertions.assertDoesNotThrow(enderCrystal::getType);
124-
Assertions.assertNotNull(type);
137+
final var type = enderCrystal.getType();
138+
if(type == null)
139+
test.fail("Did not get a recipe type from the recipe class.");
140+
141+
test.succeed();
125142
}
126143

127144

128145
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
129146
public static void RecipeReturnsEmptyIfLayerNotRegistered(final GameTestHelper test) {
130147
final MiniaturizationRecipe enderCrystal = getRecipe(test, "ender_crystal");
131-
Assertions.assertNotNull(enderCrystal);
148+
Objects.requireNonNull(enderCrystal);
149+
150+
final Optional<IRecipeLayer> layer = enderCrystal.getLayer(999);
151+
if(layer.isPresent())
152+
test.fail("Layer should not have been present.");
132153

133-
final Optional<IRecipeLayer> layer = Assertions.assertDoesNotThrow(() -> enderCrystal.getLayer(999));
134-
Assertions.assertFalse(layer.isPresent());
154+
test.succeed();
135155
}
136156

137157
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
138158
public static void FitsInCorrectFieldSizes(final GameTestHelper test) {
139159
final MiniaturizationRecipe enderCrystal = getRecipe(test, "ender_crystal");
140-
Assertions.assertNotNull(enderCrystal);
160+
Objects.requireNonNull(enderCrystal);
141161

142162
MiniaturizationFieldSize[] badSizes = new MiniaturizationFieldSize[]{
143163
MiniaturizationFieldSize.INACTIVE, MiniaturizationFieldSize.SMALL
@@ -147,11 +167,16 @@ public static void FitsInCorrectFieldSizes(final GameTestHelper test) {
147167
MiniaturizationFieldSize.MEDIUM, MiniaturizationFieldSize.LARGE, MiniaturizationFieldSize.ABSURD
148168
};
149169

170+
// TODO: GameTestGenerator?
150171
for (MiniaturizationFieldSize bs : badSizes)
151-
Assertions.assertFalse(enderCrystal.fitsInFieldSize(bs), "Fit in bad field size: " + bs);
172+
if(enderCrystal.fitsInFieldSize(bs))
173+
test.fail("Fit in bad field size: " + bs);
152174

153175
for (MiniaturizationFieldSize gs : goodSizes)
154-
Assertions.assertTrue(enderCrystal.fitsInFieldSize(gs), "Did not fit in field size: " + gs);
176+
if(!enderCrystal.fitsInFieldSize(gs))
177+
test.fail("Did not fit in field size: " + gs);
178+
179+
test.succeed();
155180
}
156181

157182
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)

src/test/java/dev/compactmods/crafting/tests/recipes/components/BlockComponentTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static void CanReserializeComponentMatcher(final GameTestHelper test) thr
137137
.ifPresent(matcher -> {
138138
var sout = BlockComponent.CODEC
139139
.encodeStart(JsonOps.INSTANCE, matcher)
140-
.resultOrPartial(Assertions::fail)
140+
.resultOrPartial(test::fail)
141141
.get();
142142

143143
if(!sout.equals(json))

src/test/java/dev/compactmods/crafting/tests/recipes/components/CCRecipeComponentsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class CCRecipeComponentsTests {
1919

2020
@Test
21-
void CanCreateInstance() {
21+
void CanCreateComponents() {
2222
MiniaturizationRecipeComponents components = new MiniaturizationRecipeComponents();
2323
Assertions.assertNotNull(components);
2424
}

src/test/java/dev/compactmods/crafting/tests/recipes/components/EmptyComponentTests.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@
1919
public class EmptyComponentTests {
2020

2121
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
22-
public static void CanCreate(final GameTestHelper test) {
22+
public static void CanCreateEmptyComponent(final GameTestHelper test) {
2323
JsonElement json = FileHelper.getJsonFromFile("components/empty/empty_component.json");
2424

2525
EmptyBlockComponent.CODEC.decode(JsonOps.INSTANCE, json)
26-
.resultOrPartial(Assertions::fail)
26+
.resultOrPartial(test::fail)
2727
.ifPresent(res -> {
2828
EmptyBlockComponent comp = res.getFirst();
2929

3030
boolean matchesAir = comp.matches(Blocks.AIR.defaultBlockState());
3131
boolean matchesCaveAir = comp.matches(Blocks.CAVE_AIR.defaultBlockState());
3232

33-
Assertions.assertTrue(matchesAir, "Expected empty to match air.");
34-
Assertions.assertTrue(matchesCaveAir, "Expected empty to match cave air.");
33+
if(!matchesAir)
34+
test.fail("Expected empty to match air.");
35+
36+
if(!matchesCaveAir)
37+
test.fail("Expected empty to match cave air.");
38+
39+
test.succeed();
3540
});
3641
}
3742

@@ -48,14 +53,19 @@ public static void HasComponentType(final GameTestHelper test) {
4853
JsonElement json = FileHelper.getJsonFromFile("components/empty/empty_component.json");
4954

5055
EmptyBlockComponent.CODEC.decode(JsonOps.INSTANCE, json)
51-
.resultOrPartial(Assertions::fail)
56+
.resultOrPartial(test::fail)
5257
.ifPresent(res -> {
5358
EmptyBlockComponent comp = res.getFirst();
5459

5560
RecipeComponentType<?> type = comp.getType();
5661

57-
Assertions.assertNotNull(type);
58-
Assertions.assertEquals(ComponentRegistration.EMPTY_BLOCK_COMPONENT.get(), type);
62+
if(type == null)
63+
test.fail("Got null component type");
64+
65+
if(!ComponentRegistration.EMPTY_BLOCK_COMPONENT.get().equals(type))
66+
test.fail("Expected correct type");
67+
68+
test.succeed();
5969
});
6070
}
6171

@@ -64,22 +74,27 @@ public static void HasRenderState(final GameTestHelper test) {
6474
JsonElement json = FileHelper.getJsonFromFile("components/empty/empty_component.json");
6575

6676
EmptyBlockComponent.CODEC.decode(JsonOps.INSTANCE, json)
67-
.resultOrPartial(Assertions::fail)
77+
.resultOrPartial(test::fail)
6878
.ifPresent(res -> {
6979
EmptyBlockComponent comp = res.getFirst();
7080

7181
BlockState renderState = comp.getRenderState();
7282

73-
Assertions.assertNotNull(renderState);
83+
if(renderState == null)
84+
test.fail("Got null render state back from component");
85+
86+
test.succeed();
7487
});
7588
}
7689

7790
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
7891
public static void CanGetBlock(final GameTestHelper test) {
7992
EmptyBlockComponent component = new EmptyBlockComponent();
80-
Assertions.assertNotNull(component);
93+
final Block block = component.getBlock();
94+
95+
if(block instanceof AirBlock)
96+
test.succeed();
8197

82-
final Block block = Assertions.assertDoesNotThrow(component::getBlock);
83-
Assertions.assertTrue(block instanceof AirBlock);
98+
test.fail("Empty block is not air.");
8499
}
85100
}

src/test/java/dev/compactmods/crafting/tests/recipes/data/MiniaturizationRecipeCodecTests.java

Lines changed: 66 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.compactmods.crafting.tests.recipes.data;
22

33
import java.util.Map;
4+
import java.util.Objects;
45
import java.util.Optional;
56
import com.google.gson.JsonElement;
67
import com.mojang.datafixers.util.Either;
@@ -16,7 +17,6 @@
1617
import net.minecraft.gametest.framework.GameTestHelper;
1718
import net.minecraft.nbt.NbtOps;
1819
import net.minecraft.nbt.Tag;
19-
import org.junit.jupiter.api.Assertions;
2020

2121
public class MiniaturizationRecipeCodecTests {
2222

@@ -118,69 +118,80 @@ public static void PartialResultIfNoOutputsExist(final GameTestHelper test) {
118118
}
119119

120120
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
121-
public static void LoadsRecipeLayersCorrectly() {
122-
MiniaturizationRecipe recipe = RecipeTestUtil.getRecipeFromFile("test_data/data/compactcrafting/recipes/compact_walls.json");
123-
if (recipe == null) {
124-
Assertions.fail("No recipe was loaded.");
125-
} else {
126-
// There should only be two layers loaded from the file
127-
Assertions.assertEquals(2, recipe.getNumberLayers());
128-
129-
Optional<IRecipeLayer> topLayer = recipe.getLayer(1);
130-
if (!topLayer.isPresent()) {
131-
Assertions.fail("No top layer loaded.");
132-
return;
133-
}
134-
135-
IRecipeLayer lay = topLayer.get();
136-
137-
// Top Layer should be a redstone dust, so one 'R' component
138-
Map<String, Integer> componentTotals = lay.getComponentTotals();
139-
Assertions.assertTrue(componentTotals.containsKey("R"), "Expected redstone component in top layer; it does not exist.");
140-
Assertions.assertEquals(1, componentTotals.get("R"), "Expected one redstone required in top layer.");
121+
public static void LoadsRecipeLayersCorrectly(final GameTestHelper test) {
122+
MiniaturizationRecipe recipe = RecipeTestUtil.getRecipeByName(test, "compact_walls").orElseThrow();
123+
124+
// There should only be two layers loaded from the file
125+
if(2 != recipe.getNumberLayers())
126+
test.fail("Expected exactly 2 layers in recipe");
127+
128+
Optional<IRecipeLayer> topLayer = recipe.getLayer(1);
129+
if (topLayer.isEmpty()) {
130+
test.fail("No top layer loaded.");
131+
return;
141132
}
133+
134+
IRecipeLayer lay = topLayer.get();
135+
136+
// Top Layer should be a redstone dust, so one 'R' component
137+
Map<String, Integer> componentTotals = lay.getComponentTotals();
138+
if(!componentTotals.containsKey("R"))
139+
test.fail("Expected redstone component in top layer; it does not exist.");
140+
141+
if(1 != componentTotals.get("R"))
142+
test.fail("Expected one redstone required in top layer.");
143+
144+
test.succeed();
142145
}
143146

144147
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
145-
public static void LoadsCatalystCorrectly() {
146-
MiniaturizationRecipe recipe = RecipeTestUtil.getRecipeFromFile("test_data/data/compactcrafting/recipes/compact_walls.json");
147-
Assertions.assertNotNull(recipe);
148-
Assertions.assertNotNull(recipe.getCatalyst());
148+
public static void LoadsCatalystCorrectly(final GameTestHelper test) {
149+
MiniaturizationRecipe recipe = RecipeTestUtil.getRecipeByName(test, "compact_walls").orElseThrow();
150+
Objects.requireNonNull(recipe);
151+
152+
var cat = recipe.getCatalyst();
153+
if(cat == null)
154+
test.fail("Expected recipe catalyst to exist.");
149155

150156
MiniaturizationRecipe noComponents = RecipeTestUtil.getRecipeFromFile("recipe_tests/warn_no_catalyst.json");
151-
Assertions.assertNotNull(noComponents);
152-
Assertions.assertNull(noComponents.getCatalyst());
157+
Objects.requireNonNull(noComponents);
158+
var cat2 = noComponents.getCatalyst();
159+
if(cat2 == null)
160+
test.fail("Expected recipe with no catalyst to be EMPTY, not null");
161+
162+
test.succeed();
153163
}
154164

155165
@GameTest(template = "empty_medium", templateNamespace = CompactCrafting.MOD_ID, prefixTemplateWithClassname = false)
156-
public static void MakesRoundTripThroughNbtCorrectly() {
157-
MiniaturizationRecipe recipe = RecipeTestUtil.getRecipeFromFile("test_data/data/compactcrafting/recipes/compact_walls.json");
158-
if (recipe == null) {
159-
Assertions.fail("No recipe was loaded.");
160-
} else {
161-
DataResult<Tag> dr = MiniaturizationRecipe.CODEC.encodeStart(NbtOps.INSTANCE, recipe);
162-
Optional<Tag> res = dr.resultOrPartial(Assertions::fail);
163-
164-
Tag nbtRecipe = res.get();
165-
166-
MiniaturizationRecipe rFromNbt = MiniaturizationRecipe.CODEC.parse(NbtOps.INSTANCE, nbtRecipe)
167-
.getOrThrow(false, Assertions::fail);
168-
169-
// There should only be two layers loaded from the file
170-
Assertions.assertEquals(2, rFromNbt.getNumberLayers());
171-
172-
Optional<IRecipeLayer> topLayer = rFromNbt.getLayer(1);
173-
if (!topLayer.isPresent()) {
174-
Assertions.fail("No top layer loaded.");
175-
return;
176-
}
177-
178-
IRecipeLayer lay = topLayer.get();
179-
180-
// Top Layer should be a redstone dust, so one 'R' component
181-
Map<String, Integer> componentTotals = lay.getComponentTotals();
182-
Assertions.assertTrue(componentTotals.containsKey("R"), "Expected redstone component in top layer; it does not exist.");
183-
Assertions.assertEquals(1, componentTotals.get("R"), "Expected one redstone required in top layer.");
166+
public static void MakesRoundTripThroughNbtCorrectly(final GameTestHelper test) {
167+
MiniaturizationRecipe recipe = RecipeTestUtil.getRecipeByName(test, "compact_walls").orElseThrow();
168+
DataResult<Tag> dr = MiniaturizationRecipe.CODEC.encodeStart(NbtOps.INSTANCE, recipe);
169+
Optional<Tag> res = dr.resultOrPartial(test::fail);
170+
171+
Tag nbtRecipe = res.get();
172+
173+
MiniaturizationRecipe rFromNbt = MiniaturizationRecipe.CODEC.parse(NbtOps.INSTANCE, nbtRecipe)
174+
.getOrThrow(false, test::fail);
175+
176+
// There should only be two layers loaded from the file
177+
if(2 != rFromNbt.getNumberLayers())
178+
test.fail("Expected 2 layers in recipe.");
179+
180+
Optional<IRecipeLayer> topLayer = rFromNbt.getLayer(1);
181+
if (topLayer.isEmpty()) {
182+
test.fail("No top layer loaded.");
184183
}
184+
185+
IRecipeLayer lay = topLayer.get();
186+
187+
// Top Layer should be a redstone dust, so one 'R' component
188+
Map<String, Integer> componentTotals = lay.getComponentTotals();
189+
if(!componentTotals.containsKey("R"))
190+
test.fail("Expected redstone component in top layer; it does not exist.");
191+
192+
if(1 != componentTotals.get("R"))
193+
test.fail("Expected one redstone required in top layer.");
194+
195+
test.succeed();
185196
}
186197
}

0 commit comments

Comments
 (0)