From 5fca5b18b8e5b89acf29a8703418f719e59ddcef Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 31 Aug 2023 22:58:33 +0800 Subject: [PATCH] Remove from commands and add to tests --- .../commands/CreateCommand.java | 8 +----- .../commands/DeleteCommand.java | 6 +--- .../multiverse/core/world/WorldManagerTest.kt | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/test/java/org/mvplugins/multiverse/core/world/WorldManagerTest.kt diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index f5ee8c81..271c61f5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -26,7 +26,6 @@ import com.onarandombox.MultiverseCore.commandtools.flags.CommandValueFlag; import com.onarandombox.MultiverseCore.commandtools.flags.ParsedCommandFlags; import com.onarandombox.MultiverseCore.utils.MVCorei18n; import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper; -import com.onarandombox.MultiverseCore.worldnew.WorldManager; import jakarta.inject.Inject; import org.bukkit.Bukkit; import org.bukkit.World; @@ -40,19 +39,16 @@ import org.jvnet.hk2.annotations.Service; public class CreateCommand extends MultiverseCommand { private final MVWorldManager worldManager; - private final WorldManager newWorldManager; @Inject public CreateCommand( @NotNull MVCommandManager commandManager, @NotNull MVWorldManager worldManager, - @NotNull UnsafeCallWrapper unsafeCallWrapper, - @NotNull WorldManager newWorldManager + @NotNull UnsafeCallWrapper unsafeCallWrapper ) { super(commandManager); this.worldManager = worldManager; - this.newWorldManager = newWorldManager; registerFlagGroup(CommandFlagGroup.builder("mvcreate") .add(CommandValueFlag.builder("--seed", String.class) @@ -116,8 +112,6 @@ public class CreateCommand extends MultiverseCommand { issuer.sendInfo(MVCorei18n.CREATE_LOADING); - newWorldManager.addWorld(worldName); - if (!worldManager.addWorld( worldName, environment, diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java index ca6c767b..0dfe37f9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java @@ -15,7 +15,6 @@ import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand; import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand; import com.onarandombox.MultiverseCore.utils.MVCorei18n; -import com.onarandombox.MultiverseCore.worldnew.WorldManager; import jakarta.inject.Inject; import org.jetbrains.annotations.NotNull; import org.jvnet.hk2.annotations.Service; @@ -25,13 +24,11 @@ import org.jvnet.hk2.annotations.Service; public class DeleteCommand extends MultiverseCommand { private final MVWorldManager worldManager; - private final WorldManager newWorldManager; @Inject - public DeleteCommand(@NotNull MVCommandManager commandManager, @NotNull MVWorldManager worldManager, @NotNull WorldManager newWorldManager) { + public DeleteCommand(@NotNull MVCommandManager commandManager, @NotNull MVWorldManager worldManager) { super(commandManager); this.worldManager = worldManager; - this.newWorldManager = newWorldManager; } @Subcommand("delete") @@ -51,7 +48,6 @@ public class DeleteCommand extends MultiverseCommand { issuer.getIssuer(), () -> { issuer.sendInfo(MVCorei18n.DELETE_DELETING, "{world}", worldName); - this.newWorldManager.deleteWorld(worldName); if (!this.worldManager.deleteWorld(worldName)) { issuer.sendError(MVCorei18n.DELETE_FAILED, "{world}", worldName); return; diff --git a/src/test/java/org/mvplugins/multiverse/core/world/WorldManagerTest.kt b/src/test/java/org/mvplugins/multiverse/core/world/WorldManagerTest.kt new file mode 100644 index 00000000..0fd856cd --- /dev/null +++ b/src/test/java/org/mvplugins/multiverse/core/world/WorldManagerTest.kt @@ -0,0 +1,28 @@ +package org.mvplugins.multiverse.core.world + +import com.onarandombox.MultiverseCore.worldnew.WorldManager +import org.mvplugins.multiverse.core.TestWithMockBukkit +import kotlin.test.BeforeTest +import kotlin.test.Test + +class WorldManagerTest : TestWithMockBukkit() { + private lateinit var worldManager: WorldManager + + @BeforeTest + fun setUp() { + worldManager = multiverseCore.getService(WorldManager::class.java).takeIf { it != null } ?: run { + throw IllegalStateException("WorldManager is not available as a service") } + } + + @Test + fun `Add world`() { + worldManager.addWorld("world") + // TODO: When logic is implemented, check that the world is added + } + + @Test + fun `Delete world`() { + worldManager.deleteWorld("world") + // TODO: When logic is implemented, check that the world is removed + } +}