mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-21 18:25:12 +01:00
Use custom server to handle new enums
This commit is contained in:
parent
cd40d27b38
commit
058fb6e70e
@ -8,10 +8,10 @@ package world.bentobox.bentobox.database.json.adapters;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import com.google.gson.TypeAdapter;
|
||||
@ -32,11 +32,12 @@ public final class BiomeTypeAdapter extends TypeAdapter<Biome>
|
||||
*/
|
||||
final Map<String, Biome> biomeMap;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public BiomeTypeAdapter() {
|
||||
this.biomeMap = new HashMap<>();
|
||||
|
||||
// Put in current values.
|
||||
Arrays.stream(Biome.values()).forEach(biome -> this.biomeMap.put(biome.name(), biome));
|
||||
Registry.BIOME.forEach(biome -> this.biomeMap.put(biome.name(), biome));
|
||||
|
||||
// Put in renamed biomes values.
|
||||
this.biomeMap.put("TALL_BIRCH_FOREST", Biome.OLD_GROWTH_BIRCH_FOREST);
|
||||
|
@ -26,8 +26,13 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -216,10 +221,24 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
try {
|
||||
// Floats need special handling because the database returns them as doubles
|
||||
Type setType = propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0];
|
||||
BentoBox.getInstance().logDebug("name = " + setType.getTypeName());
|
||||
plugin.logError("Default setting value will be used: "
|
||||
+ propertyDescriptor.getReadMethod().invoke(instance));
|
||||
plugin.logError(method.getName());
|
||||
plugin.logError(propertyDescriptor.getReadMethod().getName());
|
||||
plugin.logError(instance.toString());
|
||||
if (setType.getTypeName().equals("float")) {
|
||||
double d = (double) setTo;
|
||||
float f = (float)d;
|
||||
method.invoke(instance, f);
|
||||
} else if (setType.getTypeName().equals("org.bukkit.Sound")) {
|
||||
Sound s = Registry.SOUNDS
|
||||
.get(NamespacedKey.fromString(((String) setTo).toLowerCase(Locale.ENGLISH)));
|
||||
method.invoke(instance, s);
|
||||
} else if (setType.getTypeName().equals("org.bukkit.block.Biome")) {
|
||||
Biome b = Registry.BIOME
|
||||
.get(NamespacedKey.fromString(((String) setTo).toLowerCase(Locale.ENGLISH)));
|
||||
method.invoke(instance, b);
|
||||
} else {
|
||||
method.invoke(instance, setTo);
|
||||
}
|
||||
@ -368,8 +387,9 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
// Get the read method
|
||||
Method method = propertyDescriptor.getReadMethod();
|
||||
// Invoke the read method to get the value. We have no idea what type of value it is.
|
||||
BentoBox.getInstance().logDebug("Method is " + method.getName());
|
||||
Object value = method.invoke(instance);
|
||||
|
||||
BentoBox.getInstance().logDebug("Value is " + value);
|
||||
String storageLocation = field.getName();
|
||||
|
||||
// Check if there is an annotation on the field
|
||||
@ -395,6 +415,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
}
|
||||
|
||||
if (!checkAdapter(field, config, storageLocation, value)) {
|
||||
BentoBox.getInstance().logDebug("No adapter");
|
||||
// Set the filename if it has not be set already
|
||||
if (filename.isEmpty() && method.getName().equals("getUniqueId")) {
|
||||
// Save the name for when the file is saved
|
||||
@ -407,6 +428,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
serializeSet((Set<Object>)value, config, storageLocation);
|
||||
} else {
|
||||
// For all other data that doesn't need special serialization
|
||||
BentoBox.getInstance().logDebug("For all other data that doesn't need special serializationr");
|
||||
config.set(storageLocation, serialize(value));
|
||||
}
|
||||
}
|
||||
@ -561,6 +583,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
private Object serialize(@Nullable Object object) {
|
||||
// Null is a value object and is serialized as the string "null"
|
||||
if (object == null) {
|
||||
BentoBox.getInstance().logDebug("Object is null");
|
||||
return "null";
|
||||
}
|
||||
// UUID has it's own serialization, that is not picked up automatically
|
||||
@ -575,6 +598,11 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
if (object instanceof Location l) {
|
||||
return Util.getStringLocation(l);
|
||||
}
|
||||
// Keyed interfaces that are replacing enums
|
||||
if (object instanceof Keyed k) {
|
||||
BentoBox.getInstance().logDebug("Object is keyed");
|
||||
return k.getKey().getKey();
|
||||
}
|
||||
// Enums
|
||||
if (object instanceof Enum<?> e) {
|
||||
//Custom enums are a child of the Enum class. Just get the names of each one.
|
||||
|
@ -743,7 +743,6 @@ public class Util {
|
||||
throw new IllegalStateException("Class " + clazz.getName() + " does not implement WorldRegenerator");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
plugin.logWarning("No Regenerator found for " + bukkitVersion + ", falling back to Bukkit API.");
|
||||
handler = new world.bentobox.bentobox.nms.fallback.WorldRegeneratorImpl();
|
||||
}
|
||||
@ -773,7 +772,6 @@ public class Util {
|
||||
throw new IllegalStateException("Class " + clazz.getName() + " does not implement PasteHandler");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
plugin.logWarning("No PasteHandler found for " + bukkitVersion + ", falling back to Bukkit API.");
|
||||
handler = new world.bentobox.bentobox.nms.fallback.PasteHandlerImpl();
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@ -34,6 +35,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
@ -58,6 +60,7 @@ import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
@ -103,9 +106,13 @@ public abstract class AbstractCommonSetup {
|
||||
protected FlagsManager fm;
|
||||
@Mock
|
||||
protected Spigot spigot;
|
||||
protected Server server;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
server = ServerMocks.newServer();
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
// Set up plugin
|
||||
@ -221,6 +228,7 @@ public abstract class AbstractCommonSetup {
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
||||
import world.bentobox.bentobox.database.DatabaseSetup;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
@ -126,9 +125,8 @@ public abstract class RanksManagerBeforeClassTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws IOException {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
deleteAll(new File("database"));
|
||||
deleteAll(new File("database_backup"));
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -128,12 +127,9 @@ public class AdminResetFlagsCommandTest extends AbstractCommonSetup {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -43,6 +43,7 @@ import world.bentobox.bentobox.managers.BlueprintsManager;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.HooksManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
@ -68,8 +69,11 @@ public class AdminBlueprintLoadCommandTest {
|
||||
private Map<String, Blueprint> map;
|
||||
private File blueprintsFolder;
|
||||
|
||||
/**
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
ServerMocks.newServer();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
@ -125,8 +129,6 @@ public class AdminBlueprintLoadCommandTest {
|
||||
abcc = new AdminBlueprintLoadCommand(ac);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
User.clearUsers();
|
||||
@ -181,7 +183,6 @@ public class AdminBlueprintLoadCommandTest {
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintLoadCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testExecuteUserStringListOfStringSuccessCaps() {
|
||||
assertTrue(abcc.execute(user, "", List.of("island")));
|
||||
verify(user).sendMessage("general.success");
|
||||
|
@ -25,7 +25,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -45,6 +45,7 @@ import world.bentobox.bentobox.managers.BlueprintsManager;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.HooksManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
@ -68,8 +69,11 @@ public class AdminBlueprintSaveCommandTest {
|
||||
private BlueprintsManager bm;
|
||||
private Blueprint bp = new Blueprint();
|
||||
|
||||
/**
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
ServerMocks.newServer();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
@ -200,7 +204,6 @@ public class AdminBlueprintSaveCommandTest {
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintSaveCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testExecuteUserStringListOfString() {
|
||||
testCanExecute();
|
||||
assertTrue(absc.execute(user, "", List.of("island")));
|
||||
@ -212,7 +215,6 @@ public class AdminBlueprintSaveCommandTest {
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintSaveCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testExecuteUserStringListOfStringFileExists() {
|
||||
testCanExecute();
|
||||
assertTrue(absc.execute(user, "", List.of("island")));
|
||||
|
@ -94,9 +94,8 @@ public class AdminRangeCommandTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -117,9 +117,8 @@ public class AdminRangeResetCommandTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,9 +119,8 @@ public class AdminRangeSetCommandTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,6 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.framework;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@ -152,9 +151,8 @@ public class AdminTeamDisbandCommandTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,13 +21,12 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -75,12 +74,11 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||
private Addon addon;
|
||||
|
||||
private IslandExpelCommand iec;
|
||||
@Mock
|
||||
private Server server;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Command manager
|
||||
@ -97,7 +95,6 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(server.getOnlinePlayers()).thenReturn(Collections.emptySet());
|
||||
when(mockPlayer.getServer()).thenReturn(server);
|
||||
when(user.getPlayer()).thenReturn(mockPlayer);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
@ -155,6 +152,11 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||
iec = new IslandExpelCommand(ic);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#IslandExpelCommand(world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
||||
@ -369,7 +371,6 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testExecuteUserStringListOfStringHasIsland() {
|
||||
testCanExecute();
|
||||
assertTrue(iec.execute(user, "", Collections.singletonList("tasty")));
|
||||
@ -383,7 +384,6 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testExecuteUserStringListOfStringNoIslandSendToSpawn() {
|
||||
Optional<Island> optionalIsland = Optional.of(island);
|
||||
when(im.getSpawn(any())).thenReturn(optionalIsland);
|
||||
@ -400,7 +400,6 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testExecuteUserStringListOfStringCreateIsland() {
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
CompositeCommand pc = mock(CompositeCommand.class);
|
||||
@ -423,7 +422,6 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
||||
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testExecuteUserStringListOfStringCreateIslandFailCommand() {
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
CompositeCommand pc = mock(CompositeCommand.class);
|
||||
|
@ -176,9 +176,8 @@ public class IslandGoCommandTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,6 +187,10 @@ public class IslandResetCommandTest extends AbstractCommonSetup {
|
||||
irc = new IslandResetCommand(ic);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
/**
|
||||
* Test method for
|
||||
* {@link IslandResetCommand#canExecute(User, String, java.util.List)}
|
||||
@ -254,12 +258,6 @@ public class IslandResetCommandTest extends AbstractCommonSetup {
|
||||
checkSpigotMessage("commands.island.reset.kicked-from-island", 11);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link IslandResetCommand#canExecute(User, String, java.util.List)}
|
||||
*/
|
||||
|
@ -130,12 +130,9 @@ public class IslandSpawnCommandTest extends AbstractCommonSetup {
|
||||
isc = new IslandSpawnCommand(ic);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,6 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -56,6 +55,7 @@ import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.panels.settings.SettingsTab;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@ -96,12 +96,13 @@ public class CycleClickTest {
|
||||
@Mock
|
||||
private @NonNull Player p;
|
||||
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception - exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
ServerMocks.newServer();
|
||||
// Set up plugin
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
@ -234,11 +235,11 @@ public class CycleClickTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testNoPremission() {
|
||||
when(user.hasPermission(anyString())).thenReturn(false);
|
||||
CycleClick udc = new CycleClick(LOCK);
|
||||
@ -256,7 +257,6 @@ public class CycleClickTest {
|
||||
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnLeftClick() {
|
||||
final int SLOT = 5;
|
||||
CycleClick udc = new CycleClick(LOCK);
|
||||
@ -276,7 +276,6 @@ public class CycleClickTest {
|
||||
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnLeftClickSetMinMax() {
|
||||
// Provide a current rank value - coop
|
||||
when(island.getFlag(any())).thenReturn(RanksManager.COOP_RANK);
|
||||
@ -298,7 +297,6 @@ public class CycleClickTest {
|
||||
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnRightClick() {
|
||||
final int SLOT = 5;
|
||||
CycleClick udc = new CycleClick(LOCK);
|
||||
@ -318,7 +316,6 @@ public class CycleClickTest {
|
||||
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnRightClickMinMaxSet() {
|
||||
// Provide a current rank value - coop
|
||||
when(island.getFlag(any())).thenReturn(RanksManager.TRUSTED_RANK);
|
||||
@ -340,7 +337,6 @@ public class CycleClickTest {
|
||||
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testAllClicks() {
|
||||
// Test all possible click types
|
||||
CycleClick udc = new CycleClick(LOCK);
|
||||
@ -371,7 +367,6 @@ public class CycleClickTest {
|
||||
* Test for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnShiftLeftClickIsOp() {
|
||||
when(user.isOp()).thenReturn(true);
|
||||
CycleClick udc = new CycleClick(LOCK);
|
||||
@ -384,7 +379,6 @@ public class CycleClickTest {
|
||||
assertTrue(udc.onClick(panel, user, ClickType.SHIFT_LEFT, SLOT));
|
||||
assertTrue(hiddenFlags.isEmpty());
|
||||
// Verify sounds
|
||||
verify(p).playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||
verify(p).playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
||||
verify(p, times(2)).playSound((Location) null, (Sound) null, 1F, 1F);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -38,6 +37,7 @@ import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.panels.settings.SettingsTab;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@ -68,6 +68,7 @@ public class IslandToggleClickTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServerMocks.newServer();
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// Set up plugin
|
||||
@ -120,11 +121,11 @@ public class IslandToggleClickTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClickNoPermission() {
|
||||
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||
@ -132,7 +133,6 @@ public class IslandToggleClickTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClick() {
|
||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||
verify(island).toggleFlag(flag);
|
||||
@ -140,7 +140,6 @@ public class IslandToggleClickTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClickNoIsland() {
|
||||
when(settingsTab.getIsland()).thenReturn(null);
|
||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||
@ -148,7 +147,6 @@ public class IslandToggleClickTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClickNotOwner() {
|
||||
// No permission
|
||||
when(user.hasPermission(anyString())).thenReturn(false);
|
||||
|
@ -19,7 +19,6 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -37,6 +36,7 @@ import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@ -58,10 +58,9 @@ public class WorldToggleClickTest {
|
||||
@Mock
|
||||
private World world;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServerMocks.newServer();
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
@ -105,6 +104,7 @@ public class WorldToggleClickTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
}
|
||||
|
||||
@ -112,7 +112,6 @@ public class WorldToggleClickTest {
|
||||
* Test for {@link WorldToggleClick#onClick(Panel, User, ClickType, int)}
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClickNoPermission() {
|
||||
when(user.hasPermission(anyString())).thenReturn(false);
|
||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||
@ -124,7 +123,6 @@ public class WorldToggleClickTest {
|
||||
* Test for {@link WorldToggleClick#onClick(Panel, User, ClickType, int)}
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClick() {
|
||||
when(user.hasPermission(anyString())).thenReturn(true);
|
||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||
|
@ -45,7 +45,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -136,9 +135,8 @@ public class UserTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,12 +106,9 @@ public class BentoBoxPermsCommandTest extends AbstractCommonSetup {
|
||||
cmd = new BentoBoxPermsCommand(ac);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
Mockito.framework().clearInlineMocks();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,7 +35,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -206,9 +205,8 @@ public class JoinLeaveListenerTest extends RanksManagerBeforeClassTest {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,12 +119,9 @@ public class StandardSpawnProtectionListenerTest extends AbstractCommonSetup {
|
||||
ssp = new StandardSpawnProtectionListener(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,8 +25,8 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -149,6 +149,11 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
|
||||
crcl = new CommandRankClickListener();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.clicklisteners.CommandRankClickListener#onClick(world.bentobox.bentobox.api.panels.Panel, world.bentobox.bentobox.api.user.User, org.bukkit.event.inventory.ClickType, int)}.
|
||||
*/
|
||||
@ -163,7 +168,6 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.clicklisteners.CommandRankClickListener#onClick(world.bentobox.bentobox.api.panels.Panel, world.bentobox.bentobox.api.user.User, org.bukkit.event.inventory.ClickType, int)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClickNoPermission() {
|
||||
when(user.isOp()).thenReturn(false);
|
||||
when(user.hasPermission(anyString())).thenReturn(false);
|
||||
@ -176,7 +180,6 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
|
||||
* Test method for {@link world.bentobox.bentobox.listeners.flags.clicklisteners.CommandRankClickListener#onClick(world.bentobox.bentobox.api.panels.Panel, world.bentobox.bentobox.api.user.User, org.bukkit.event.inventory.ClickType, int)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClickNoFlag() {
|
||||
when(island.isAllowed(user, Flags.CHANGE_SETTINGS)).thenReturn(false);
|
||||
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
|
||||
|
@ -30,7 +30,6 @@ import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -52,6 +51,7 @@ import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@ -88,6 +88,7 @@ public class LockAndBanListenerTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServerMocks.newServer();
|
||||
// Server & Scheduler
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
@ -190,6 +191,7 @@ public class LockAndBanListenerTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
User.clearUsers();
|
||||
framework().clearInlineMocks();
|
||||
}
|
||||
@ -299,7 +301,6 @@ public class LockAndBanListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testPlayerMoveIntoBannedIsland() {
|
||||
// Make player
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
@ -322,7 +323,6 @@ public class LockAndBanListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testPlayerMoveInsideBannedIsland() {
|
||||
// Make player
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
@ -350,7 +350,6 @@ public class LockAndBanListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testVehicleMoveIntoBannedIsland() {
|
||||
// Make player
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
@ -513,7 +512,6 @@ public class LockAndBanListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testPlayerMoveIntoLockedIsland() {
|
||||
// Make player
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
@ -618,7 +616,6 @@ public class LockAndBanListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testPlayerMoveInsideLockedIsland() {
|
||||
// Make player
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
@ -707,7 +704,6 @@ public class LockAndBanListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testVehicleMoveIntoLockedIsland() {
|
||||
// Make player
|
||||
Player player = mock(Player.class);
|
||||
|
@ -173,9 +173,8 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,13 +18,11 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import world.bentobox.bentobox.AbstractCommonSetup;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@ -47,13 +45,9 @@ public class CreeperListenerTest extends AbstractCommonSetup {
|
||||
cl = new CreeperListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,6 @@ import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -63,6 +62,7 @@ import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@ -91,10 +91,9 @@ public class InvincibleVisitorsListenerTest {
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ServerMocks.newServer();
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// Set up plugin
|
||||
@ -187,6 +186,7 @@ public class InvincibleVisitorsListenerTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
User.clearUsers();
|
||||
framework().clearInlineMocks();
|
||||
}
|
||||
@ -199,7 +199,6 @@ public class InvincibleVisitorsListenerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnClickNoPermission() {
|
||||
when(user.hasPermission(anyString())).thenReturn(false);
|
||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||
|
@ -29,7 +29,6 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.util.RayTraceResult;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -141,13 +140,11 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnPlayerInteract() {
|
||||
// Test incorrect items
|
||||
inHand = Material.ACACIA_DOOR;
|
||||
@ -157,7 +154,6 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnPlayerInteractBucketInHand() {
|
||||
// Test incorrect items
|
||||
inHand = Material.BUCKET;
|
||||
@ -167,7 +163,6 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnPlayerInteractObsidianAnvilInHand() {
|
||||
// Test with obsidian in hand
|
||||
inHand = Material.ANVIL;
|
||||
@ -177,7 +172,6 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnPlayerInteractObsidianBucketInHand() {
|
||||
// Positive test with 1 bucket in the stack
|
||||
inHand = Material.BUCKET;
|
||||
@ -187,7 +181,6 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testOnPlayerInteractObsidianManyBucketsInHand() {
|
||||
// Positive test with 1 bucket in the stack
|
||||
inHand = Material.BUCKET;
|
||||
|
@ -111,12 +111,9 @@ public class VisitorKeepInventoryListenerTest extends AbstractCommonSetup {
|
||||
l = new VisitorKeepInventoryListener();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,6 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -42,6 +41,7 @@ import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.blueprints.Blueprint;
|
||||
import world.bentobox.bentobox.blueprints.BlueprintClipboard;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
|
||||
@ -104,7 +104,7 @@ public class BlueprintClipboardManagerTest {
|
||||
" \"ySize\": 10,\n" +
|
||||
" \"zSize\": 10\n" +
|
||||
"}";
|
||||
@Mock
|
||||
|
||||
private Server server;
|
||||
|
||||
private void zip(File targetFile) throws IOException {
|
||||
@ -129,6 +129,7 @@ public class BlueprintClipboardManagerTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
server = ServerMocks.newServer();
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
blueprintFolder = new File("blueprints");
|
||||
@ -153,7 +154,7 @@ public class BlueprintClipboardManagerTest {
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
|
||||
ServerMocks.unsetBukkitServer();
|
||||
if (blueprintFolder.exists()) {
|
||||
// Clean up file system
|
||||
Files.walk(blueprintFolder.toPath())
|
||||
@ -232,7 +233,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testLoadBlueprintFileInZipJSONError() throws IOException {
|
||||
blueprintFolder.mkdirs();
|
||||
// Make a blueprint file
|
||||
@ -256,7 +256,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testLoadBlueprintFileInZipNoBedrock() throws IOException {
|
||||
blueprintFolder.mkdirs();
|
||||
// Make a blueprint file
|
||||
@ -277,7 +276,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testLoadBlueprintFileInZip() throws IOException {
|
||||
blueprintFolder.mkdirs();
|
||||
// Make a blueprint file
|
||||
@ -299,7 +297,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#load(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testLoadString() throws IOException {
|
||||
blueprintFolder.mkdirs();
|
||||
// Make a blueprint file
|
||||
@ -322,7 +319,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#load(world.bentobox.bentobox.api.user.User, java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testLoadUserString() throws IOException {
|
||||
blueprintFolder.mkdirs();
|
||||
// Make a blueprint file
|
||||
@ -352,7 +348,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testSave() throws IOException {
|
||||
// Load a blueprint, then save it
|
||||
blueprintFolder.mkdirs();
|
||||
@ -374,7 +369,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testSaveBadChars() throws IOException {
|
||||
// Load a blueprint, then save it
|
||||
blueprintFolder.mkdirs();
|
||||
@ -396,7 +390,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testSaveForeignChars() throws IOException {
|
||||
// Load a blueprint, then save it
|
||||
blueprintFolder.mkdirs();
|
||||
@ -418,7 +411,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testSaveForeignBadChars() throws IOException {
|
||||
// Load a blueprint, then save it
|
||||
blueprintFolder.mkdirs();
|
||||
@ -453,7 +445,6 @@ public class BlueprintClipboardManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#saveBlueprint(world.bentobox.bentobox.blueprints.Blueprint)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testSaveBlueprintSuccess() {
|
||||
BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder);
|
||||
Blueprint blueprint = new Blueprint();
|
||||
|
@ -37,7 +37,6 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -61,6 +60,7 @@ import world.bentobox.bentobox.blueprints.BlueprintPaster;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
@ -99,11 +99,12 @@ public class BlueprintsManagerTest {
|
||||
private BukkitTask task;
|
||||
|
||||
private int times;
|
||||
@Mock
|
||||
|
||||
private Server server;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
server = ServerMocks.newServer();
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
@ -188,6 +189,7 @@ public class BlueprintsManagerTest {
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
// Clean up file system
|
||||
deleteDir(dataFolder.toPath());
|
||||
// Delete addon.jar
|
||||
@ -259,7 +261,6 @@ public class BlueprintsManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintsManager#loadBlueprintBundles(world.bentobox.bentobox.api.addons.GameModeAddon)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testLoadBlueprintBundlesNoBlueprintFolder() {
|
||||
// Set up running and verification
|
||||
when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer<BukkitTask>) invocation -> {
|
||||
@ -280,7 +281,6 @@ public class BlueprintsManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintsManager#loadBlueprintBundles(world.bentobox.bentobox.api.addons.GameModeAddon)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testLoadBlueprintBundles() {
|
||||
// Set up running and verification
|
||||
when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer<BukkitTask>) invocation -> {
|
||||
@ -319,7 +319,6 @@ public class BlueprintsManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintsManager#loadBlueprints(world.bentobox.bentobox.api.addons.GameModeAddon)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testLoadBlueprints() {
|
||||
// Set up running and verification
|
||||
when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer<BukkitTask>) invocation -> {
|
||||
@ -352,7 +351,6 @@ public class BlueprintsManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintsManager#saveBlueprint(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.blueprints.Blueprint)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testSaveBlueprint() {
|
||||
// Save it
|
||||
BlueprintsManager bpm = new BlueprintsManager(plugin);
|
||||
@ -650,7 +648,6 @@ public class BlueprintsManagerTest {
|
||||
* Test method for {@link world.bentobox.bentobox.managers.BlueprintsManager#renameBlueprint(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.blueprints.Blueprint, java.lang.String, java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
@Ignore("Enums")
|
||||
public void testRenameBlueprint() {
|
||||
// Save it
|
||||
BlueprintsManager bpm = new BlueprintsManager(plugin);
|
||||
|
@ -45,7 +45,6 @@ import org.bukkit.util.Vector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@ -66,6 +65,7 @@ import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.database.objects.Names;
|
||||
import world.bentobox.bentobox.database.objects.Players;
|
||||
import world.bentobox.bentobox.hooks.VaultHook;
|
||||
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
@ -74,7 +74,6 @@ import world.bentobox.bentobox.util.Util;
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class, Logger.class, DatabaseSetup.class })
|
||||
@Ignore("Enums")
|
||||
public class PlayersManagerTest {
|
||||
|
||||
private static AbstractDatabaseHandler<Object> handler;
|
||||
@ -136,6 +135,8 @@ public class PlayersManagerTest {
|
||||
public void setUp() throws Exception {
|
||||
// Clear any lingering database
|
||||
tearDown();
|
||||
|
||||
ServerMocks.newServer();
|
||||
// Set up plugin
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
when(plugin.getVault()).thenReturn(Optional.of(vault));
|
||||
@ -273,6 +274,7 @@ public class PlayersManagerTest {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
ServerMocks.unsetBukkitServer();
|
||||
User.clearUsers();
|
||||
Mockito.framework().clearInlineMocks();
|
||||
deleteAll(new File("database"));
|
||||
|
118
src/test/java/world/bentobox/bentobox/mocks/ServerMocks.java
Normal file
118
src/test/java/world/bentobox/bentobox/mocks/ServerMocks.java
Normal file
@ -0,0 +1,118 @@
|
||||
package world.bentobox.bentobox.mocks;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.notNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
public final class ServerMocks {
|
||||
|
||||
public static @NonNull Server newServer() {
|
||||
Server mock = mock(Server.class);
|
||||
|
||||
Logger noOp = mock(Logger.class);
|
||||
when(mock.getLogger()).thenReturn(noOp);
|
||||
when(mock.isPrimaryThread()).thenReturn(true);
|
||||
|
||||
// Unsafe
|
||||
UnsafeValues unsafe = mock(UnsafeValues.class);
|
||||
when(mock.getUnsafe()).thenReturn(unsafe);
|
||||
|
||||
// Server must be available before tags can be mocked.
|
||||
Bukkit.setServer(mock);
|
||||
|
||||
// Bukkit has a lot of static constants referencing registry values. To initialize those, the
|
||||
// registries must be able to be fetched before the classes are touched.
|
||||
Map<Class<? extends Keyed>, Object> registers = new HashMap<>();
|
||||
|
||||
doAnswer(invocationGetRegistry -> registers.computeIfAbsent(invocationGetRegistry.getArgument(0), clazz -> {
|
||||
Registry<?> registry = mock(Registry.class);
|
||||
Map<NamespacedKey, Keyed> cache = new HashMap<>();
|
||||
doAnswer(invocationGetEntry -> {
|
||||
NamespacedKey key = invocationGetEntry.getArgument(0);
|
||||
// Some classes (like BlockType and ItemType) have extra generics that will be
|
||||
// erased during runtime calls. To ensure accurate typing, grab the constant's field.
|
||||
// This approach also allows us to return null for unsupported keys.
|
||||
Class<? extends Keyed> constantClazz;
|
||||
try {
|
||||
//noinspection unchecked
|
||||
constantClazz = (Class<? extends Keyed>) clazz
|
||||
.getField(key.getKey().toUpperCase(Locale.ROOT).replace('.', '_')).getType();
|
||||
} catch (ClassCastException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchFieldException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cache.computeIfAbsent(key, key1 -> {
|
||||
Keyed keyed = mock(constantClazz);
|
||||
doReturn(key).when(keyed).getKey();
|
||||
return keyed;
|
||||
});
|
||||
}).when(registry).get(notNull());
|
||||
return registry;
|
||||
})).when(mock).getRegistry(notNull());
|
||||
|
||||
// Tags are dependent on registries, but use a different method.
|
||||
// This will set up blank tags for each constant; all that needs to be done to render them
|
||||
// functional is to re-mock Tag#getValues.
|
||||
doAnswer(invocationGetTag -> {
|
||||
Tag<?> tag = mock(Tag.class);
|
||||
doReturn(invocationGetTag.getArgument(1)).when(tag).getKey();
|
||||
doReturn(Set.of()).when(tag).getValues();
|
||||
doAnswer(invocationIsTagged -> {
|
||||
Keyed keyed = invocationIsTagged.getArgument(0);
|
||||
Class<?> type = invocationGetTag.getArgument(2);
|
||||
if (!type.isAssignableFrom(keyed.getClass())) {
|
||||
return null;
|
||||
}
|
||||
// Since these are mocks, the exact instance might not be equal. Consider equal keys equal.
|
||||
return tag.getValues().contains(keyed)
|
||||
|| tag.getValues().stream().anyMatch(value -> value.getKey().equals(keyed.getKey()));
|
||||
}).when(tag).isTagged(notNull());
|
||||
return tag;
|
||||
}).when(mock).getTag(notNull(), notNull(), notNull());
|
||||
|
||||
// Once the server is all set up, touch BlockType and ItemType to initialize.
|
||||
// This prevents issues when trying to access dependent methods from a Material constant.
|
||||
try {
|
||||
Class.forName("org.bukkit.inventory.ItemType");
|
||||
Class.forName("org.bukkit.block.BlockType");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return mock;
|
||||
}
|
||||
|
||||
public static void unsetBukkitServer() {
|
||||
try {
|
||||
Field server = Bukkit.class.getDeclaredField("server");
|
||||
server.setAccessible(true);
|
||||
server.set(null, null);
|
||||
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ServerMocks() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user