I'm trying to test my Minecraft plugin with MockBukkit, but when I'm trying to mock a server (via MockBukkit#mock()
) a NPE is thrown:
java.lang.NullPointerException: Cannot invoke "org.eclipse.aether.RepositorySystem.newLocalRepositoryManager(org.eclipse.aether.RepositorySystemSession, org.eclipse.aether.repository.LocalRepository)" because "this.repository" is null
at org.bukkit.plugin.java.LibraryLoader.<init>(LibraryLoader.java:59)
at org.bukkit.plugin.java.JavaPluginLoader.<init>(JavaPluginLoader.java:73)
at be.seeseemelk.mockbukkit.plugin.PluginManagerMock.<init>(PluginManagerMock.java:90)
at be.seeseemelk.mockbukkit.ServerMock.<init>(ServerMock.java:166)
at be.seeseemelk.mockbukkit.MockBukkit.mock(MockBukkit.java:56)
Here you can find my pom.xml: https://pastebin.com/TPjDRr9f
My test contains just a method with the annotation @BeforeAll
in which I mock via MockBukkit#mock()
. This issue is also mentioned here https://github.com/MockBukkit/MockBukkit/issues/614, but this issue is currently in backlog, so I'm trying to find a solution / workaround for this.
I tried mocking the server in a test method with the annotation @BeforeAll
:
@BeforeAll
public void setUp() {
MockBukkit.mock();
}
I expected the test to work.
I actually got a NPE, which origin's located in the MockBukkit code.
CodePudding user response:
So I finally managed to fix this error: it occured because of this dependency:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.4</version>
</dependency>
Watch this for updates: https://github.com/MockBukkit/MockBukkit/issues/614