From c421eed473594427c3e41a0016d094d5e8bb8ada Mon Sep 17 00:00:00 2001 From: Jikoo Date: Mon, 9 Oct 2023 10:41:00 -0400 Subject: [PATCH] Fix tests on recent Bukkit This is a mess, lucky it works at all. --- .../com/github/jikoo/planarwrappers/config/SettingTest.java | 2 -- .../com/github/jikoo/planarwrappers/mock/ServerMocks.java | 5 +++++ .../jikoo/planarwrappers/util/StringConvertersTest.java | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/github/jikoo/planarwrappers/config/SettingTest.java b/src/test/java/com/github/jikoo/planarwrappers/config/SettingTest.java index 20f3f7f..695b3e4 100644 --- a/src/test/java/com/github/jikoo/planarwrappers/config/SettingTest.java +++ b/src/test/java/com/github/jikoo/planarwrappers/config/SettingTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.notNull; import static org.mockito.Mockito.when; import com.github.jikoo.planarwrappers.config.impl.BooleanSetting; @@ -65,7 +64,6 @@ class SettingTest { @BeforeAll void beforeAll() { Server server = ServerMocks.newServer(); - when(server.getRegistry(notNull())).thenReturn(null); when(server.getTag(Tag.REGISTRY_BLOCKS, NamespacedKey.minecraft("wall_signs"), Material.class)) .thenReturn(new Tag<>() { private final Set materials = Set.of(Material.CRIMSON_WALL_SIGN, Material.WARPED_WALL_SIGN); diff --git a/src/test/java/com/github/jikoo/planarwrappers/mock/ServerMocks.java b/src/test/java/com/github/jikoo/planarwrappers/mock/ServerMocks.java index 54a7e1c..61b003f 100644 --- a/src/test/java/com/github/jikoo/planarwrappers/mock/ServerMocks.java +++ b/src/test/java/com/github/jikoo/planarwrappers/mock/ServerMocks.java @@ -1,13 +1,16 @@ package com.github.jikoo.planarwrappers.mock; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.lang.reflect.Field; import java.util.logging.Logger; import org.bukkit.Bukkit; +import org.bukkit.Registry; import org.bukkit.Server; import org.jetbrains.annotations.NotNull; +import org.mockito.ArgumentMatchers; public final class ServerMocks { @@ -18,6 +21,8 @@ public final class ServerMocks { when(mock.getLogger()).thenReturn(noOp); when(mock.isPrimaryThread()).thenReturn(true); + doAnswer(invocation -> mock(Registry.class)).when(mock).getRegistry(ArgumentMatchers.notNull()); + return mock; } diff --git a/src/test/java/com/github/jikoo/planarwrappers/util/StringConvertersTest.java b/src/test/java/com/github/jikoo/planarwrappers/util/StringConvertersTest.java index d0c8364..5e32c62 100644 --- a/src/test/java/com/github/jikoo/planarwrappers/util/StringConvertersTest.java +++ b/src/test/java/com/github/jikoo/planarwrappers/util/StringConvertersTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.ArgumentMatchers.notNull; import static org.mockito.Mockito.when; import com.github.jikoo.planarwrappers.mock.ServerMocks; @@ -30,7 +29,6 @@ class StringConvertersTest { @BeforeAll void beforeAll() { Server server = ServerMocks.newServer(); - when(server.getRegistry(notNull())).thenReturn(null); when(server.getTag(Tag.REGISTRY_BLOCKS, NamespacedKey.minecraft("wall_signs"), Material.class)) .thenReturn(new Tag<>() { private final Set materials = Set.of(Material.CRIMSON_WALL_SIGN, Material.WARPED_WALL_SIGN);