From fbd958a49166b7f1a5b9606345a16dde12fc528c Mon Sep 17 00:00:00 2001 From: sleet01 Date: Wed, 6 Mar 2024 23:47:27 -0800 Subject: [PATCH] Exclude clientsettings.xml from "last save" search in MekHQ --- .../mekhq/gui/panels/StartupScreenPanel.java | 2 +- .../gui/panels/StartupScreenPanelTest.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 MekHQ/unittests/mekhq/gui/panels/StartupScreenPanelTest.java diff --git a/MekHQ/src/mekhq/gui/panels/StartupScreenPanel.java b/MekHQ/src/mekhq/gui/panels/StartupScreenPanel.java index 0fe7eb0fbd7..695b3d9afc0 100644 --- a/MekHQ/src/mekhq/gui/panels/StartupScreenPanel.java +++ b/MekHQ/src/mekhq/gui/panels/StartupScreenPanel.java @@ -53,7 +53,7 @@ public class StartupScreenPanel extends AbstractMHQPanel { private BufferedImage backgroundIcon; // Save file filtering needs to avoid loading some special files - public FilenameFilter saveFilter = new FilenameFilter() { + static public FilenameFilter saveFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { // Allow any .xml, .cpnx, and .cpnx.gz file that is not in the list of excluded files diff --git a/MekHQ/unittests/mekhq/gui/panels/StartupScreenPanelTest.java b/MekHQ/unittests/mekhq/gui/panels/StartupScreenPanelTest.java new file mode 100644 index 00000000000..c56688e0555 --- /dev/null +++ b/MekHQ/unittests/mekhq/gui/panels/StartupScreenPanelTest.java @@ -0,0 +1,37 @@ +package mekhq.gui.panels; + +import megamek.common.preference.PreferenceManager; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.mockito.Mockito.*; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.*; + +class StartupScreenPanelTest { + File dir; + + @BeforeEach + void setUp() { + dir = mock(File.class); + } + + @Test + void testSaveFilterAllowsValidCampaignSaves(){ + String fileName = "MySave.xml"; + assertTrue(StartupScreenPanel.saveFilter.accept(dir, fileName)); + fileName = "MySave.CPNX"; + assertTrue(StartupScreenPanel.saveFilter.accept(dir, fileName)); + fileName = "20240306T2344 Save Campaign No 666.cpnx.gz"; + assertTrue(StartupScreenPanel.saveFilter.accept(dir, fileName)); + } + + @Test + void testSaveFilterNotAllowClientSettingsXML(){ + String fileName = PreferenceManager.DEFAULT_CFG_FILE_NAME.toLowerCase(); + boolean allowed = StartupScreenPanel.saveFilter.accept(dir, fileName); + assertFalse(allowed); + } +} \ No newline at end of file