Skip to content

Commit

Permalink
Exclude clientsettings.xml from "last save" search in MekHQ
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleet01 committed Mar 7, 2024
1 parent 9ca6efe commit fbd958a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/panels/StartupScreenPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions MekHQ/unittests/mekhq/gui/panels/StartupScreenPanelTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit fbd958a

Please sign in to comment.