Skip to content

Commit 26616f1

Browse files
committed
Migrate tests to use JUnit 5
1 parent 8e22b15 commit 26616f1

File tree

9 files changed

+90
-101
lines changed

9 files changed

+90
-101
lines changed

dependencies.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
* For more details, see https://docs.gradle.org/8.4/userguide/java_library_plugin.html#sec:java_library_configurations_graph
3939
*/
4040
dependencies {
41-
// Existing tests are written in JUnit 4
42-
testImplementation("junit:junit:4.13.1")
43-
4441
compileOnly rfg.deobf("curse.maven:forestry-59751:2684780") // Forestry 5.8.2.387
4542
api rfg.deobf("codechicken:ChickenASM:1.12-1.0.2.9")
4643
api("codechicken:codechickenlib:3.2.3.358")

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ enableSpotless = false
163163

164164
# Enable JUnit testing platform used for testing your code.
165165
# Uses JUnit 5. See guide and documentation here: https://junit.org/junit5/docs/current/user-guide/
166-
enableJUnit = false
166+
enableJUnit = true
167167

168168
# Deployment debug setting
169169
# Uncomment this to test deployments to CurseForge and Modrinth

src/test/java/gregtech/api/capability/impl/AbstractRecipeLogicTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import net.minecraft.tileentity.TileEntity;
1212
import net.minecraft.util.*;
1313
import net.minecraft.world.World;
14-
import org.junit.*;
14+
import org.junit.jupiter.api.*;
1515

16-
import static org.junit.Assert.*;
16+
import static org.junit.jupiter.api.Assertions.*;
1717

1818
public class AbstractRecipeLogicTest {
1919

20-
@BeforeClass
20+
@BeforeAll
2121
public static void init() {
2222
Bootstrap.register();
2323
}

src/test/java/gregtech/api/capability/impl/MultiblockRecipeLogicTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,22 @@
1616
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityItemBus;
1717
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityMultiblockPart;
1818
import gregtech.common.metatileentities.multi.electric.MetaTileEntityElectricBlastFurnace;
19-
import net.minecraft.block.state.IBlockState;
2019
import net.minecraft.init.Blocks;
2120
import net.minecraft.init.Bootstrap;
2221
import net.minecraft.item.ItemStack;
2322
import net.minecraft.util.ResourceLocation;
2423
import net.minecraft.world.World;
2524
import net.minecraftforge.items.IItemHandlerModifiable;
2625

27-
import org.junit.BeforeClass;
28-
import org.junit.Test;
26+
import org.junit.jupiter.api.*;
2927

3028
import java.lang.reflect.Field;
3129

32-
import static org.junit.Assert.*;
33-
import static org.junit.Assert.assertTrue;
30+
import static org.junit.jupiter.api.Assertions.*;
3431

3532
public class MultiblockRecipeLogicTest {
3633

37-
@BeforeClass
34+
@BeforeAll
3835
public static void init() {
3936
Bootstrap.register();
4037
}

src/test/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorageTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import com.google.common.collect.ImmutableMap;
44
import gregtech.api.util.GTLog;
55
import org.apache.logging.log4j.LogManager;
6-
import org.junit.Before;
7-
import org.junit.BeforeClass;
8-
import org.junit.Test;
6+
import org.junit.jupiter.api.*;
97

108
import java.util.*;
119

12-
import static org.junit.Assert.*;
10+
import static org.junit.jupiter.api.Assertions.*;
1311

1412
public class RecipePropertyStorageTest {
1513
private static final String propInt1Key = "propInt1";
@@ -21,12 +19,12 @@ public class RecipePropertyStorageTest {
2119

2220
private RecipePropertyStorage storage;
2321

24-
@BeforeClass
22+
@BeforeAll
2523
public static void initTestClassStub() {
2624
GTLog.init(LogManager.getLogger(RecipePropertyStorageTest.class));
2725
}
2826

29-
@Before
27+
@BeforeEach
3028
public void initTestStub() {
3129
this.storage = new RecipePropertyStorage();
3230
}

src/test/java/gregtech/api/util/InventoryUtilsTest.java

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,23 @@
44
import net.minecraft.item.*;
55
import net.minecraft.nbt.*;
66
import net.minecraftforge.items.*;
7-
import org.junit.*;
8-
import org.junit.rules.*;
7+
import org.junit.jupiter.api.*;
98

109
import java.util.*;
1110

12-
import static org.junit.Assert.*;
11+
import static org.junit.jupiter.api.Assertions.*;
1312

1413
public class InventoryUtilsTest
1514
{
1615
/**
1716
* Required. Without this all item-related operations will fail because registries haven't been initialized.
1817
*/
19-
@BeforeClass
18+
@BeforeAll
2019
public static void bootStrap()
2120
{
2221
Bootstrap.register();
2322
}
2423

25-
/**
26-
* Used by tests where exception properties need to be verified.
27-
*/
28-
@Rule
29-
public ExpectedException thrown = ExpectedException.none();
30-
3124
@Test
3225
public void simulateItemStackMerge_succeeds_for_inserting_single_stack_into_empty_one_slot_inventory()
3326
{
@@ -41,8 +34,8 @@ public void simulateItemStackMerge_succeeds_for_inserting_single_stack_into_empt
4134
);
4235

4336
assertTrue(
44-
"Merging one full stack into a single empty slot failed.",
45-
result
37+
result,
38+
"Merging one full stack into a single empty slot failed."
4639
);
4740
}
4841

@@ -59,8 +52,8 @@ public void simulateItemStackMerge_succeeds_for_inserting_two_half_stacks_into_e
5952
);
6053

6154
assertTrue(
62-
"Merging two half-stacks into an empty inventory with one slot failed.",
63-
result
55+
result,
56+
"Merging two half-stacks into an empty inventory with one slot failed."
6457
);
6558
}
6659

@@ -79,8 +72,8 @@ public void simulateItemStackMerge_succeeds_for_inserting_one_half_stack_into_in
7972
);
8073

8174
assertTrue(
82-
"Merging half a stack into an inventory with one slot containing half a stack of the same item failed.",
83-
result
75+
result,
76+
"Merging half a stack into an inventory with one slot containing half a stack of the same item failed."
8477
);
8578
}
8679

@@ -101,8 +94,8 @@ public void simulateItemStackMerge_succeeds_for_inserting_one_half_stack_into_in
10194
);
10295

10396
assertTrue(
104-
"Merging half a stack into an inventory with two three-quarter stacks of the same item failed.",
105-
result
97+
result,
98+
"Merging half a stack into an inventory with two three-quarter stacks of the same item failed."
10699
);
107100
}
108101

@@ -123,8 +116,8 @@ public void simulateItemStackMerge_succeeds_for_inserting_one_half_stack_into_in
123116
);
124117

125118
assertTrue(
126-
"Merging half a stack into an inventory with one three-quarter stack of the same item and one empty slot failed.",
127-
result
119+
result,
120+
"Merging half a stack into an inventory with one three-quarter stack of the same item and one empty slot failed."
128121
);
129122
}
130123

@@ -144,8 +137,8 @@ public void simulateItemStackMerge_fails_to_insert_items_into_a_full_inventory_w
144137
);
145138

146139
assertFalse(
147-
"Unexpectedly succeeded at merging an arrow into an inventory full of feathers.",
148-
result
140+
result,
141+
"Unexpectedly succeeded at merging an arrow into an inventory full of feathers."
149142
);
150143
}
151144

@@ -165,8 +158,8 @@ public void simulateItemStackMerge_fails_to_insert_items_into_a_full_inventory_w
165158
);
166159

167160
assertFalse(
168-
"Unexpectedly succeeded at merging feathers into an inventory full of feathers.",
169-
result
161+
result,
162+
"Unexpectedly succeeded at merging feathers into an inventory full of feathers."
170163
);
171164
}
172165

@@ -187,8 +180,8 @@ public void simulateItemStackMerge_respects_different_NBT_tags_as_different_item
187180
);
188181

189182
assertFalse(
190-
"Unexpectedly succeeded at merging feathers with NBT tags into a stack of plain feathers.",
191-
result
183+
result,
184+
"Unexpectedly succeeded at merging feathers with NBT tags into a stack of plain feathers."
192185
);
193186
}
194187

@@ -209,8 +202,8 @@ public void simulateItemStackMerge_respects_different_damage_values_as_different
209202
);
210203

211204
assertFalse(
212-
"Unexpectedly succeeded at merging damaged feathers into a stack of plain feathers.",
213-
result
205+
result,
206+
"Unexpectedly succeeded at merging damaged feathers into a stack of plain feathers."
214207
);
215208
}
216209

@@ -232,8 +225,8 @@ public void simulateItemStackMerge_respects_unstackable_but_otherwise_identical_
232225
);
233226

234227
assertFalse(
235-
"Unexpectedly succeeded at merging a pickaxe into another one.",
236-
result
228+
result,
229+
"Unexpectedly succeeded at merging a pickaxe into another one."
237230
);
238231
}
239232

@@ -242,8 +235,8 @@ public void normalizeItemStack_returns_empty_list_for_single_empty_stack()
242235
{
243236
List<ItemStack> result = InventoryUtils.normalizeItemStack(ItemStack.EMPTY);
244237
assertTrue(
245-
"Unexpectedly got results when normalizing an empty ItemStack",
246-
result.isEmpty()
238+
result.isEmpty(),
239+
"Unexpectedly got results when normalizing an empty ItemStack"
247240
);
248241
}
249242

@@ -254,16 +247,16 @@ public void normalizeItemStack_returns_single_element_list_for_a_single_already_
254247
List<ItemStack> result = InventoryUtils.normalizeItemStack(stack);
255248

256249
assertFalse(
257-
"Unexpectedly got no results when normalizing an already normal ItemStack",
258-
result.isEmpty()
250+
result.isEmpty(),
251+
"Unexpectedly got no results when normalizing an already normal ItemStack"
259252
);
260253
assertEquals(
261-
"Unexpectedly got wrong number of resulting stacks when normalizing an already normal ItemStack",
262-
1, result.size()
254+
1, result.size(),
255+
"Unexpectedly got wrong number of resulting stacks when normalizing an already normal ItemStack"
263256
);
264257
assertTrue(
265-
"ItemStack was modified when it didn't need to be",
266-
ItemStack.areItemStacksEqual(stack, result.get(0))
258+
ItemStack.areItemStacksEqual(stack, result.get(0)),
259+
"ItemStack was modified when it didn't need to be"
267260
);
268261
}
269262

@@ -274,46 +267,49 @@ public void normalizeItemStack_returns_normalized_stacks_for_an_abnormal_stack()
274267
List<ItemStack> result = InventoryUtils.normalizeItemStack(stack);
275268

276269
assertFalse(
277-
"Unexpectedly got no results when normalizing an abnormal stack",
278-
result.isEmpty()
270+
result.isEmpty(),
271+
"Unexpectedly got no results when normalizing an abnormal stack"
279272
);
280273
assertEquals(
281-
"Unexpectedly got wrong number of resulting stacks when normalizing an abnormal ItemStack",
282-
3, result.size()
274+
3, result.size(),
275+
"Unexpectedly got wrong number of resulting stacks when normalizing an abnormal ItemStack"
283276
);
284277

285278
ItemStack expectedFull = new ItemStack(Items.ENDER_PEARL, 16);
286279
ItemStack expectedPartial = new ItemStack(Items.ENDER_PEARL, 13);
287-
assertTrue("First item stack does not match expected full stack",
288-
ItemStack.areItemStacksEqual(expectedFull, result.get(0)));
289-
assertTrue("Second item stack does not match expected full stack",
290-
ItemStack.areItemStacksEqual(expectedFull, result.get(1)));
291-
assertTrue("Third item stack does not match expected partial stack",
292-
ItemStack.areItemStacksEqual(expectedPartial, result.get(2)));
280+
assertTrue(ItemStack.areItemStacksEqual(expectedFull, result.get(0)),
281+
"First item stack does not match expected full stack");
282+
assertTrue(ItemStack.areItemStacksEqual(expectedFull, result.get(1)),
283+
"Second item stack does not match expected full stack");
284+
assertTrue(ItemStack.areItemStacksEqual(expectedPartial, result.get(2)),
285+
"Third item stack does not match expected partial stack");
293286
}
294287

295288
@Test
296289
public void apportionStack_throws_AssertionError_when_supplied_stack_is_empty()
297290
{
298-
thrown.expect(IllegalArgumentException.class);
299-
thrown.expectMessage("Cannot apportion an empty stack.");
300-
InventoryUtils.apportionStack(ItemStack.EMPTY, 64);
291+
IllegalArgumentException e =
292+
assertThrows(IllegalArgumentException.class,
293+
() -> InventoryUtils.apportionStack(ItemStack.EMPTY, 64));
294+
assertEquals("Cannot apportion an empty stack.", e.getMessage());
301295
}
302296

303297
@Test
304298
public void apportionStack_throws_AssertionError_when_maxCount_is_zero()
305299
{
306-
thrown.expect(IllegalArgumentException.class);
307-
thrown.expectMessage("Count must be non-zero and positive.");
308-
InventoryUtils.apportionStack(new ItemStack(Items.ARROW, 1), 0);
300+
IllegalArgumentException e =
301+
assertThrows(IllegalArgumentException.class,
302+
() -> InventoryUtils.apportionStack(new ItemStack(Items.ARROW, 1), 0));
303+
assertEquals("Count must be non-zero and positive.", e.getMessage());
309304
}
310305

311306
@Test
312307
public void apportionStack_throws_AssertionError_when_maxCount_is_negative()
313308
{
314-
thrown.expect(IllegalArgumentException.class);
315-
thrown.expectMessage("Count must be non-zero and positive.");
316-
InventoryUtils.apportionStack(new ItemStack(Items.ARROW, 1), -1);
309+
IllegalArgumentException e =
310+
assertThrows(IllegalArgumentException.class,
311+
() -> InventoryUtils.apportionStack(new ItemStack(Items.ARROW, 1), -1));
312+
assertEquals("Count must be non-zero and positive.", e.getMessage());
317313
}
318314

319315
@Test

0 commit comments

Comments
 (0)