Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 11, 2024
2 parents d058830 + b1fa9a9 commit ec6b950
Show file tree
Hide file tree
Showing 7 changed files with 656 additions and 647 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -390,6 +396,7 @@
<format>XML</format>
</formats>
</configuration>

</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ChallengesGlobalPlayerCommand(ChallengesAddon addon, List<GameModeAddon>
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");
}
Expand Down
1,242 changes: 621 additions & 621 deletions src/main/java/world/bentobox/challenges/panel/CommonPanel.java

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/main/java/world/bentobox/challenges/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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;
Expand Down Expand Up @@ -53,7 +52,7 @@
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, ChatColor.class, Util.class})
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
public class ChallengesCommandTest {

@Mock
Expand Down Expand Up @@ -141,10 +140,6 @@ public void setUp() {
// 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);
Expand All @@ -159,6 +154,9 @@ public void setUp() {
// 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand All @@ -46,10 +45,10 @@
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;
Expand All @@ -59,7 +58,7 @@
*
*/
@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
Expand Down Expand Up @@ -150,11 +149,6 @@ public void setUp() {
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);
Expand All @@ -176,6 +170,8 @@ public void setUp() {
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -71,14 +70,13 @@
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
Expand Down Expand Up @@ -120,6 +118,7 @@ public class TryToCompleteTest {
private final ItemStack[] contents = {};
@Mock
private BoundingBox bb;
private Set<Player> onlinePlayers;

/**
*/
Expand Down Expand Up @@ -169,6 +168,8 @@ public void setUp() {
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);
Expand Down Expand Up @@ -205,6 +206,7 @@ public void setUp() {
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));
Expand All @@ -213,6 +215,7 @@ public void setUp() {
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");
Expand All @@ -227,6 +230,7 @@ public void setUp() {
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()))
Expand All @@ -242,7 +246,7 @@ public void setUp() {
// 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();
Expand All @@ -252,7 +256,7 @@ public void setUp() {
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<>();
Expand All @@ -264,10 +268,6 @@ public void setUp() {
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
Expand Down

0 comments on commit ec6b950

Please sign in to comment.