|
@@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.levelup;
|
|
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.MINING;
|
|
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.MINING;
|
|
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.WOODCUTTING;
|
|
import static com.gmail.nossr50.datatypes.skills.PrimarySkillType.WOODCUTTING;
|
|
import static java.util.Objects.requireNonNull;
|
|
import static java.util.Objects.requireNonNull;
|
|
|
|
+import static java.util.logging.Logger.getLogger;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.Mockito.atLeast;
|
|
import static org.mockito.Mockito.atLeast;
|
|
@@ -12,41 +13,72 @@ import static org.mockito.Mockito.never;
|
|
import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
|
|
-import com.gmail.nossr50.MMOTestEnvironmentBasic;
|
|
|
|
|
|
+import com.gmail.nossr50.MMOTestEnvironment;
|
|
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
|
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
|
import com.gmail.nossr50.datatypes.experience.XPGainSource;
|
|
import com.gmail.nossr50.datatypes.experience.XPGainSource;
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
|
|
|
+import com.gmail.nossr50.events.experience.McMMOPlayerPreXpGainEvent;
|
|
|
|
+import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
|
|
|
|
+import com.gmail.nossr50.listeners.SelfListener;
|
|
import com.gmail.nossr50.mcMMO;
|
|
import com.gmail.nossr50.mcMMO;
|
|
-import com.gmail.nossr50.util.EventUtils;
|
|
|
|
|
|
+import com.gmail.nossr50.util.TestPlayerMock;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
import java.util.function.BiPredicate;
|
|
import java.util.function.BiPredicate;
|
|
import java.util.function.Predicate;
|
|
import java.util.function.Predicate;
|
|
|
|
+import java.util.logging.Logger;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Bukkit;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
+import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.Mockito;
|
|
import org.mockito.Mockito;
|
|
|
|
|
|
-class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
|
|
|
|
+class LevelUpCommandTest extends MMOTestEnvironment {
|
|
|
|
+ private static final Logger logger = getLogger(LevelUpCommandTest.class.getName());
|
|
private static final BiPredicate<PrimarySkillType, Integer> ALWAYS_TRUE = (skill, level) -> true;
|
|
private static final BiPredicate<PrimarySkillType, Integer> ALWAYS_TRUE = (skill, level) -> true;
|
|
- private McMMOPlayer mmoPlayer;
|
|
|
|
- private final String playerName = "Momshroom";
|
|
|
|
|
|
+ private static final String DEFAULT_PLAYER_NAME = "Momshroom";
|
|
|
|
+ private SelfListener selfListener;
|
|
|
|
|
|
@BeforeEach
|
|
@BeforeEach
|
|
void beforeEach() {
|
|
void beforeEach() {
|
|
|
|
+ mockBaseEnvironment(logger);
|
|
mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().clear();
|
|
mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().clear();
|
|
|
|
|
|
- this.mmoPlayer = getMMOPlayer(UUID.randomUUID(), playerName, 0);
|
|
|
|
|
|
+ // Self listener
|
|
|
|
+ selfListener = Mockito.spy(new SelfListener(mcMMO.p));
|
|
|
|
+
|
|
|
|
+ // Process level up events in our self listener
|
|
|
|
+ Mockito.doAnswer(invocation -> {
|
|
|
|
+ selfListener.onPlayerLevelUp(invocation.getArgument(0));
|
|
|
|
+ return null;
|
|
|
|
+ }).when(pluginManager).callEvent(any(McMMOPlayerLevelUpEvent.class));
|
|
|
|
+
|
|
|
|
+ Mockito.doAnswer(invocation -> {
|
|
|
|
+ selfListener.onPlayerXpGain(invocation.getArgument(0));
|
|
|
|
+ return null;
|
|
|
|
+ }).when(pluginManager).callEvent(any(McMMOPlayerXpGainEvent.class));
|
|
|
|
+
|
|
|
|
+ Mockito.doAnswer(invocation -> {
|
|
|
|
+ return invocation.getArgument(0);
|
|
|
|
+ }).when(pluginManager).callEvent(any(McMMOPlayerPreXpGainEvent.class));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @AfterEach
|
|
|
|
+ void tearDown() {
|
|
|
|
+ cleanUpStaticMocks();
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
void skillLevelUpShouldRunFiveTimes() {
|
|
void skillLevelUpShouldRunFiveTimes() {
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
final String commandStr = "say hello";
|
|
final String commandStr = "say hello";
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
(skill, skillLevel) -> skill == MINING && skillLevel >= 1 && skillLevel <= 5);
|
|
(skill, skillLevel) -> skill == MINING && skillLevel >= 1 && skillLevel <= 5);
|
|
@@ -65,37 +97,39 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), any()), atLeast(5));
|
|
mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), any()), atLeast(5));
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
- void dualRequirementsShouldRunOnce() {
|
|
|
|
- // GIVEN
|
|
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
- final String commandStr = "say hello";
|
|
|
|
- BiPredicate<PrimarySkillType, Integer> predicate = (skill, skillLevel) -> skill == MINING
|
|
|
|
- && skillLevel == 3;
|
|
|
|
- BiPredicate<PrimarySkillType, Integer> predicate2 = (skill, skillLevel) ->
|
|
|
|
- skill == WOODCUTTING && skillLevel == 3;
|
|
|
|
- final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
|
|
- List.of(predicate, predicate2));
|
|
|
|
-
|
|
|
|
- mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
|
|
-
|
|
|
|
- // WHEN player gains 5 levels in mining and woodcutting via command
|
|
|
|
- levelPlayerViaXP(mmoPlayer, MINING, 5);
|
|
|
|
- levelPlayerViaXP(mmoPlayer, WOODCUTTING, 5);
|
|
|
|
-
|
|
|
|
- // THEN the command should be checked for execution
|
|
|
|
- verify(levelUpCommandManager, atLeastOnce()).applySkillLevelUp(any(), any(), any(), any());
|
|
|
|
- verify(levelUpCommand, times(10)).process(any(), any(), any(), any());
|
|
|
|
-
|
|
|
|
- // THEN the command should have executed
|
|
|
|
- verify(levelUpCommand, times(1)).executeCommand(any(McMMOPlayer.class));
|
|
|
|
- mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), any()), atLeast(1));
|
|
|
|
- }
|
|
|
|
|
|
+// @Test
|
|
|
|
+// void dualRequirementsShouldRunOnce() {
|
|
|
|
+// // GIVEN
|
|
|
|
+// final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+// final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
|
|
+// final String commandStr = "say hello";
|
|
|
|
+// BiPredicate<PrimarySkillType, Integer> predicate = (skill, skillLevel) -> skill == MINING
|
|
|
|
+// && skillLevel == 3;
|
|
|
|
+// BiPredicate<PrimarySkillType, Integer> predicate2 = (skill, skillLevel) ->
|
|
|
|
+// skill == WOODCUTTING && skillLevel == 3;
|
|
|
|
+// final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
|
|
+// List.of(predicate, predicate2));
|
|
|
|
+//
|
|
|
|
+// mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
|
|
+//
|
|
|
|
+// // WHEN player gains 5 levels in mining and woodcutting via command
|
|
|
|
+// levelPlayerViaXP(mmoPlayer, MINING, 5);
|
|
|
|
+// levelPlayerViaXP(mmoPlayer, WOODCUTTING, 5);
|
|
|
|
+//
|
|
|
|
+// // THEN the command should be checked for execution
|
|
|
|
+// verify(levelUpCommandManager, times(10)).applySkillLevelUp(any(), any(), any(), any());
|
|
|
|
+// verify(levelUpCommand, times(10)).process(any(), any(), any(), any());
|
|
|
|
+//
|
|
|
|
+// // THEN the command should have executed
|
|
|
|
+// verify(levelUpCommand, times(1)).executeCommand(any(McMMOPlayer.class));
|
|
|
|
+// mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), any()), atLeast(1));
|
|
|
|
+// }
|
|
|
|
|
|
@Test
|
|
@Test
|
|
void skillLevelUpViaXPGainShouldRunFiveTimes() {
|
|
void skillLevelUpViaXPGainShouldRunFiveTimes() {
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
final String commandStr = "say hello";
|
|
final String commandStr = "say hello";
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
(skill, skillLevel) -> skill == MINING && skillLevel >= 1 && skillLevel <= 5);
|
|
(skill, skillLevel) -> skill == MINING && skillLevel >= 1 && skillLevel <= 5);
|
|
@@ -115,15 +149,20 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
void skillLevelUpViaXPGainShouldRunCommandFiveTimesWithPlaceholders() {
|
|
void skillLevelUpViaXPGainShouldRunCommandFiveTimesWithPlaceholders() {
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
- assertEquals(mmoPlayer.getPlayer().getName(), playerName);
|
|
|
|
final String commandStr = "say hello {@player}, you have reached level {@mining_level}";
|
|
final String commandStr = "say hello {@player}, you have reached level {@mining_level}";
|
|
- final String expectedStr1 = "say hello " + playerName + ", you have reached level 1";
|
|
|
|
- final String expectedStr2 = "say hello " + playerName + ", you have reached level 2";
|
|
|
|
- final String expectedStr3 = "say hello " + playerName + ", you have reached level 3";
|
|
|
|
- final String expectedStr4 = "say hello " + playerName + ", you have reached level 4";
|
|
|
|
- final String expectedStr5 = "say hello " + playerName + ", you have reached level 5";
|
|
|
|
|
|
+ final String expectedStr1 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 1";
|
|
|
|
+ final String expectedStr2 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 2";
|
|
|
|
+ final String expectedStr3 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 3";
|
|
|
|
+ final String expectedStr4 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 4";
|
|
|
|
+ final String expectedStr5 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 5";
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
(skill, skillLevel) -> skill == MINING && skillLevel >= 1 && skillLevel <= 5);
|
|
(skill, skillLevel) -> skill == MINING && skillLevel >= 1 && skillLevel <= 5);
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
@@ -158,11 +197,11 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
Each registered command runs only once.
|
|
Each registered command runs only once.
|
|
*/
|
|
*/
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
- assertEquals(mmoPlayer.getPlayer().getName(), playerName);
|
|
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
|
|
|
|
final String commandStr = "say hello {@player}";
|
|
final String commandStr = "say hello {@player}";
|
|
- final String expectedStr = "say hello " + playerName;
|
|
|
|
|
|
+ final String expectedStr = "say hello " + DEFAULT_PLAYER_NAME;
|
|
final LevelUpCommand levelUpCommandOne = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand levelUpCommandOne = buildLevelUpCommand(commandStr,
|
|
(skill, level) -> skill == MINING && level == 1);
|
|
(skill, level) -> skill == MINING && level == 1);
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommandOne);
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommandOne);
|
|
@@ -199,11 +238,11 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
One command runs twice, the others run once.
|
|
One command runs twice, the others run once.
|
|
*/
|
|
*/
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
- assertEquals(mmoPlayer.getPlayer().getName(), playerName);
|
|
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
|
|
|
|
final String commandStr = "say hello {@player}";
|
|
final String commandStr = "say hello {@player}";
|
|
- final String expectedStr = "say hello " + playerName;
|
|
|
|
|
|
+ final String expectedStr = "say hello " + DEFAULT_PLAYER_NAME;
|
|
final LevelUpCommand levelUpCommandOne = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand levelUpCommandOne = buildLevelUpCommand(commandStr,
|
|
(skill, level) -> skill == MINING && (level == 1 || level == 4));
|
|
(skill, level) -> skill == MINING && (level == 1 || level == 4));
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommandOne);
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommandOne);
|
|
@@ -235,15 +274,20 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
@Test
|
|
@Test
|
|
void addLevelsShouldRunCommandFiveTimesWithPlaceholdersForLevel() {
|
|
void addLevelsShouldRunCommandFiveTimesWithPlaceholdersForLevel() {
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
- assertEquals(mmoPlayer.getPlayer().getName(), playerName);
|
|
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
|
|
|
|
final String commandStr = "say hello {@player}, you have reached level {@mining_level}";
|
|
final String commandStr = "say hello {@player}, you have reached level {@mining_level}";
|
|
- final String expectedStr1 = "say hello " + playerName + ", you have reached level 1";
|
|
|
|
- final String expectedStr2 = "say hello " + playerName + ", you have reached level 2";
|
|
|
|
- final String expectedStr3 = "say hello " + playerName + ", you have reached level 3";
|
|
|
|
- final String expectedStr4 = "say hello " + playerName + ", you have reached level 4";
|
|
|
|
- final String expectedStr5 = "say hello " + playerName + ", you have reached level 5";
|
|
|
|
|
|
+ final String expectedStr1 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 1";
|
|
|
|
+ final String expectedStr2 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 2";
|
|
|
|
+ final String expectedStr3 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 3";
|
|
|
|
+ final String expectedStr4 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 4";
|
|
|
|
+ final String expectedStr5 =
|
|
|
|
+ "say hello " + DEFAULT_PLAYER_NAME + ", you have reached level 5";
|
|
|
|
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
(skill, ignored) -> skill == MINING);
|
|
(skill, ignored) -> skill == MINING);
|
|
@@ -251,32 +295,29 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
|
|
|
|
// WHEN player gains 5 levels in mining
|
|
// WHEN player gains 5 levels in mining
|
|
int levelsGained = 5;
|
|
int levelsGained = 5;
|
|
- mmoPlayer.getProfile().addLevels(MINING, levelsGained);
|
|
|
|
- EventUtils.tryLevelChangeEvent(
|
|
|
|
- mmoPlayer.getPlayer(),
|
|
|
|
- MINING,
|
|
|
|
- levelsGained,
|
|
|
|
- mmoPlayer.getProfile().getSkillXpLevelRaw(MINING),
|
|
|
|
- true,
|
|
|
|
- XPGainReason.COMMAND);
|
|
|
|
|
|
+ levelPlayerViaXP(mmoPlayer, MINING, levelsGained);
|
|
|
|
|
|
// THEN the command should be checked for execution
|
|
// THEN the command should be checked for execution
|
|
- verify(levelUpCommandManager).applySkillLevelUp(any(), any(), any(), any());
|
|
|
|
- verify(levelUpCommand).process(any(), any(), any(), any());
|
|
|
|
|
|
+ verify(levelUpCommandManager, times(levelsGained))
|
|
|
|
+ .applySkillLevelUp(any(), any(), any(), any());
|
|
|
|
+ verify(levelUpCommand, times(levelsGained))
|
|
|
|
+ .process(any(), any(), any(), any());
|
|
// THEN the command should have executed
|
|
// THEN the command should have executed
|
|
- verify(levelUpCommand, times(1)).executeCommand(any(McMMOPlayer.class));
|
|
|
|
|
|
+ verify(levelUpCommand, times(levelsGained))
|
|
|
|
+ .executeCommand(any(McMMOPlayer.class));
|
|
// verify that Bukkit.dispatchCommand got executed at least 5 times with the correct injectedCommand
|
|
// verify that Bukkit.dispatchCommand got executed at least 5 times with the correct injectedCommand
|
|
- mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr1)));
|
|
|
|
- mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr2)));
|
|
|
|
- mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr3)));
|
|
|
|
- mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr4)));
|
|
|
|
- mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr5)));
|
|
|
|
|
|
+ mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr1)), atLeastOnce());
|
|
|
|
+ mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr2)), atLeastOnce());
|
|
|
|
+ mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr3)), atLeastOnce());
|
|
|
|
+ mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr4)), atLeastOnce());
|
|
|
|
+ mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), eq(expectedStr5)), atLeastOnce());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
void skillLevelUpShouldRunCommandAtLeastOnce() {
|
|
void skillLevelUpShouldRunCommandAtLeastOnce() {
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
final String commandStr = "say hello";
|
|
final String commandStr = "say hello";
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
(skill, ignored) -> skill == MINING);
|
|
(skill, ignored) -> skill == MINING);
|
|
@@ -298,7 +339,8 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
@Test
|
|
@Test
|
|
void skillLevelUpShouldNotRunCommand() {
|
|
void skillLevelUpShouldNotRunCommand() {
|
|
// GIVEN level up command for Woodcutting should not execute for Mining level up
|
|
// GIVEN level up command for Woodcutting should not execute for Mining level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
final String commandStr = "say hello";
|
|
final String commandStr = "say hello";
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr,
|
|
(skill, ignored) -> skill == WOODCUTTING);
|
|
(skill, ignored) -> skill == WOODCUTTING);
|
|
@@ -320,7 +362,8 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
@Test
|
|
@Test
|
|
public void levelUpShouldAlwaysRunCommand() {
|
|
public void levelUpShouldAlwaysRunCommand() {
|
|
// GIVEN level up command should always execute for any level up
|
|
// GIVEN level up command should always execute for any level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
final String commandStr = "say hello";
|
|
final String commandStr = "say hello";
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr, ALWAYS_TRUE);
|
|
final LevelUpCommand levelUpCommand = buildLevelUpCommand(commandStr, ALWAYS_TRUE);
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
@@ -339,7 +382,8 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
@Test
|
|
@Test
|
|
public void skillLevelUpShouldRunPowerlevelCommandOnce() {
|
|
public void skillLevelUpShouldRunPowerlevelCommandOnce() {
|
|
// GIVEN level up command for power level should always execute for any level up
|
|
// GIVEN level up command for power level should always execute for any level up
|
|
- assert mcMMO.p.getLevelUpCommandManager().getLevelUpCommands().isEmpty();
|
|
|
|
|
|
+ final TestPlayerMock testPlayerMock = mockPlayer(UUID.randomUUID(), DEFAULT_PLAYER_NAME, 0);
|
|
|
|
+ final McMMOPlayer mmoPlayer = testPlayerMock.mmoPlayer();
|
|
final String commandStr = "say hello";
|
|
final String commandStr = "say hello";
|
|
final LevelUpCommand powerLevelUpCommand = buildLevelUpCommand(commandStr,
|
|
final LevelUpCommand powerLevelUpCommand = buildLevelUpCommand(commandStr,
|
|
(ignoredA, ignoredB) -> true, (powerlevel) -> powerlevel == 3);
|
|
(ignoredA, ignoredB) -> true, (powerlevel) -> powerlevel == 3);
|