mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Further improvements to Unit Tests
This commit is contained in:
parent
944c009afb
commit
ffa3ea1c1b
@ -36,7 +36,6 @@
|
||||
* Added Bamboo to possible fishing loot for the Fishing Android
|
||||
|
||||
#### Changes
|
||||
* Fixed a few memory leaks
|
||||
* Removed Digital Miner
|
||||
* Removed Advanced Digital Miner
|
||||
* Dried Kelp Blocks can now be used in the Coal Generator
|
||||
@ -52,6 +51,7 @@
|
||||
#### Fixes
|
||||
* Fixed Ore Washer recipes showing up twice
|
||||
* Fixed #1942
|
||||
* Fixed a few memory leaks
|
||||
* Fixed #1943
|
||||
* Fixed Nuclear Reactors accepting Lava as coolant
|
||||
* Fixed #1971
|
||||
@ -64,6 +64,7 @@
|
||||
* Fixed tab completion for /sf give showing players instead of amounts
|
||||
* Fixed #1993
|
||||
* Fixed #1907
|
||||
* Fixed research fireworks still dealing damage sometimes
|
||||
|
||||
## Release Candidate 12 (27 May 2020)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#12
|
||||
|
@ -9,6 +9,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.data.ComputedOptional;
|
||||
@ -37,12 +38,15 @@ public class Contributor {
|
||||
private boolean locked = false;
|
||||
|
||||
public Contributor(String username, String profile) {
|
||||
Validate.notNull(username, "Username must never be null!");
|
||||
Validate.notNull(profile, "The profile link must never be null!");
|
||||
githubUsername = profile.substring(profile.lastIndexOf('/') + 1);
|
||||
minecraftUsername = username;
|
||||
profileLink = profile;
|
||||
}
|
||||
|
||||
public Contributor(String username) {
|
||||
Validate.notNull(username, "Username must never be null!");
|
||||
githubUsername = username;
|
||||
minecraftUsername = username;
|
||||
profileLink = null;
|
||||
|
@ -1,9 +1,12 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
|
||||
@ -15,9 +18,14 @@ public class FireworksListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onResearchFireworkDamage(EntityDamageByEntityEvent e) {
|
||||
if (e.getDamager().getType() == EntityType.FIREWORK && e.getDamager().hasMetadata("no_fireworks_damage")) {
|
||||
if (e.getDamager().getType() == EntityType.FIREWORK) {
|
||||
Firework firework = (Firework) e.getDamager();
|
||||
FireworkMeta meta = firework.getFireworkMeta();
|
||||
|
||||
if (meta.hasDisplayName() && meta.getDisplayName().equals(ChatColor.GREEN + "Slimefun Research")) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.utils;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
@ -11,9 +12,6 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
|
||||
public final class FireworkUtils {
|
||||
|
||||
@ -23,9 +21,9 @@ public final class FireworkUtils {
|
||||
|
||||
public static void launchFirework(Location l, Color color) {
|
||||
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
|
||||
fw.setMetadata("no_fireworks_damage", new FixedMetadataValue(SlimefunPlugin.instance, true));
|
||||
|
||||
FireworkMeta meta = fw.getFireworkMeta();
|
||||
|
||||
meta.setDisplayName(ChatColor.GREEN + "Slimefun Research");
|
||||
FireworkEffect effect = getRandomEffect(ThreadLocalRandom.current(), color);
|
||||
meta.addEffect(effect);
|
||||
meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
|
||||
@ -34,9 +32,9 @@ public final class FireworkUtils {
|
||||
|
||||
public static Firework createFirework(Location l, Color color) {
|
||||
Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
|
||||
fw.setMetadata("no_fireworks_damage", new FixedMetadataValue(SlimefunPlugin.instance, true));
|
||||
|
||||
FireworkMeta meta = fw.getFireworkMeta();
|
||||
|
||||
meta.setDisplayName(ChatColor.GREEN + "Slimefun Research");
|
||||
FireworkEffect effect = FireworkEffect.builder().flicker(ThreadLocalRandom.current().nextBoolean()).withColor(color).with(ThreadLocalRandom.current().nextInt(3) + 1 == 1 ? Type.BALL : Type.BALL_LARGE).trail(ThreadLocalRandom.current().nextBoolean()).build();
|
||||
meta.addEffect(effect);
|
||||
meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
|
||||
|
@ -3,14 +3,19 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.items;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunItemSetup;
|
||||
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
|
||||
@TestMethodOrder(value = OrderAnnotation.class)
|
||||
public class TestItemSetup {
|
||||
|
||||
private static SlimefunPlugin plugin;
|
||||
@ -28,6 +33,7 @@ public class TestItemSetup {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(value = 1)
|
||||
public void testForExceptions() {
|
||||
// Not really ideal but still important to test.
|
||||
// Item amount is variable, so we can't test for that.
|
||||
@ -37,4 +43,10 @@ public class TestItemSetup {
|
||||
// Running it a second time should NOT be allowed.
|
||||
Assertions.assertThrows(UnsupportedOperationException.class, () -> SlimefunItemSetup.setup(plugin));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(value = 2)
|
||||
public void testWikiSetup() {
|
||||
Assertions.assertDoesNotThrow(() -> PostSetup.setupWiki());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package io.github.thebusybiscuit.slimefun4.testing.tests.listeners;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.inventory.meta.FireworkMetaMock;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.FireworksListener;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
|
||||
public class TestFireworksListener {
|
||||
|
||||
private static ServerMock server;
|
||||
|
||||
@BeforeAll
|
||||
public static void load() {
|
||||
server = MockBukkit.mock();
|
||||
SlimefunPlugin plugin = MockBukkit.load(SlimefunPlugin.class);
|
||||
new FireworksListener(plugin);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void unload() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFireworkDamage() {
|
||||
Player player = server.addPlayer();
|
||||
Firework firework = Mockito.mock(Firework.class);
|
||||
FireworkMeta meta = new FireworkMetaMock();
|
||||
meta.setDisplayName(ChatColor.GREEN + "Slimefun Research");
|
||||
|
||||
Mockito.when(firework.getType()).thenReturn(EntityType.FIREWORK);
|
||||
Mockito.when(firework.getFireworkMeta()).thenReturn(meta);
|
||||
|
||||
EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(firework, player, DamageCause.ENTITY_EXPLOSION, 6.0);
|
||||
server.getPluginManager().callEvent(event);
|
||||
Assertions.assertTrue(event.isCancelled());
|
||||
}
|
||||
|
||||
}
|
@ -85,6 +85,19 @@ public class TestMultiBlocks {
|
||||
Assertions.assertTrue(multiblock.equals(multiblock2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualWithMovingPistons() {
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PISTON_MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));
|
||||
|
||||
// Some Pistons are moving but that should not interefere with the Multiblock
|
||||
MultiBlock multiblock = new MultiBlock(item, new Material[] { Material.PISTON, Material.MOVING_PISTON, Material.PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);
|
||||
MultiBlock multiblock2 = new MultiBlock(item, new Material[] { Material.MOVING_PISTON, Material.PISTON, Material.MOVING_PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);
|
||||
MultiBlock multiblock3 = new MultiBlock(item, new Material[] { Material.PISTON, Material.PISTON, Material.STICKY_PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);
|
||||
|
||||
Assertions.assertTrue(multiblock.equals(multiblock2));
|
||||
Assertions.assertFalse(multiblock.equals(multiblock3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEqual() {
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.thebusybiscuit.slimefun4.testing.tests.services;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@ -18,6 +19,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import io.github.thebusybiscuit.cscorelib2.recipes.RecipeSnapshot;
|
||||
import io.github.thebusybiscuit.slimefun4.core.services.MinecraftRecipeService;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
|
||||
@ -46,6 +48,9 @@ public class TestRecipeService {
|
||||
FurnaceRecipe recipe = new FurnaceRecipe(key, result, new MaterialChoice(Material.DIAMOND), 1, 2);
|
||||
server.addRecipe(recipe);
|
||||
|
||||
// The Snapshot has not been taken, so it should fallback to an empty array
|
||||
Assertions.assertEquals(0, service.getRecipesFor(result).length);
|
||||
|
||||
service.refresh();
|
||||
|
||||
Recipe[] recipes = service.getRecipesFor(result);
|
||||
@ -72,6 +77,9 @@ public class TestRecipeService {
|
||||
FurnaceRecipe recipe = new FurnaceRecipe(key, result, materials, 1, 2);
|
||||
server.addRecipe(recipe);
|
||||
|
||||
// The Snapshot has not been taken, so it should fallback to an empty Optional
|
||||
Assertions.assertFalse(service.getFurnaceOutput(new ItemStack(Material.DIRT)).isPresent());
|
||||
|
||||
service.refresh();
|
||||
|
||||
Assertions.assertFalse(service.getFurnaceOutput(null).isPresent());
|
||||
@ -136,4 +144,18 @@ public class TestRecipeService {
|
||||
|
||||
Assertions.assertArrayEquals(new RecipeChoice[] { choice }, service.getRecipeShape(recipe));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubscriptions() {
|
||||
MinecraftRecipeService service = new MinecraftRecipeService(plugin);
|
||||
AtomicReference<RecipeSnapshot> reference = new AtomicReference<>();
|
||||
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> service.subscribe(null));
|
||||
|
||||
service.subscribe(reference::set);
|
||||
service.refresh();
|
||||
|
||||
// The callback was executed
|
||||
Assertions.assertNotNull(reference.get());
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.utils;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -20,7 +21,7 @@ public class TestWikiResource {
|
||||
Pattern pattern = Pattern.compile("[A-Z_0-9]+");
|
||||
|
||||
// Here we test for any Syntax errors in our wiki.json file
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("wiki.json")))) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/wiki.json"), StandardCharsets.UTF_8))) {
|
||||
JsonElement json = parser.parse(reader);
|
||||
Assertions.assertTrue(json.isJsonObject());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user