From 75acd68ce19fd15ea88da55e635afb6e1d3aba9d Mon Sep 17 00:00:00 2001 From: Dario Date: Fri, 7 Jun 2024 22:23:25 +0200 Subject: [PATCH] change --- build.gradle.kts | 2 +- paper/build.gradle.kts | 6 +-- .../javautils/paper/test/ItemStackTest.java | 20 --------- .../de/derioo/javautils/paper/test/Main.java | 24 ---------- .../javautils/paper/ItemStackUtilityTest.java | 44 +++++++++++++++++++ .../javautils/paper/MaterialUtilityTest.java | 20 +++++++++ 6 files changed, 68 insertions(+), 48 deletions(-) delete mode 100644 paper/src/main/java/de/derioo/javautils/paper/test/ItemStackTest.java delete mode 100644 paper/src/main/java/de/derioo/javautils/paper/test/Main.java create mode 100644 paper/src/test/java/de/derioo/javautils/paper/ItemStackUtilityTest.java diff --git a/build.gradle.kts b/build.gradle.kts index 8f1afda..449cd4d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ subprojects { apply(plugin = "maven-publish") group = "de.derioo.javautils" - version = "2.2.3" + version = "2.2.4" repositories { mavenCentral() diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts index 13eba72..8eb0f2d 100644 --- a/paper/build.gradle.kts +++ b/paper/build.gradle.kts @@ -12,8 +12,9 @@ dependencies { implementation(platform("org.junit:junit-bom:5.10.2")) implementation("org.junit.jupiter:junit-jupiter") implementation("org.assertj:assertj-core:3.26.0") - compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT") - testImplementation("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT") + implementation("com.github.seeseemelk:MockBukkit-v1.20:3.9.0") + + testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.9.0") } tasks { @@ -21,7 +22,6 @@ tasks { minecraftVersion("1.20.6") } test { - dependsOn(runServer) useJUnitPlatform() } named("compileJava") { diff --git a/paper/src/main/java/de/derioo/javautils/paper/test/ItemStackTest.java b/paper/src/main/java/de/derioo/javautils/paper/test/ItemStackTest.java deleted file mode 100644 index d465647..0000000 --- a/paper/src/main/java/de/derioo/javautils/paper/test/ItemStackTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.derioo.javautils.paper.test; - -import org.bukkit.*; -import org.bukkit.inventory.ItemStack; - -import java.io.IOException; - -import static de.derioo.javautils.paper.ItemStackUtility.*; -import static org.assertj.core.api.Assertions.*; - -public class ItemStackTest { - - public ItemStackTest() throws IOException { - ItemStack[] itemStacks = new ItemStack[]{new ItemStack(Material.DIAMOND), new ItemStack(Material.DIRT)}; - byte[] bytes = decodeItemStacksToBytes(itemStacks); - assertThat(bytes).isNotNull(); - assertThat(encodeItemStacksFromBytes(bytes)).isEqualTo(itemStacks); - assertThat(encodeItemStacksFromBytes(decodeItemStacksToBytes(new ItemStack[]{itemStacks[0]}))).isEqualTo(new ItemStack[]{itemStacks[0]}); - } -} diff --git a/paper/src/main/java/de/derioo/javautils/paper/test/Main.java b/paper/src/main/java/de/derioo/javautils/paper/test/Main.java deleted file mode 100644 index 1e635ba..0000000 --- a/paper/src/main/java/de/derioo/javautils/paper/test/Main.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.derioo.javautils.paper.test; - -import de.derioo.javautils.common.MathUtility; -import lombok.extern.java.Log; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.logging.Level; - -public class Main extends JavaPlugin { - - @Override - public void onEnable() { - try { - getLogger().log(Level.INFO, "ItemstackTest passed in (" + (MathUtility.computeTimeTaking(ItemStackTest::new).toMillis()) + " ms)"); - getLogger().log(Level.INFO, "------------"); - getLogger().log(Level.INFO, "All tests passed"); - } catch (Throwable e) { - getLogger().log(Level.SEVERE, "Doesnt work :(", e); - System.exit(1); - } - Bukkit.shutdown(); - } -} diff --git a/paper/src/test/java/de/derioo/javautils/paper/ItemStackUtilityTest.java b/paper/src/test/java/de/derioo/javautils/paper/ItemStackUtilityTest.java new file mode 100644 index 0000000..24c5f1f --- /dev/null +++ b/paper/src/test/java/de/derioo/javautils/paper/ItemStackUtilityTest.java @@ -0,0 +1,44 @@ +package de.derioo.javautils.paper; + +import be.seeseemelk.mockbukkit.MockBukkit; +import be.seeseemelk.mockbukkit.ServerMock; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static de.derioo.javautils.paper.ItemStackUtility.*; +import static org.assertj.core.api.Assertions.*; + +public class ItemStackUtilityTest { + + private ServerMock server; + @BeforeEach + public void setUp() + { + server = MockBukkit.mock(); + } + + @AfterEach + public void tearDown() + { + MockBukkit.unmock(); + } + + @Test + public void testItemStackDecodingAndEncoding() { + ItemStack[] itemStacks = new ItemStack[]{new ItemStack(Material.DIAMOND), new ItemStack(Material.DIRT)}; + try { + byte[] bytes = decodeItemStacksToBytes(itemStacks); + assertThat(bytes).isNotNull(); + assertThat(encodeItemStacksFromBytes(bytes)).isEqualTo(itemStacks); + assertThat(encodeItemStacksFromBytes(decodeItemStacksToBytes(new ItemStack[]{itemStacks[0]}))).isEqualTo(new ItemStack[]{itemStacks[0]}); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/paper/src/test/java/de/derioo/javautils/paper/MaterialUtilityTest.java b/paper/src/test/java/de/derioo/javautils/paper/MaterialUtilityTest.java index 095b623..8f36a80 100644 --- a/paper/src/test/java/de/derioo/javautils/paper/MaterialUtilityTest.java +++ b/paper/src/test/java/de/derioo/javautils/paper/MaterialUtilityTest.java @@ -1,16 +1,36 @@ package de.derioo.javautils.paper; +import be.seeseemelk.mockbukkit.MockBukkit; +import be.seeseemelk.mockbukkit.ServerMock; import org.bukkit.*; import org.bukkit.inventory.ItemStack; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.util.*; +import static de.derioo.javautils.paper.ItemStackUtility.decodeItemStacksToBytes; +import static de.derioo.javautils.paper.ItemStackUtility.encodeItemStacksFromBytes; import static de.derioo.javautils.paper.MaterialUtility.*; import static org.assertj.core.api.Assertions.assertThat; public class MaterialUtilityTest { + private ServerMock server; + @BeforeEach + public void setUp() + { + server = MockBukkit.mock(); + } + + @AfterEach + public void tearDown() + { + MockBukkit.unmock(); + } + static Random random = new Random(); @Test