Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/BentoBoxWorld/BentoBox.git
Browse files Browse the repository at this point in the history
… into develop
  • Loading branch information
tastybento committed Jun 15, 2024
2 parents 894b063 + d23f15f commit 09c5cbb
Show file tree
Hide file tree
Showing 90 changed files with 230 additions and 149 deletions.
2 changes: 1 addition & 1 deletion src/main/java/world/bentobox/bentobox/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class Util {

// Bukkit method that was added in 2011
// Example value: 1.20.4-R0.1-SNAPSHOT
private static final String bukkitVersion = "v" + Bukkit.getServer().getBukkitVersion().replace('.', '_').replace('-', '_');
private static final String bukkitVersion = "v" + Bukkit.getBukkitVersion().replace('.', '_').replace('-', '_');
private static final String pluginPackageName = plugin.getClass().getPackage().getName();

private Util() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ private enum mandatoryTags {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);

PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
// Set up plugin
plugin = mock(BentoBox.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class AddonTest {

@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);

server = mock(Server.class);
World world = mock(World.class);
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
Expand All @@ -79,8 +81,6 @@ public void setUp() throws Exception {

PluginManager pluginManager = mock(PluginManager.class);


PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
when(Bukkit.getServer()).thenReturn(server);
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void setUp() throws Exception {
when(plugin.getSettings()).thenReturn(settings);
when(settings.getDelayTime()).thenReturn(10); // 10 seconds
// Server & Scheduler
PowerMockito.mockStatic(Bukkit.class);
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
when(Bukkit.getScheduler()).thenReturn(sch);
when(sch.runTaskLater(any(), any(Runnable.class), anyLong())).thenReturn(task);
// Plugin manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.junit.After;
Expand All @@ -21,6 +22,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
Expand All @@ -36,7 +38,7 @@
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({BentoBox.class, CommandEvent.class})
@PrepareForTest({ BentoBox.class, CommandEvent.class, Bukkit.class })
public class HiddenCommandTest {

@Mock
Expand All @@ -49,6 +51,7 @@ public class HiddenCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Command manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class AdminDeleteCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);

// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -131,7 +133,6 @@ public void setUp() throws Exception {

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
BukkitTask task = mock(BukkitTask.class);
when(sch.runTaskLater(any(), any(Runnable.class), any(Long.class))).thenReturn(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class AdminGetrankCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -107,7 +108,6 @@ public void setUp() throws Exception {
online.put(uuid, name);
onlinePlayers.add(p1);
}
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> onlinePlayers);

// Command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class AdminRegisterCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -145,7 +146,6 @@ public void setUp() throws Exception {

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);

// Locales
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class AdminResetFlagsCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -129,7 +130,6 @@ public void setUp() throws Exception {

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
Expand Down Expand Up @@ -53,6 +55,7 @@ public class AdminSwitchCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class AdminTeleportCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -142,7 +143,6 @@ public void setUp() throws Exception {

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
when(Bukkit.getScheduler()).thenReturn(sch);

// Locales
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class AdminUnregisterCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);

PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Expand Down Expand Up @@ -137,7 +139,6 @@ public void setUp() throws Exception {

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);

// Locales
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class AdminPurgeCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);

// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);

Expand Down Expand Up @@ -284,7 +286,6 @@ public void testExecuteUserStringListOfStringIslandsFound() {
when(island.isOwned()).thenReturn(true);
when(island.getMemberSet()).thenReturn(ImmutableSet.of(UUID.randomUUID()));
when(im.getIslands()).thenReturn(Collections.singleton(island));
PowerMockito.mockStatic(Bukkit.class);
OfflinePlayer op = mock(OfflinePlayer.class);
when(op.getLastPlayed()).thenReturn(0L);
when(Bukkit.getOfflinePlayer(any(UUID.class))).thenReturn(op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class AdminRangeCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -94,7 +95,6 @@ public void setUp() throws Exception {

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);

// Locales
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package world.bentobox.bentobox.api.commands.admin.range;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.framework;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
Expand Down Expand Up @@ -46,6 +50,7 @@ public class AdminRangeDisplayCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -76,37 +81,36 @@ public void setUp() throws Exception {

// Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);

// Player has island to begin with
IslandsManager im = mock(IslandsManager.class);
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
when(plugin.getIslands()).thenReturn(im);

// Has team
PlayersManager pm = mock(PlayersManager.class);
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
when(im.inTeam(any(), eq(uuid))).thenReturn(true);

when(plugin.getPlayers()).thenReturn(pm);

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);

// Locales
LocalesManager lm = mock(LocalesManager.class);
Answer<String> answer = invocation -> invocation.getArgument(1, String.class);
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer);
when(lm.get(any(), any())).thenAnswer(answer);
when(plugin.getLocalesManager()).thenReturn(lm);
}

@After
public void tearDown() {
User.clearUsers();
Mockito.framework().clearInlineMocks();
framework().clearInlineMocks();
}

/**
Expand All @@ -118,12 +122,12 @@ public void testExecutePlayerDisplayArgs() {
AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac);
ardc.execute(user, "display", new ArrayList<>());
// Show display
Mockito.verify(user).sendMessage("commands.admin.range.display.showing");
Mockito.verify(user).sendMessage("commands.admin.range.display.hint");
verify(user).sendMessage("commands.admin.range.display.showing");
verify(user).sendMessage("commands.admin.range.display.hint");
// Run command again
ardc.execute(user, "display", new ArrayList<>());
// Remove
Mockito.verify(user).sendMessage("commands.admin.range.display.hiding");
verify(user).sendMessage("commands.admin.range.display.hiding");
}

/**
Expand All @@ -135,13 +139,13 @@ public void testExecutePlayeShowArgs() {
AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac);
ardc.execute(user, "show", new ArrayList<>());
// Show display
Mockito.verify(user).sendMessage("commands.admin.range.display.showing");
Mockito.verify(user).sendMessage("commands.admin.range.display.hint");
verify(user).sendMessage("commands.admin.range.display.showing");
verify(user).sendMessage("commands.admin.range.display.hint");
// Run command again
ardc.execute(user, "show", new ArrayList<>());
Mockito.verify(user).sendMessage("commands.admin.range.display.already-on");
verify(user).sendMessage("commands.admin.range.display.already-on");
ardc.execute(user, "hide", new ArrayList<>());
Mockito.verify(user).sendMessage("commands.admin.range.display.hiding");
verify(user).sendMessage("commands.admin.range.display.hiding");
}

/**
Expand All @@ -152,7 +156,7 @@ public void testExecutePlayeShowArgs() {
public void testExecutePlayeHideArgs() {
AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac);
ardc.execute(user, "hide", new ArrayList<>());
Mockito.verify(user).sendMessage("commands.admin.range.display.already-off");
verify(user).sendMessage("commands.admin.range.display.already-off");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class AdminRangeResetCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);

// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -112,7 +114,6 @@ public void setUp() throws Exception {

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
when(Bukkit.getPluginManager()).thenReturn(pim);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class AdminRangeSetCommandTest {
*/
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
Expand Down Expand Up @@ -126,7 +127,6 @@ public void setUp() throws Exception {

// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
when(Bukkit.getPluginManager()).thenReturn(pim);

Expand Down
Loading

0 comments on commit 09c5cbb

Please sign in to comment.