44import net .minecraft .item .*;
55import net .minecraft .nbt .*;
66import net .minecraftforge .items .*;
7- import org .junit .*;
8- import org .junit .rules .*;
7+ import org .junit .jupiter .api .*;
98
109import java .util .*;
1110
12- import static org .junit .Assert .*;
11+ import static org .junit .jupiter . api . Assertions .*;
1312
1413public 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