mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 02:35:21 +01:00
Merge pull request #2550 from BentoBoxWorld/custom_server
Use custom server to handle new enums
This commit is contained in:
commit
c77da07d82
2
pom.xml
2
pom.xml
@ -52,7 +52,7 @@
|
|||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>codemc-releases</id>
|
<id>codemc-releases</id>
|
||||||
<url>https://repo.codemc.org/repository/bentoboxworld</url>
|
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@ package world.bentobox.bentobox.database.json.adapters;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Registry;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
|
|
||||||
import com.google.gson.TypeAdapter;
|
import com.google.gson.TypeAdapter;
|
||||||
@ -32,11 +32,12 @@ public final class BiomeTypeAdapter extends TypeAdapter<Biome>
|
|||||||
*/
|
*/
|
||||||
final Map<String, Biome> biomeMap;
|
final Map<String, Biome> biomeMap;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public BiomeTypeAdapter() {
|
public BiomeTypeAdapter() {
|
||||||
this.biomeMap = new HashMap<>();
|
this.biomeMap = new HashMap<>();
|
||||||
|
|
||||||
// Put in current values.
|
// 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.
|
// Put in renamed biomes values.
|
||||||
this.biomeMap.put("TALL_BIRCH_FOREST", Biome.OLD_GROWTH_BIRCH_FOREST);
|
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 java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Keyed;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Registry;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.configuration.MemorySection;
|
import org.bukkit.configuration.MemorySection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -216,10 +221,24 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
try {
|
try {
|
||||||
// Floats need special handling because the database returns them as doubles
|
// Floats need special handling because the database returns them as doubles
|
||||||
Type setType = propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0];
|
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")) {
|
if (setType.getTypeName().equals("float")) {
|
||||||
double d = (double) setTo;
|
double d = (double) setTo;
|
||||||
float f = (float)d;
|
float f = (float)d;
|
||||||
method.invoke(instance, f);
|
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 {
|
} else {
|
||||||
method.invoke(instance, setTo);
|
method.invoke(instance, setTo);
|
||||||
}
|
}
|
||||||
@ -368,8 +387,9 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Get the read method
|
// Get the read method
|
||||||
Method method = propertyDescriptor.getReadMethod();
|
Method method = propertyDescriptor.getReadMethod();
|
||||||
// Invoke the read method to get the value. We have no idea what type of value it is.
|
// 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);
|
Object value = method.invoke(instance);
|
||||||
|
BentoBox.getInstance().logDebug("Value is " + value);
|
||||||
String storageLocation = field.getName();
|
String storageLocation = field.getName();
|
||||||
|
|
||||||
// Check if there is an annotation on the field
|
// 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)) {
|
if (!checkAdapter(field, config, storageLocation, value)) {
|
||||||
|
BentoBox.getInstance().logDebug("No adapter");
|
||||||
// Set the filename if it has not be set already
|
// Set the filename if it has not be set already
|
||||||
if (filename.isEmpty() && method.getName().equals("getUniqueId")) {
|
if (filename.isEmpty() && method.getName().equals("getUniqueId")) {
|
||||||
// Save the name for when the file is saved
|
// 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);
|
serializeSet((Set<Object>)value, config, storageLocation);
|
||||||
} else {
|
} else {
|
||||||
// For all other data that doesn't need special serialization
|
// 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));
|
config.set(storageLocation, serialize(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,6 +583,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
private Object serialize(@Nullable Object object) {
|
private Object serialize(@Nullable Object object) {
|
||||||
// Null is a value object and is serialized as the string "null"
|
// Null is a value object and is serialized as the string "null"
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
|
BentoBox.getInstance().logDebug("Object is null");
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
// UUID has it's own serialization, that is not picked up automatically
|
// 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) {
|
if (object instanceof Location l) {
|
||||||
return Util.getStringLocation(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
|
// Enums
|
||||||
if (object instanceof Enum<?> e) {
|
if (object instanceof Enum<?> e) {
|
||||||
//Custom enums are a child of the Enum class. Just get the names of each one.
|
//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");
|
throw new IllegalStateException("Class " + clazz.getName() + " does not implement WorldRegenerator");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
plugin.logWarning("No Regenerator found for " + bukkitVersion + ", falling back to Bukkit API.");
|
plugin.logWarning("No Regenerator found for " + bukkitVersion + ", falling back to Bukkit API.");
|
||||||
handler = new world.bentobox.bentobox.nms.fallback.WorldRegeneratorImpl();
|
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");
|
throw new IllegalStateException("Class " + clazz.getName() + " does not implement PasteHandler");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
plugin.logWarning("No PasteHandler found for " + bukkitVersion + ", falling back to Bukkit API.");
|
plugin.logWarning("No PasteHandler found for " + bukkitVersion + ", falling back to Bukkit API.");
|
||||||
handler = new world.bentobox.bentobox.nms.fallback.PasteHandlerImpl();
|
handler = new world.bentobox.bentobox.nms.fallback.PasteHandlerImpl();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import java.util.UUID;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Server;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -34,6 +35,7 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
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.LocalesManager;
|
||||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,9 +106,13 @@ public abstract class AbstractCommonSetup {
|
|||||||
protected FlagsManager fm;
|
protected FlagsManager fm;
|
||||||
@Mock
|
@Mock
|
||||||
protected Spigot spigot;
|
protected Spigot spigot;
|
||||||
|
protected Server server;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
|
server = ServerMocks.newServer();
|
||||||
// Bukkit
|
// Bukkit
|
||||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
@ -221,6 +228,7 @@ public abstract class AbstractCommonSetup {
|
|||||||
*/
|
*/
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
User.clearUsers();
|
User.clearUsers();
|
||||||
Mockito.framework().clearInlineMocks();
|
Mockito.framework().clearInlineMocks();
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
|||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
|
||||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
||||||
import world.bentobox.bentobox.database.DatabaseSetup;
|
import world.bentobox.bentobox.database.DatabaseSetup;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
@ -126,9 +125,8 @@ public abstract class RanksManagerBeforeClassTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
deleteAll(new File("database"));
|
deleteAll(new File("database"));
|
||||||
deleteAll(new File("database_backup"));
|
deleteAll(new File("database_backup"));
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
@ -128,12 +127,9 @@ public class AdminResetFlagsCommandTest extends AbstractCommonSetup {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +24,7 @@ import java.util.UUID;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.CommandsManager;
|
||||||
import world.bentobox.bentobox.managers.HooksManager;
|
import world.bentobox.bentobox.managers.HooksManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
@ -68,8 +69,11 @@ public class AdminBlueprintLoadCommandTest {
|
|||||||
private Map<String, Blueprint> map;
|
private Map<String, Blueprint> map;
|
||||||
private File blueprintsFolder;
|
private File blueprintsFolder;
|
||||||
|
|
||||||
/**
|
@BeforeClass
|
||||||
*/
|
public static void beforeClass() {
|
||||||
|
ServerMocks.newServer();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
@ -125,8 +129,6 @@ public class AdminBlueprintLoadCommandTest {
|
|||||||
abcc = new AdminBlueprintLoadCommand(ac);
|
abcc = new AdminBlueprintLoadCommand(ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
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 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
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testExecuteUserStringListOfStringSuccessCaps() {
|
public void testExecuteUserStringListOfStringSuccessCaps() {
|
||||||
assertTrue(abcc.execute(user, "", List.of("island")));
|
assertTrue(abcc.execute(user, "", List.of("island")));
|
||||||
verify(user).sendMessage("general.success");
|
verify(user).sendMessage("general.success");
|
||||||
|
@ -25,7 +25,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.CommandsManager;
|
||||||
import world.bentobox.bentobox.managers.HooksManager;
|
import world.bentobox.bentobox.managers.HooksManager;
|
||||||
import world.bentobox.bentobox.managers.LocalesManager;
|
import world.bentobox.bentobox.managers.LocalesManager;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
@ -68,8 +69,11 @@ public class AdminBlueprintSaveCommandTest {
|
|||||||
private BlueprintsManager bm;
|
private BlueprintsManager bm;
|
||||||
private Blueprint bp = new Blueprint();
|
private Blueprint bp = new Blueprint();
|
||||||
|
|
||||||
/**
|
@BeforeClass
|
||||||
*/
|
public static void beforeClass() {
|
||||||
|
ServerMocks.newServer();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Set up plugin
|
// 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 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
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testExecuteUserStringListOfString() {
|
public void testExecuteUserStringListOfString() {
|
||||||
testCanExecute();
|
testCanExecute();
|
||||||
assertTrue(absc.execute(user, "", List.of("island")));
|
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 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
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testExecuteUserStringListOfStringFileExists() {
|
public void testExecuteUserStringListOfStringFileExists() {
|
||||||
testCanExecute();
|
testCanExecute();
|
||||||
assertTrue(absc.execute(user, "", List.of("island")));
|
assertTrue(absc.execute(user, "", List.of("island")));
|
||||||
|
@ -94,9 +94,8 @@ public class AdminRangeCommandTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -117,9 +117,8 @@ public class AdminRangeResetCommandTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,9 +119,8 @@ public class AdminRangeSetCommandTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,6 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.framework;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@ -152,9 +151,8 @@ public class AdminTeamDisbandCommandTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,13 +21,12 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -75,12 +74,11 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
|||||||
private Addon addon;
|
private Addon addon;
|
||||||
|
|
||||||
private IslandExpelCommand iec;
|
private IslandExpelCommand iec;
|
||||||
@Mock
|
|
||||||
private Server server;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
|
|
||||||
// Command manager
|
// Command manager
|
||||||
@ -97,7 +95,6 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
|||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
when(user.getUniqueId()).thenReturn(uuid);
|
when(user.getUniqueId()).thenReturn(uuid);
|
||||||
when(server.getOnlinePlayers()).thenReturn(Collections.emptySet());
|
|
||||||
when(mockPlayer.getServer()).thenReturn(server);
|
when(mockPlayer.getServer()).thenReturn(server);
|
||||||
when(user.getPlayer()).thenReturn(mockPlayer);
|
when(user.getPlayer()).thenReturn(mockPlayer);
|
||||||
when(user.getName()).thenReturn("tastybento");
|
when(user.getName()).thenReturn("tastybento");
|
||||||
@ -155,6 +152,11 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
|
|||||||
iec = new IslandExpelCommand(ic);
|
iec = new IslandExpelCommand(ic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#IslandExpelCommand(world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
* {@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)}.
|
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testExecuteUserStringListOfStringHasIsland() {
|
public void testExecuteUserStringListOfStringHasIsland() {
|
||||||
testCanExecute();
|
testCanExecute();
|
||||||
assertTrue(iec.execute(user, "", Collections.singletonList("tasty")));
|
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)}.
|
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testExecuteUserStringListOfStringNoIslandSendToSpawn() {
|
public void testExecuteUserStringListOfStringNoIslandSendToSpawn() {
|
||||||
Optional<Island> optionalIsland = Optional.of(island);
|
Optional<Island> optionalIsland = Optional.of(island);
|
||||||
when(im.getSpawn(any())).thenReturn(optionalIsland);
|
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)}.
|
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testExecuteUserStringListOfStringCreateIsland() {
|
public void testExecuteUserStringListOfStringCreateIsland() {
|
||||||
GameModeAddon gma = mock(GameModeAddon.class);
|
GameModeAddon gma = mock(GameModeAddon.class);
|
||||||
CompositeCommand pc = mock(CompositeCommand.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)}.
|
* {@link world.bentobox.bentobox.api.commands.island.IslandExpelCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testExecuteUserStringListOfStringCreateIslandFailCommand() {
|
public void testExecuteUserStringListOfStringCreateIslandFailCommand() {
|
||||||
GameModeAddon gma = mock(GameModeAddon.class);
|
GameModeAddon gma = mock(GameModeAddon.class);
|
||||||
CompositeCommand pc = mock(CompositeCommand.class);
|
CompositeCommand pc = mock(CompositeCommand.class);
|
||||||
|
@ -176,9 +176,8 @@ public class IslandGoCommandTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,6 +187,10 @@ public class IslandResetCommandTest extends AbstractCommonSetup {
|
|||||||
irc = new IslandResetCommand(ic);
|
irc = new IslandResetCommand(ic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Test method for
|
* Test method for
|
||||||
* {@link IslandResetCommand#canExecute(User, String, java.util.List)}
|
* {@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);
|
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)}
|
* Test method for {@link IslandResetCommand#canExecute(User, String, java.util.List)}
|
||||||
*/
|
*/
|
||||||
|
@ -130,12 +130,9 @@ public class IslandSpawnCommandTest extends AbstractCommonSetup {
|
|||||||
isc = new IslandSpawnCommand(ic);
|
isc = new IslandSpawnCommand(ic);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,6 @@ import org.bukkit.scheduler.BukkitScheduler;
|
|||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.LocalesManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.panels.settings.SettingsTab;
|
import world.bentobox.bentobox.panels.settings.SettingsTab;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@ -96,12 +96,13 @@ public class CycleClickTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private @NonNull Player p;
|
private @NonNull Player p;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception - exception
|
* @throws java.lang.Exception - exception
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
ServerMocks.newServer();
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
@ -234,11 +235,11 @@ public class CycleClickTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
Mockito.framework().clearInlineMocks();
|
Mockito.framework().clearInlineMocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testNoPremission() {
|
public void testNoPremission() {
|
||||||
when(user.hasPermission(anyString())).thenReturn(false);
|
when(user.hasPermission(anyString())).thenReturn(false);
|
||||||
CycleClick udc = new CycleClick(LOCK);
|
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 for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnLeftClick() {
|
public void testOnLeftClick() {
|
||||||
final int SLOT = 5;
|
final int SLOT = 5;
|
||||||
CycleClick udc = new CycleClick(LOCK);
|
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 for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnLeftClickSetMinMax() {
|
public void testOnLeftClickSetMinMax() {
|
||||||
// Provide a current rank value - coop
|
// Provide a current rank value - coop
|
||||||
when(island.getFlag(any())).thenReturn(RanksManager.COOP_RANK);
|
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 for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnRightClick() {
|
public void testOnRightClick() {
|
||||||
final int SLOT = 5;
|
final int SLOT = 5;
|
||||||
CycleClick udc = new CycleClick(LOCK);
|
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 for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnRightClickMinMaxSet() {
|
public void testOnRightClickMinMaxSet() {
|
||||||
// Provide a current rank value - coop
|
// Provide a current rank value - coop
|
||||||
when(island.getFlag(any())).thenReturn(RanksManager.TRUSTED_RANK);
|
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 for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testAllClicks() {
|
public void testAllClicks() {
|
||||||
// Test all possible click types
|
// Test all possible click types
|
||||||
CycleClick udc = new CycleClick(LOCK);
|
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 for {@link CycleClick#onClick(world.bentobox.bentobox.api.panels.Panel, User, ClickType, int)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnShiftLeftClickIsOp() {
|
public void testOnShiftLeftClickIsOp() {
|
||||||
when(user.isOp()).thenReturn(true);
|
when(user.isOp()).thenReturn(true);
|
||||||
CycleClick udc = new CycleClick(LOCK);
|
CycleClick udc = new CycleClick(LOCK);
|
||||||
@ -384,7 +379,6 @@ public class CycleClickTest {
|
|||||||
assertTrue(udc.onClick(panel, user, ClickType.SHIFT_LEFT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.SHIFT_LEFT, SLOT));
|
||||||
assertTrue(hiddenFlags.isEmpty());
|
assertTrue(hiddenFlags.isEmpty());
|
||||||
// Verify sounds
|
// Verify sounds
|
||||||
verify(p).playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
verify(p, times(2)).playSound((Location) null, (Sound) null, 1F, 1F);
|
||||||
verify(p).playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.FlagsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.panels.settings.SettingsTab;
|
import world.bentobox.bentobox.panels.settings.SettingsTab;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@ -68,6 +68,7 @@ public class IslandToggleClickTest {
|
|||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
ServerMocks.newServer();
|
||||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
|
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
@ -120,11 +121,11 @@ public class IslandToggleClickTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
Mockito.framework().clearInlineMocks();
|
Mockito.framework().clearInlineMocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClickNoPermission() {
|
public void testOnClickNoPermission() {
|
||||||
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
@ -132,7 +133,6 @@ public class IslandToggleClickTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClick() {
|
public void testOnClick() {
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
verify(island).toggleFlag(flag);
|
verify(island).toggleFlag(flag);
|
||||||
@ -140,7 +140,6 @@ public class IslandToggleClickTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClickNoIsland() {
|
public void testOnClickNoIsland() {
|
||||||
when(settingsTab.getIsland()).thenReturn(null);
|
when(settingsTab.getIsland()).thenReturn(null);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
@ -148,7 +147,6 @@ public class IslandToggleClickTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClickNotOwner() {
|
public void testOnClickNotOwner() {
|
||||||
// No permission
|
// No permission
|
||||||
when(user.hasPermission(anyString())).thenReturn(false);
|
when(user.hasPermission(anyString())).thenReturn(false);
|
||||||
|
@ -19,7 +19,6 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.api.user.User;
|
||||||
import world.bentobox.bentobox.managers.FlagsManager;
|
import world.bentobox.bentobox.managers.FlagsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@ -58,10 +58,9 @@ public class WorldToggleClickTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
ServerMocks.newServer();
|
||||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
@ -105,6 +104,7 @@ public class WorldToggleClickTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
Mockito.framework().clearInlineMocks();
|
Mockito.framework().clearInlineMocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,6 @@ public class WorldToggleClickTest {
|
|||||||
* Test for {@link WorldToggleClick#onClick(Panel, User, ClickType, int)}
|
* Test for {@link WorldToggleClick#onClick(Panel, User, ClickType, int)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClickNoPermission() {
|
public void testOnClickNoPermission() {
|
||||||
when(user.hasPermission(anyString())).thenReturn(false);
|
when(user.hasPermission(anyString())).thenReturn(false);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
@ -124,7 +123,6 @@ public class WorldToggleClickTest {
|
|||||||
* Test for {@link WorldToggleClick#onClick(Panel, User, ClickType, int)}
|
* Test for {@link WorldToggleClick#onClick(Panel, User, ClickType, int)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClick() {
|
public void testOnClick() {
|
||||||
when(user.hasPermission(anyString())).thenReturn(true);
|
when(user.hasPermission(anyString())).thenReturn(true);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
|
@ -45,7 +45,6 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
@ -136,9 +135,8 @@ public class UserTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,12 +106,9 @@ public class BentoBoxPermsCommandTest extends AbstractCommonSetup {
|
|||||||
cmd = new BentoBoxPermsCommand(ac);
|
cmd = new BentoBoxPermsCommand(ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
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.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
@ -206,9 +205,8 @@ public class JoinLeaveListenerTest extends RanksManagerBeforeClassTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,12 +119,9 @@ public class StandardSpawnProtectionListenerTest extends AbstractCommonSetup {
|
|||||||
ssp = new StandardSpawnProtectionListener(plugin);
|
ssp = new StandardSpawnProtectionListener(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ import org.bukkit.event.inventory.ClickType;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -149,6 +149,11 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
|
|||||||
crcl = new CommandRankClickListener();
|
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)}.
|
* 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 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
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClickNoPermission() {
|
public void testOnClickNoPermission() {
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
when(user.hasPermission(anyString())).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 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
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClickNoFlag() {
|
public void testOnClickNoFlag() {
|
||||||
when(island.isAllowed(user, Flags.CHANGE_SETTINGS)).thenReturn(false);
|
when(island.isAllowed(user, Flags.CHANGE_SETTINGS)).thenReturn(false);
|
||||||
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
|
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.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.LocalesManager;
|
||||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||||
import world.bentobox.bentobox.managers.PlayersManager;
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@ -88,6 +88,7 @@ public class LockAndBanListenerTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
ServerMocks.newServer();
|
||||||
// Server & Scheduler
|
// Server & Scheduler
|
||||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||||
@ -190,6 +191,7 @@ public class LockAndBanListenerTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
User.clearUsers();
|
User.clearUsers();
|
||||||
framework().clearInlineMocks();
|
framework().clearInlineMocks();
|
||||||
}
|
}
|
||||||
@ -299,7 +301,6 @@ public class LockAndBanListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testPlayerMoveIntoBannedIsland() {
|
public void testPlayerMoveIntoBannedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
@ -322,7 +323,6 @@ public class LockAndBanListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testPlayerMoveInsideBannedIsland() {
|
public void testPlayerMoveInsideBannedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
@ -350,7 +350,6 @@ public class LockAndBanListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testVehicleMoveIntoBannedIsland() {
|
public void testVehicleMoveIntoBannedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
@ -513,7 +512,6 @@ public class LockAndBanListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testPlayerMoveIntoLockedIsland() {
|
public void testPlayerMoveIntoLockedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
@ -618,7 +616,6 @@ public class LockAndBanListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testPlayerMoveInsideLockedIsland() {
|
public void testPlayerMoveInsideLockedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
@ -707,7 +704,6 @@ public class LockAndBanListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testVehicleMoveIntoLockedIsland() {
|
public void testVehicleMoveIntoLockedIsland() {
|
||||||
// Make player
|
// Make player
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
@ -173,9 +173,8 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,13 +18,11 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import world.bentobox.bentobox.AbstractCommonSetup;
|
import world.bentobox.bentobox.AbstractCommonSetup;
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@ -47,13 +45,9 @@ public class CreeperListenerTest extends AbstractCommonSetup {
|
|||||||
cl = new CreeperListener();
|
cl = new CreeperListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +41,6 @@ import org.bukkit.util.Vector;
|
|||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.FlagsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@ -91,10 +91,9 @@ public class InvincibleVisitorsListenerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PluginManager pim;
|
private PluginManager pim;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
ServerMocks.newServer();
|
||||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
|
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
@ -187,6 +186,7 @@ public class InvincibleVisitorsListenerTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
User.clearUsers();
|
User.clearUsers();
|
||||||
framework().clearInlineMocks();
|
framework().clearInlineMocks();
|
||||||
}
|
}
|
||||||
@ -199,7 +199,6 @@ public class InvincibleVisitorsListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnClickNoPermission() {
|
public void testOnClickNoPermission() {
|
||||||
when(user.hasPermission(anyString())).thenReturn(false);
|
when(user.hasPermission(anyString())).thenReturn(false);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
|
@ -29,7 +29,6 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
import org.bukkit.util.RayTraceResult;
|
import org.bukkit.util.RayTraceResult;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -141,13 +140,11 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnPlayerInteract() {
|
public void testOnPlayerInteract() {
|
||||||
// Test incorrect items
|
// Test incorrect items
|
||||||
inHand = Material.ACACIA_DOOR;
|
inHand = Material.ACACIA_DOOR;
|
||||||
@ -157,7 +154,6 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnPlayerInteractBucketInHand() {
|
public void testOnPlayerInteractBucketInHand() {
|
||||||
// Test incorrect items
|
// Test incorrect items
|
||||||
inHand = Material.BUCKET;
|
inHand = Material.BUCKET;
|
||||||
@ -167,7 +163,6 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnPlayerInteractObsidianAnvilInHand() {
|
public void testOnPlayerInteractObsidianAnvilInHand() {
|
||||||
// Test with obsidian in hand
|
// Test with obsidian in hand
|
||||||
inHand = Material.ANVIL;
|
inHand = Material.ANVIL;
|
||||||
@ -177,7 +172,6 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnPlayerInteractObsidianBucketInHand() {
|
public void testOnPlayerInteractObsidianBucketInHand() {
|
||||||
// Positive test with 1 bucket in the stack
|
// Positive test with 1 bucket in the stack
|
||||||
inHand = Material.BUCKET;
|
inHand = Material.BUCKET;
|
||||||
@ -187,7 +181,6 @@ public class ObsidianScoopingListenerTest extends AbstractCommonSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testOnPlayerInteractObsidianManyBucketsInHand() {
|
public void testOnPlayerInteractObsidianManyBucketsInHand() {
|
||||||
// Positive test with 1 bucket in the stack
|
// Positive test with 1 bucket in the stack
|
||||||
inHand = Material.BUCKET;
|
inHand = Material.BUCKET;
|
||||||
|
@ -111,12 +111,9 @@ public class VisitorKeepInventoryListenerTest extends AbstractCommonSetup {
|
|||||||
l = new VisitorKeepInventoryListener();
|
l = new VisitorKeepInventoryListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
User.clearUsers();
|
super.tearDown();
|
||||||
Mockito.framework().clearInlineMocks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,7 +28,6 @@ import org.bukkit.block.data.BlockData;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -42,6 +41,7 @@ import world.bentobox.bentobox.BentoBox;
|
|||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.blueprints.Blueprint;
|
import world.bentobox.bentobox.blueprints.Blueprint;
|
||||||
import world.bentobox.bentobox.blueprints.BlueprintClipboard;
|
import world.bentobox.bentobox.blueprints.BlueprintClipboard;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ public class BlueprintClipboardManagerTest {
|
|||||||
" \"ySize\": 10,\n" +
|
" \"ySize\": 10,\n" +
|
||||||
" \"zSize\": 10\n" +
|
" \"zSize\": 10\n" +
|
||||||
"}";
|
"}";
|
||||||
@Mock
|
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|
||||||
private void zip(File targetFile) throws IOException {
|
private void zip(File targetFile) throws IOException {
|
||||||
@ -129,6 +129,7 @@ public class BlueprintClipboardManagerTest {
|
|||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
server = ServerMocks.newServer();
|
||||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||||
|
|
||||||
blueprintFolder = new File("blueprints");
|
blueprintFolder = new File("blueprints");
|
||||||
@ -153,7 +154,7 @@ public class BlueprintClipboardManagerTest {
|
|||||||
*/
|
*/
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
if (blueprintFolder.exists()) {
|
if (blueprintFolder.exists()) {
|
||||||
// Clean up file system
|
// Clean up file system
|
||||||
Files.walk(blueprintFolder.toPath())
|
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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testLoadBlueprintFileInZipJSONError() throws IOException {
|
public void testLoadBlueprintFileInZipJSONError() throws IOException {
|
||||||
blueprintFolder.mkdirs();
|
blueprintFolder.mkdirs();
|
||||||
// Make a blueprint file
|
// 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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testLoadBlueprintFileInZipNoBedrock() throws IOException {
|
public void testLoadBlueprintFileInZipNoBedrock() throws IOException {
|
||||||
blueprintFolder.mkdirs();
|
blueprintFolder.mkdirs();
|
||||||
// Make a blueprint file
|
// 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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#loadBlueprint(java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testLoadBlueprintFileInZip() throws IOException {
|
public void testLoadBlueprintFileInZip() throws IOException {
|
||||||
blueprintFolder.mkdirs();
|
blueprintFolder.mkdirs();
|
||||||
// Make a blueprint file
|
// 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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#load(java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testLoadString() throws IOException {
|
public void testLoadString() throws IOException {
|
||||||
blueprintFolder.mkdirs();
|
blueprintFolder.mkdirs();
|
||||||
// Make a blueprint file
|
// 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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#load(world.bentobox.bentobox.api.user.User, java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testLoadUserString() throws IOException {
|
public void testLoadUserString() throws IOException {
|
||||||
blueprintFolder.mkdirs();
|
blueprintFolder.mkdirs();
|
||||||
// Make a blueprint file
|
// 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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testSave() throws IOException {
|
public void testSave() throws IOException {
|
||||||
// Load a blueprint, then save it
|
// Load a blueprint, then save it
|
||||||
blueprintFolder.mkdirs();
|
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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testSaveBadChars() throws IOException {
|
public void testSaveBadChars() throws IOException {
|
||||||
// Load a blueprint, then save it
|
// Load a blueprint, then save it
|
||||||
blueprintFolder.mkdirs();
|
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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testSaveForeignChars() throws IOException {
|
public void testSaveForeignChars() throws IOException {
|
||||||
// Load a blueprint, then save it
|
// Load a blueprint, then save it
|
||||||
blueprintFolder.mkdirs();
|
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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#save(world.bentobox.bentobox.api.user.User, java.lang.String, java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testSaveForeignBadChars() throws IOException {
|
public void testSaveForeignBadChars() throws IOException {
|
||||||
// Load a blueprint, then save it
|
// Load a blueprint, then save it
|
||||||
blueprintFolder.mkdirs();
|
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 method for {@link world.bentobox.bentobox.managers.BlueprintClipboardManager#saveBlueprint(world.bentobox.bentobox.blueprints.Blueprint)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testSaveBlueprintSuccess() {
|
public void testSaveBlueprintSuccess() {
|
||||||
BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder);
|
BlueprintClipboardManager bcm = new BlueprintClipboardManager(plugin, blueprintFolder);
|
||||||
Blueprint blueprint = new Blueprint();
|
Blueprint blueprint = new Blueprint();
|
||||||
|
@ -37,7 +37,6 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.BlueprintBlock;
|
||||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,11 +99,12 @@ public class BlueprintsManagerTest {
|
|||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
|
|
||||||
private int times;
|
private int times;
|
||||||
@Mock
|
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
server = ServerMocks.newServer();
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
@ -188,6 +189,7 @@ public class BlueprintsManagerTest {
|
|||||||
*/
|
*/
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
// Clean up file system
|
// Clean up file system
|
||||||
deleteDir(dataFolder.toPath());
|
deleteDir(dataFolder.toPath());
|
||||||
// Delete addon.jar
|
// 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 method for {@link world.bentobox.bentobox.managers.BlueprintsManager#loadBlueprintBundles(world.bentobox.bentobox.api.addons.GameModeAddon)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testLoadBlueprintBundlesNoBlueprintFolder() {
|
public void testLoadBlueprintBundlesNoBlueprintFolder() {
|
||||||
// Set up running and verification
|
// Set up running and verification
|
||||||
when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer<BukkitTask>) invocation -> {
|
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 method for {@link world.bentobox.bentobox.managers.BlueprintsManager#loadBlueprintBundles(world.bentobox.bentobox.api.addons.GameModeAddon)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testLoadBlueprintBundles() {
|
public void testLoadBlueprintBundles() {
|
||||||
// Set up running and verification
|
// Set up running and verification
|
||||||
when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer<BukkitTask>) invocation -> {
|
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 method for {@link world.bentobox.bentobox.managers.BlueprintsManager#loadBlueprints(world.bentobox.bentobox.api.addons.GameModeAddon)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testLoadBlueprints() {
|
public void testLoadBlueprints() {
|
||||||
// Set up running and verification
|
// Set up running and verification
|
||||||
when(scheduler.runTaskAsynchronously(eq(plugin), any(Runnable.class))).thenAnswer((Answer<BukkitTask>) invocation -> {
|
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 method for {@link world.bentobox.bentobox.managers.BlueprintsManager#saveBlueprint(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.blueprints.Blueprint)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testSaveBlueprint() {
|
public void testSaveBlueprint() {
|
||||||
// Save it
|
// Save it
|
||||||
BlueprintsManager bpm = new BlueprintsManager(plugin);
|
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 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
|
@Test
|
||||||
@Ignore("Enums")
|
|
||||||
public void testRenameBlueprint() {
|
public void testRenameBlueprint() {
|
||||||
// Save it
|
// Save it
|
||||||
BlueprintsManager bpm = new BlueprintsManager(plugin);
|
BlueprintsManager bpm = new BlueprintsManager(plugin);
|
||||||
|
@ -45,7 +45,6 @@ import org.bukkit.util.Vector;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
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.Names;
|
||||||
import world.bentobox.bentobox.database.objects.Players;
|
import world.bentobox.bentobox.database.objects.Players;
|
||||||
import world.bentobox.bentobox.hooks.VaultHook;
|
import world.bentobox.bentobox.hooks.VaultHook;
|
||||||
|
import world.bentobox.bentobox.mocks.ServerMocks;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,7 +74,6 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class, Logger.class, DatabaseSetup.class })
|
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class, Logger.class, DatabaseSetup.class })
|
||||||
@Ignore("Enums")
|
|
||||||
public class PlayersManagerTest {
|
public class PlayersManagerTest {
|
||||||
|
|
||||||
private static AbstractDatabaseHandler<Object> handler;
|
private static AbstractDatabaseHandler<Object> handler;
|
||||||
@ -136,6 +135,8 @@ public class PlayersManagerTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Clear any lingering database
|
// Clear any lingering database
|
||||||
tearDown();
|
tearDown();
|
||||||
|
|
||||||
|
ServerMocks.newServer();
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
when(plugin.getVault()).thenReturn(Optional.of(vault));
|
when(plugin.getVault()).thenReturn(Optional.of(vault));
|
||||||
@ -273,6 +274,7 @@ public class PlayersManagerTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
|
ServerMocks.unsetBukkitServer();
|
||||||
User.clearUsers();
|
User.clearUsers();
|
||||||
Mockito.framework().clearInlineMocks();
|
Mockito.framework().clearInlineMocks();
|
||||||
deleteAll(new File("database"));
|
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