mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-28 05:25:21 +01:00
Fix tests.
This commit is contained in:
commit
ec6b950304
7
pom.xml
7
pom.xml
@ -120,6 +120,12 @@
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- This is required for PowerMockito to work and must be placed before it -->
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>3.30.2-GA</version>
|
||||
</dependency>
|
||||
<!-- Spigot API -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
@ -390,6 +396,7 @@
|
||||
<format>XML</format>
|
||||
</formats>
|
||||
</configuration>
|
||||
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
@ -39,7 +39,7 @@ public class ChallengesGlobalPlayerCommand extends CompositeCommand
|
||||
public void setup()
|
||||
{
|
||||
this.setOnlyPlayer(true);
|
||||
this.setPermission("challenges");
|
||||
this.setPermission("addon.challenges");
|
||||
this.setParametersHelp("challenges.commands.user.main.parameters");
|
||||
this.setDescription("challenges.commands.user.main.description");
|
||||
}
|
||||
|
@ -7,11 +7,19 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
@ -16,7 +16,6 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFactory;
|
||||
@ -53,7 +52,7 @@ import world.bentobox.challenges.managers.ChallengesManager;
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, ChatColor.class, Util.class})
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
|
||||
public class ChallengesCommandTest {
|
||||
|
||||
@Mock
|
||||
@ -141,10 +140,6 @@ public class ChallengesCommandTest {
|
||||
// Challenges exist
|
||||
when(chm.hasAnyChallengeData(any(World.class))).thenReturn(true);
|
||||
|
||||
// ChatColor
|
||||
PowerMockito.mockStatic(ChatColor.class);
|
||||
when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
|
||||
// Settings
|
||||
Settings settings = new Settings();
|
||||
when(addon.getChallengesSettings()).thenReturn(settings);
|
||||
@ -159,6 +154,9 @@ public class ChallengesCommandTest {
|
||||
// Util
|
||||
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
|
||||
when(Util.sameWorld(any(), any())).thenReturn(true);
|
||||
when(Util.translateColorCodes(anyString()))
|
||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Command under test
|
||||
cc = new ChallengesPlayerCommand(addon, ic);
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFactory;
|
||||
@ -46,10 +45,10 @@ import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.managers.ChallengesManager;
|
||||
import world.bentobox.challenges.config.Settings;
|
||||
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
|
||||
import world.bentobox.challenges.database.object.Challenge;
|
||||
import world.bentobox.challenges.managers.ChallengesManager;
|
||||
import world.bentobox.challenges.tasks.TryToComplete;
|
||||
import world.bentobox.challenges.utils.Constants;
|
||||
import world.bentobox.challenges.utils.Utils;
|
||||
@ -59,7 +58,7 @@ import world.bentobox.challenges.utils.Utils;
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, ChatColor.class, Utils.class, TryToComplete.class, Util.class})
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Utils.class, TryToComplete.class, Util.class })
|
||||
public class CompleteChallengeCommandTest {
|
||||
|
||||
@Mock
|
||||
@ -150,11 +149,6 @@ public class CompleteChallengeCommandTest {
|
||||
List<String> nameList = Arrays.asList("world_maker", "world_placer", "bad_challenge_name", "world_breaker");
|
||||
when(chm.getAllChallengesNames(any())).thenReturn(nameList);
|
||||
|
||||
|
||||
// ChatColor
|
||||
PowerMockito.mockStatic(ChatColor.class);
|
||||
when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
|
||||
// Settings
|
||||
Settings settings = new Settings();
|
||||
when(addon.getChallengesSettings()).thenReturn(settings);
|
||||
@ -176,6 +170,8 @@ public class CompleteChallengeCommandTest {
|
||||
// Util
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.tabLimit(any(), any())).thenAnswer((Answer<List<String>>) invocation -> (List<String>)invocation.getArgument(0, List.class));
|
||||
when(Util.translateColorCodes(anyString()))
|
||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Command under test
|
||||
cc = new CompleteChallengeCommand(addon, ic);
|
||||
|
@ -22,7 +22,6 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -71,14 +70,13 @@ import world.bentobox.challenges.database.object.requirements.InventoryRequireme
|
||||
import world.bentobox.challenges.database.object.requirements.IslandRequirements;
|
||||
import world.bentobox.challenges.managers.ChallengesManager;
|
||||
import world.bentobox.challenges.tasks.TryToComplete.ChallengeResult;
|
||||
import world.bentobox.challenges.utils.Utils;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class, Utils.class, ChatColor.class })
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
|
||||
public class TryToCompleteTest {
|
||||
|
||||
// Constants
|
||||
@ -120,6 +118,7 @@ public class TryToCompleteTest {
|
||||
private final ItemStack[] contents = {};
|
||||
@Mock
|
||||
private BoundingBox bb;
|
||||
private Set<Player> onlinePlayers;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -169,6 +168,8 @@ public class TryToCompleteTest {
|
||||
when(Util.getWorld(any())).thenReturn(world);
|
||||
when(Util.prettifyText(anyString())).thenCallRealMethod();
|
||||
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
|
||||
when(Util.translateColorCodes(anyString()))
|
||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
@ -205,6 +206,7 @@ public class TryToCompleteTest {
|
||||
when(user.hasPermission(anyString())).thenReturn(true);
|
||||
when(user.getPlayer()).thenReturn(player);
|
||||
UUID uniqueId = UUID.randomUUID();
|
||||
when(player.getUniqueId()).thenReturn(uniqueId);
|
||||
when(user.getUniqueId()).thenReturn(uniqueId);
|
||||
when(user.getTranslation(anyString()))
|
||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
@ -213,6 +215,7 @@ public class TryToCompleteTest {
|
||||
when(user.getTranslationOrNothing(anyString()))
|
||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
User.getInstance(player);
|
||||
@Nullable
|
||||
Location userLoc = mock(Location.class);
|
||||
when(userLoc.toString()).thenReturn("location");
|
||||
@ -227,6 +230,7 @@ public class TryToCompleteTest {
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
PlaceholdersManager phm = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||
when(phm.replacePlaceholders(any(), any()))
|
||||
@ -242,7 +246,7 @@ public class TryToCompleteTest {
|
||||
// Bukkit - online players
|
||||
Map<UUID, String> online = new HashMap<>();
|
||||
|
||||
Set<Player> onlinePlayers = new HashSet<>();
|
||||
onlinePlayers = new HashSet<>();
|
||||
for (String name : NAMES) {
|
||||
Player p1 = mock(Player.class);
|
||||
UUID uuid2 = UUID.randomUUID();
|
||||
@ -252,7 +256,7 @@ public class TryToCompleteTest {
|
||||
onlinePlayers.add(p1);
|
||||
}
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> onlinePlayers);
|
||||
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> Set.of(player));
|
||||
|
||||
// World settings
|
||||
Map<String, Boolean> map = new HashMap<>();
|
||||
@ -264,10 +268,6 @@ public class TryToCompleteTest {
|
||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||
|
||||
// ChatColor
|
||||
PowerMockito.mockStatic(ChatColor.class, Mockito.RETURNS_MOCKS);
|
||||
when(ChatColor.stripColor(anyString()))
|
||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
}
|
||||
|
||||
@After
|
||||
|
Loading…
Reference in New Issue
Block a user