generated from neoforged/MDK
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62b7302
commit 69365ba
Showing
13 changed files
with
202 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/github/minecraftschurlimods/bibliocraft/test/BibliocraftApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.minecraftschurlimods.bibliocraft.test; | ||
|
||
|
||
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi; | ||
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftDatagenHelper; | ||
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftWoodTypeRegistry; | ||
import com.github.minecraftschurlimods.bibliocraft.apiimpl.BibliocraftDatagenHelperImpl; | ||
import com.github.minecraftschurlimods.bibliocraft.apiimpl.BibliocraftWoodTypeRegistryImpl; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.world.level.block.state.properties.WoodType; | ||
import net.neoforged.testframework.annotation.ForEachTest; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import net.neoforged.testframework.gametest.EmptyTemplate; | ||
import net.neoforged.testframework.gametest.ExtendedGameTestHelper; | ||
|
||
import static com.github.minecraftschurlimods.bibliocraft.test.GametestAssertions.*; | ||
|
||
@ForEachTest(groups = BibliocraftApi.MOD_ID + ".api") | ||
public class BibliocraftApiTest { | ||
@GameTest | ||
@EmptyTemplate | ||
@TestHolder(description = "Test that the BibliocraftDatagenHelper is available via the BibliocraftApi") | ||
public static void testDatagenHelperAvailable(ExtendedGameTestHelper helper) { | ||
BibliocraftDatagenHelper datagenHelper = BibliocraftApi.getDatagenHelper(); | ||
assertNotNull(datagenHelper, "BibliocraftDatagenHelper is not available"); | ||
assertInstance(datagenHelper, BibliocraftDatagenHelperImpl.class, "BibliocraftDatagenHelper implementation is replaced"); | ||
helper.succeed(); | ||
} | ||
|
||
@GameTest | ||
@EmptyTemplate | ||
@TestHolder(description = "Test that the BibliocraftWoodTypeRegistry is available via the BibliocraftApi") | ||
public static void testWoodTypeRegistryAvailable(ExtendedGameTestHelper helper) { | ||
BibliocraftWoodTypeRegistry woodTypeRegistry = BibliocraftApi.getWoodTypeRegistry(); | ||
assertNotNull(woodTypeRegistry, "BibliocraftWoodTypeRegistry is not available"); | ||
assertInstance(woodTypeRegistry, BibliocraftWoodTypeRegistryImpl.class, "BibliocraftWoodTypeRegistry implementation is replaced"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.OAK), "Oak WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.SPRUCE), "Spruce WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.BIRCH), "Birch WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.JUNGLE), "Jungle WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.ACACIA), "Acacia WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.DARK_OAK), "Dark Oak WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.CRIMSON), "Crimson WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.WARPED), "Warped WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.MANGROVE), "Mangrove WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.BAMBOO), "Bamboo WoodType is not registered"); | ||
assertNotNull(woodTypeRegistry.get(WoodType.CHERRY), "Cherry WoodType is not registered"); | ||
helper.succeed(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/test/java/com/github/minecraftschurlimods/bibliocraft/test/GametestAssertions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.github.minecraftschurlimods.bibliocraft.test; | ||
|
||
import net.minecraft.gametest.framework.GameTestAssertException; | ||
import org.jetbrains.annotations.ApiStatus.NonExtendable; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Objects; | ||
|
||
@NonExtendable | ||
public interface GametestAssertions { | ||
@Contract("false, _ -> fail") | ||
static void assertTrue(boolean condition, String message) { | ||
if (!condition) { | ||
fail(message); | ||
} | ||
} | ||
|
||
@Contract("true, _ -> fail") | ||
static void assertFalse(boolean condition, String message) { | ||
if (condition) { | ||
fail(message); | ||
} | ||
} | ||
|
||
@SuppressWarnings("UnusedReturnValue") | ||
static <T> T assertInstance(@Nullable Object instance, Class<T> clazz, String message) { | ||
if (!clazz.isInstance(instance)) { | ||
fail(message); | ||
return null; // never reached | ||
} else { | ||
return clazz.cast(instance); | ||
} | ||
} | ||
|
||
@Contract("!null, _ -> fail") | ||
static void assertNull(@Nullable Object o, String message) { | ||
if (o != null) { | ||
fail(message); | ||
} | ||
} | ||
|
||
@Contract("null, _ -> fail") | ||
static void assertNotNull(@Nullable Object o, String message) { | ||
if (o == null) { | ||
fail(message); | ||
} | ||
} | ||
|
||
static void assertEquals(@Nullable Object expected, @Nullable Object actual, String message) { | ||
if (expected == null) { | ||
assertNull(actual, message); | ||
} | ||
if (expected instanceof BigDecimal bd1 && actual instanceof BigDecimal bd2) { | ||
assertEquals(bd1, bd2, message); | ||
} | ||
if (!Objects.equals(expected, actual)) { | ||
fail(message); | ||
} | ||
} | ||
|
||
static void assertEquals(@Nullable BigDecimal expected, @Nullable BigDecimal actual, String message) { | ||
if (expected == null) { | ||
assertNull(actual, message); | ||
} | ||
if (Objects.compare(expected, actual, Comparable::compareTo) != 0) { | ||
fail(message); | ||
} | ||
} | ||
|
||
@Contract("_ -> fail") | ||
static void fail(String message) throws GameTestAssertException { | ||
throw new GameTestAssertException(message); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/com/github/minecraftschurlimods/bibliocraft/test/Tests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.github.minecraftschurlimods.bibliocraft.test; | ||
|
||
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.commands.Commands; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.neoforged.bus.api.EventPriority; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.ModContainer; | ||
import net.neoforged.fml.ModList; | ||
import net.neoforged.fml.common.Mod; | ||
import net.neoforged.fml.event.lifecycle.FMLConstructModEvent; | ||
import net.neoforged.neoforge.common.NeoForge; | ||
import net.neoforged.neoforge.event.RegisterCommandsEvent; | ||
import net.neoforged.testframework.conf.ClientConfiguration; | ||
import net.neoforged.testframework.conf.Feature; | ||
import net.neoforged.testframework.conf.FrameworkConfiguration; | ||
import net.neoforged.testframework.impl.MutableTestFramework; | ||
import net.neoforged.testframework.summary.GitHubActionsStepSummaryFormatter; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = BibliocraftApi.MOD_ID) | ||
public final class Tests { | ||
@SubscribeEvent(priority = EventPriority.HIGHEST) | ||
static void init(FMLConstructModEvent event) { | ||
ModList.get().getModContainerById(BibliocraftApi.MOD_ID).ifPresent(Tests::init); | ||
} | ||
|
||
private static void init(ModContainer container) { | ||
final MutableTestFramework framework = FrameworkConfiguration.builder(new ResourceLocation(container.getModId(), "tests")) | ||
.clientConfiguration(() -> ClientConfiguration.builder() | ||
.toggleOverlayKey(GLFW.GLFW_KEY_J) | ||
.openManagerKey(GLFW.GLFW_KEY_N) | ||
.build()) | ||
.enable(Feature.CLIENT_SYNC, Feature.CLIENT_MODIFICATIONS, Feature.TEST_STORE) | ||
.formatters(new GitHubActionsStepSummaryFormatter("Bibliocraft Gametest Summary")) | ||
.build().create(); | ||
|
||
framework.init(container.getEventBus(), container); | ||
|
||
NeoForge.EVENT_BUS.addListener((final RegisterCommandsEvent event) -> { | ||
final LiteralArgumentBuilder<CommandSourceStack> node = Commands.literal("tests"); | ||
framework.registerCommands(node); | ||
event.getDispatcher().register(node); | ||
}); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/test/java/com/github/minecraftschurlimods/bibliocraft/test/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@MethodsReturnNonnullByDefault | ||
@ParametersAreNonnullByDefault | ||
package com.github.minecraftschurlimods.bibliocraft.test; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
12 changes: 12 additions & 0 deletions
12
src/test/java/com/github/minecraftschurlimods/bibliocraft/test/readme.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
todo: | ||
- add tests for interactions | ||
- bookcase | ||
- display case | ||
- fancy armor stand | ||
- potion shelf | ||
- seat | ||
- shelf | ||
- sword pedestal | ||
- table | ||
- toolrack | ||
- add tests for automation (hoppers etc.) |