diff --git a/patches/0007-test-cover-the-hotkey-s-null-recipe-GUI-guard-5.patch b/patches/0007-test-cover-the-hotkey-s-null-recipe-GUI-guard-5.patch new file mode 100644 index 0000000..4e2690c --- /dev/null +++ b/patches/0007-test-cover-the-hotkey-s-null-recipe-GUI-guard-5.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Stratum +Date: Wed, 18 Nov 2026 17:27:13 +0800 +Subject: [PATCH] test: cover the hotkey's null recipe GUI guard (#5) + +--- + .../kuba6000/mobsinfo/KeyBindingHandler.java | 2 +- + .../com/kuba6000/mobsinfo/RecipeGuiGuard.java | 11 +++++++++++ + .../kuba6000/mobsinfo/RecipeGuiGuardTest.java | 19 +++++++++++++++++++ + 3 files changed, 31 insertions(+), 1 deletion(-) + create mode 100644 src/main/java/com/kuba6000/mobsinfo/RecipeGuiGuard.java + create mode 100644 src/test/java/com/kuba6000/mobsinfo/RecipeGuiGuardTest.java + +diff --git a/src/main/java/com/kuba6000/mobsinfo/KeyBindingHandler.java b/src/main/java/com/kuba6000/mobsinfo/KeyBindingHandler.java +index 4725637..6a74690 100644 +--- a/src/main/java/com/kuba6000/mobsinfo/KeyBindingHandler.java ++++ b/src/main/java/com/kuba6000/mobsinfo/KeyBindingHandler.java +@@ -36,7 +36,7 @@ public class KeyBindingHandler { + .getOverlayIdentifier(), + false); + // NEI returns null when no handler has any recipe (config not received yet, or Mob Handler disabled). +- if (!(created instanceof GuiCraftingRecipe)) return; ++ if (!RecipeGuiGuard.isOpenable(created)) return; + GuiCraftingRecipe gui = (GuiCraftingRecipe) created; + if (LoaderReference.InfernalMobs.isLoaded) + gui.currenthandlers.add(new MobHandlerInfernal().addAllRecipes()); +diff --git a/src/main/java/com/kuba6000/mobsinfo/RecipeGuiGuard.java b/src/main/java/com/kuba6000/mobsinfo/RecipeGuiGuard.java +new file mode 100644 +index 0000000..1d088f3 +--- /dev/null ++++ b/src/main/java/com/kuba6000/mobsinfo/RecipeGuiGuard.java +@@ -0,0 +1,11 @@ ++package com.kuba6000.mobsinfo; ++ ++final class RecipeGuiGuard { ++ ++ private RecipeGuiGuard() {} ++ ++ /** NEI's createRecipeGui returns null when no handler has a recipe; there is then nothing to open or extend. */ ++ static boolean isOpenable(Object createdGui) { ++ return createdGui != null; ++ } ++} +diff --git a/src/test/java/com/kuba6000/mobsinfo/RecipeGuiGuardTest.java b/src/test/java/com/kuba6000/mobsinfo/RecipeGuiGuardTest.java +new file mode 100644 +index 0000000..2415770 +--- /dev/null ++++ b/src/test/java/com/kuba6000/mobsinfo/RecipeGuiGuardTest.java +@@ -0,0 +1,19 @@ ++package com.kuba6000.mobsinfo; ++ ++import static org.junit.Assert.assertFalse; ++import static org.junit.Assert.assertTrue; ++ ++import org.junit.Test; ++ ++public class RecipeGuiGuardTest { ++ ++ @Test ++ public void nullGuiFromNeiIsNotOpenable() { ++ assertFalse(RecipeGuiGuard.isOpenable(null)); ++ } ++ ++ @Test ++ public void createdGuiIsOpenable() { ++ assertTrue(RecipeGuiGuard.isOpenable(new Object())); ++ } ++}