|
1 | 1 | package com.skyblockexp.ezrtp.platform; |
2 | 2 |
|
| 3 | +import org.bukkit.Location; |
3 | 4 | import org.bukkit.Server; |
| 5 | +import org.bukkit.entity.Player; |
4 | 6 | import org.bukkit.plugin.Plugin; |
5 | 7 | import org.bukkit.scheduler.BukkitScheduler; |
6 | 8 | import org.bukkit.scheduler.BukkitTask; |
|
14 | 16 |
|
15 | 17 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
16 | 18 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 19 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
17 | 20 | import static org.mockito.ArgumentMatchers.any; |
18 | 21 | import static org.mockito.ArgumentMatchers.anyLong; |
19 | 22 | import static org.mockito.ArgumentMatchers.eq; |
@@ -175,4 +178,42 @@ void executeRegionDelayed_withFoliaCapabilities_doesNotThrow() { |
175 | 178 |
|
176 | 179 | assertDoesNotThrow(() -> scheduler.executeRegionDelayed(null, 0, 0, () -> {}, 20L)); |
177 | 180 | } |
| 181 | + |
| 182 | + // --- teleportAsync --- |
| 183 | + |
| 184 | + /** |
| 185 | + * On Folia (regionized), teleportAsync must not call the synchronous Player.teleport(). |
| 186 | + * Since Player.teleportAsync() is not available in the test JVM, the reflection path |
| 187 | + * falls through to the sync fallback. This test verifies the method does not throw and |
| 188 | + * returns a completed future. |
| 189 | + */ |
| 190 | + @Test |
| 191 | + void teleportAsync_withFoliaCapabilities_doesNotThrow() { |
| 192 | + Player player = mock(Player.class); |
| 193 | + Location destination = mock(Location.class); |
| 194 | + when(player.teleport(destination)).thenReturn(true); |
| 195 | + |
| 196 | + BukkitPlatformScheduler scheduler = |
| 197 | + new BukkitPlatformScheduler(plugin, PlatformRuntimeCapabilities.PAPER_FOLIA); |
| 198 | + |
| 199 | + assertDoesNotThrow(() -> scheduler.teleportAsync(player, destination)); |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * On standard Bukkit, teleportAsync delegates to the synchronous Player.teleport(). |
| 204 | + */ |
| 205 | + @Test |
| 206 | + void teleportAsync_withBukkitCapabilities_callsSyncTeleport() throws Exception { |
| 207 | + Player player = mock(Player.class); |
| 208 | + Location destination = mock(Location.class); |
| 209 | + when(player.teleport(destination)).thenReturn(true); |
| 210 | + |
| 211 | + BukkitPlatformScheduler scheduler = |
| 212 | + new BukkitPlatformScheduler(plugin, PlatformRuntimeCapabilities.BUKKIT); |
| 213 | + |
| 214 | + Boolean result = scheduler.teleportAsync(player, destination).get(); |
| 215 | + |
| 216 | + assertTrue(result); |
| 217 | + verify(player).teleport(destination); |
| 218 | + } |
178 | 219 | } |
0 commit comments