Expected behavior
When running new ItemStack(Material.BARRIER) in code in a JUnit test it will not throw an error: java.lang.IllegalArgumentException: BARRIER isn't an item
Observed/Actual behavior
Hi - I'm in the process of shifting BentoBox to PaperAPI fully and trying to get all the JUnit tests to run.
One of the issues I'm hitting is with this code: new ItemStack(Material.BARRIER) where, when run, will throw an error in the JUnit test: java.lang.IllegalArgumentException: BARRIER isn't an item. Barrier is just an example - it happens when trying to create any ItemStack with any Material.
This is thrown by a check that is done in ItemStack.java:
Preconditions.checkArgument(type.asItemType() != null, type + " isn't an item");
Indeed, if I put debug code before the new ItemStack is created:
System.out.println(Material.BARRIER.isItem()); it returns false, so I'm not surprised that this is being thrown.
Stack trace of error:
java.lang.IllegalArgumentException: BARRIER isn't an item
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143)
at org.bukkit.inventory.ItemStack.of(ItemStack.java:58)
at org.bukkit.inventory.ItemStack.<init>(ItemStack.java:138)
at org.bukkit.inventory.ItemStack.<init>(ItemStack.java:117)
at org.bukkit.inventory.ItemStack.<init>(ItemStack.java:104)
at org.bukkit.inventory.ItemStack.<init>(ItemStack.java:87)
at world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteGUI.getBlankBorder(IslandTeamInviteGUI.java:164)
at world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteGUI.createPreviousButton(IslandTeamInviteGUI.java:159)
at world.bentobox.bentobox.api.panels.TemplatedPanel.makeAddonButton(TemplatedPanel.java:295)
at world.bentobox.bentobox.api.panels.TemplatedPanel.makeButton(TemplatedPanel.java:248)
at world.bentobox.bentobox.api.panels.TemplatedPanel.processItemData(TemplatedPanel.java:126)
at world.bentobox.bentobox.api.panels.TemplatedPanel.populateInventoryPanel(TemplatedPanel.java:81)
at world.bentobox.bentobox.api.panels.TemplatedPanel.generatePanel(TemplatedPanel.java:61)
at world.bentobox.bentobox.api.panels.TemplatedPanel.<init>(TemplatedPanel.java:52)
at world.bentobox.bentobox.api.panels.builders.TemplatedPanelBuilder.build(TemplatedPanelBuilder.java:150)
at world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteGUI.build(IslandTeamInviteGUI.java:85)
at world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteCommand.canExecute(IslandTeamInviteCommand.java:63)
at world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteCommandTest.testCanExecuteNoTarget(IslandTeamInviteCommandTest.java:236)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:326)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:89)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:310)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:131)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.access$100(PowerMockJUnit47RunnerDelegateImpl.java:59)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner$TestExecutorStatement.evaluate(PowerMockJUnit47RunnerDelegateImpl.java:147)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:298)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:218)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:160)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:134)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:136)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:117)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:57)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:530)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:758)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:453)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:211)
Steps/models to reproduce
- Clone BentoBox https://github.com/BentoBoxWorld/BentoBox.git
- Edit
src/test/java/world/bentobox/bentobox/api/commands/island/team /IslandTeamInviteCommandTest.java
- Comment out
@Ignore("PaperAPI Material issue with Material.get") line so the test will attempt to run. (BTW, this is just one example - the issue is common).
- Compile with tests (Maven so /mvn)
- It should compile except for this one test error. It may take a while because we have a lot of tests.
Plugin and Datapack List
BentoBox
Paper version
> version
[10:13:55 INFO]: Checking version, please wait...
[10:13:56 INFO]: This server is running Paper version 1.21.4-68-main@9298f59 (2024-12-30T20:42:05Z) (Implementing API version 1.21.4-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.4-66-d00344a (MC: 1.21.4)
Other
In order to run tests, I do have to mock up a Server, which I have enhanced to support the Paper registries, etc. It is at src/test/java/world/bentobox/bentobox/mocks/ServerMocks.java. Maybe I need some code in there to make this work in ItemType, not sure. Any help would be really appreciated. This code is used on a lot of the BentoBox projects now.
I have tried mocking up ItemStack itself, but no luck. The item check code still runs and errors.
I realize this is quite advanced test fu, but I'm blocked on testing a lot of code if ItemStacks can't work. I have a feeling there's something I'm missing when it comes to mocking up the various bits.
Expected behavior
When running
new ItemStack(Material.BARRIER)in code in a JUnit test it will not throw an error:java.lang.IllegalArgumentException: BARRIER isn't an itemObserved/Actual behavior
Hi - I'm in the process of shifting BentoBox to PaperAPI fully and trying to get all the JUnit tests to run.
One of the issues I'm hitting is with this code:
new ItemStack(Material.BARRIER)where, when run, will throw an error in the JUnit test:java.lang.IllegalArgumentException: BARRIER isn't an item. Barrier is just an example - it happens when trying to create any ItemStack with any Material.This is thrown by a check that is done in ItemStack.java:
Preconditions.checkArgument(type.asItemType() != null, type + " isn't an item");Indeed, if I put debug code before the new ItemStack is created:
System.out.println(Material.BARRIER.isItem());it returnsfalse, so I'm not surprised that this is being thrown.Stack trace of error:
Steps/models to reproduce
src/test/java/world/bentobox/bentobox/api/commands/island/team /IslandTeamInviteCommandTest.java@Ignore("PaperAPI Material issue with Material.get")line so the test will attempt to run. (BTW, this is just one example - the issue is common).Plugin and Datapack List
BentoBox
Paper version
Other
In order to run tests, I do have to mock up a Server, which I have enhanced to support the Paper registries, etc. It is at
src/test/java/world/bentobox/bentobox/mocks/ServerMocks.java. Maybe I need some code in there to make this work in ItemType, not sure. Any help would be really appreciated. This code is used on a lot of the BentoBox projects now.I have tried mocking up ItemStack itself, but no luck. The item check code still runs and errors.
I realize this is quite advanced test fu, but I'm blocked on testing a lot of code if ItemStacks can't work. I have a feeling there's something I'm missing when it comes to mocking up the various bits.