1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

[CI skip] Added an extremely simple ResearchSetup test

This commit is contained in:
TheBusyBiscuit 2020-05-25 12:58:01 +02:00
parent a34abcb1e7
commit 1b951f77ea
2 changed files with 44 additions and 0 deletions

View File

@ -20,9 +20,17 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
*/
public final class ResearchSetup {
private static boolean alreadyRan = false;
private ResearchSetup() {}
public static void setupResearches() {
if (alreadyRan) {
throw new UnsupportedOperationException("Researches can only be registered once!");
}
alreadyRan = true;
register("walking_sticks", 0, "Walking Sticks", 1, SlimefunItems.GRANDMAS_WALKING_STICK, SlimefunItems.GRANDPAS_WALKING_STICK);
register("portable_crafter", 1, "Portable Crafter", 1, SlimefunItems.PORTABLE_CRAFTER);
register("fortune_cookie", 2, "Fortune Cookie", 1, SlimefunItems.FORTUNE_COOKIE);

View File

@ -0,0 +1,36 @@
package io.github.thebusybiscuit.slimefun4.tests.researches;
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 be.seeseemelk.mockbukkit.MockBukkit;
import io.github.thebusybiscuit.slimefun4.implementation.setup.ResearchSetup;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
public class TestResearchSetup {
@BeforeAll
public static void load() {
MockBukkit.mock();
MockBukkit.load(SlimefunPlugin.class);
}
@AfterAll
public static void unload() {
MockBukkit.unmock();
}
@Test
public void testForExceptions() {
// Not really ideal but still important to test.
// Research amount is variable, so we can't test for that.
// We are really only concerned about any runtime exceptions here.
Assertions.assertDoesNotThrow(() -> ResearchSetup.setupResearches());
// Running it a second time should NOT be allowed.
Assertions.assertThrows(UnsupportedOperationException.class, () -> ResearchSetup.setupResearches());
}
}