|
@@ -2,6 +2,7 @@ package com.gmail.nossr50.commands.levelup;
|
|
|
|
|
|
import com.gmail.nossr50.MMOTestEnvironmentBasic;
|
|
|
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
|
|
+import com.gmail.nossr50.datatypes.experience.XPGainSource;
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
|
@@ -11,11 +12,9 @@ import org.bukkit.Bukkit;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.mockito.Mockito;
|
|
|
|
|
|
-import java.util.Set;
|
|
|
import java.util.function.BiPredicate;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
@@ -51,6 +50,71 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
|
mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), any()), atLeast(5));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void levelUpViaXPGainShouldRunCommandFiveTimes() {
|
|
|
+ // GIVEN level up command for Mining should always execute for Mining level up
|
|
|
+ assert mcMMO.p.getLevelUpCommandManager().isEmpty();
|
|
|
+ final String commandStr = "say hello";
|
|
|
+ final LevelUpCommand levelUpCommand
|
|
|
+ = buildLevelUpCommand(commandStr, (s, ignored) -> s == skill);
|
|
|
+ mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
|
+
|
|
|
+ // WHEN player gains 5 levels in mining via command
|
|
|
+ assertEquals(0, mmoPlayer.getSkillLevel(skill));
|
|
|
+ int levelsGained = 5;
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ mmoPlayer.applyXpGain(skill, mmoPlayer.getProfile().getXpToLevel(skill), XPGainReason.COMMAND, XPGainSource.COMMAND);
|
|
|
+ }
|
|
|
+
|
|
|
+ // THEN the command should be checked for execution
|
|
|
+ verify(levelUpCommandManager, times(levelsGained)).apply(any(), any(), any());
|
|
|
+ verify(levelUpCommand, times(levelsGained)).process(any(), any(), any());
|
|
|
+
|
|
|
+ // THEN the command should have executed
|
|
|
+ verify(levelUpCommand, times(levelsGained)).executeCommand(any(McMMOPlayer.class), any(PrimarySkillType.class), anyInt());
|
|
|
+ mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), any()), atLeast(5));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void levelUpViaXPGainShouldRunCommandFiveTimesWithPlaceholders() {
|
|
|
+ // GIVEN level up command for Mining should always execute for Mining level up
|
|
|
+ assert mcMMO.p.getLevelUpCommandManager().isEmpty();
|
|
|
+ String playerName = "Momshroom";
|
|
|
+ when (player.getName()).thenReturn(playerName);
|
|
|
+ assertEquals(player.getName(), playerName);
|
|
|
+ final String commandStr = "say hello %player%, you have reached level %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 LevelUpCommand levelUpCommand
|
|
|
+ = buildLevelUpCommand(commandStr, (s, ignored) -> s == skill);
|
|
|
+ mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
|
+
|
|
|
+ // WHEN player gains 5 levels in mining via command
|
|
|
+ assertEquals(0, mmoPlayer.getSkillLevel(skill));
|
|
|
+ int levelsGained = 5;
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ mmoPlayer.applyXpGain(skill, mmoPlayer.getProfile().getXpToLevel(skill), XPGainReason.COMMAND, XPGainSource.COMMAND);
|
|
|
+ }
|
|
|
+
|
|
|
+ // THEN the command should be checked for execution
|
|
|
+ verify(levelUpCommandManager, times(levelsGained)).apply(any(), any(), any());
|
|
|
+ verify(levelUpCommand, times(levelsGained)).process(any(), any(), any());
|
|
|
+
|
|
|
+ // THEN the command should have executed
|
|
|
+ verify(levelUpCommand, times(levelsGained)).executeCommand(any(McMMOPlayer.class), any(PrimarySkillType.class), anyInt());
|
|
|
+ mockedBukkit.verify(() -> Bukkit.dispatchCommand(any(), any()), atLeast(5));
|
|
|
+ // AND THEN the message for each level up should have happened at least once
|
|
|
+ // 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)));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void levelUpShouldRunCommandFiveTimesWithPlaceholders() {
|
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
@@ -80,7 +144,7 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- void levelUpShouldRunCommandFiveTimesWithPlaceholdersForLevel() {
|
|
|
+ void levelUpViaAddLevelsShouldRunCommandFiveTimesWithPlaceholdersForLevel() {
|
|
|
// GIVEN level up command for Mining should always execute for Mining level up
|
|
|
assert mcMMO.p.getLevelUpCommandManager().isEmpty();
|
|
|
String playerName = "Momshroom";
|
|
@@ -97,11 +161,17 @@ class LevelUpCommandTest extends MMOTestEnvironmentBasic {
|
|
|
final LevelUpCommand levelUpCommand
|
|
|
= buildLevelUpCommand(commandStr, (s, ignored) -> s == skill);
|
|
|
mcMMO.p.getLevelUpCommandManager().registerCommand(levelUpCommand);
|
|
|
- int levelsGained = 5;
|
|
|
|
|
|
// WHEN player gains 5 levels in mining
|
|
|
- McMMOPlayerLevelUpEvent event = new McMMOPlayerLevelUpEvent(player, skill, levelsGained, XPGainReason.PVE);
|
|
|
- selfListener.onPlayerLevelUp(event);
|
|
|
+ int levelsGained = 5;
|
|
|
+ mmoPlayer.getProfile().addLevels(skill, levelsGained);
|
|
|
+ EventUtils.tryLevelChangeEvent(
|
|
|
+ player,
|
|
|
+ skill,
|
|
|
+ levelsGained,
|
|
|
+ mmoPlayer.getProfile().getSkillXpLevelRaw(skill),
|
|
|
+ true,
|
|
|
+ XPGainReason.COMMAND);
|
|
|
|
|
|
// THEN the command should be checked for execution
|
|
|
verify(levelUpCommandManager).apply(any(), any(), any());
|