-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move check for invalid characters to linked files editor (#12219)
* move check for invalid characters to linked files editor Fixes #12212 some cleanup * fix checkstyle * restore switch * set working dir path * checkstyle * add test * fix import
- Loading branch information
1 parent
38b70e2
commit 4f8ece3
Showing
5 changed files
with
95 additions
and
72 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
55 changes: 55 additions & 0 deletions
55
src/test/java/org/jabref/gui/linkedfile/LinkedFileEditDialogViewModelTest.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,55 @@ | ||
package org.jabref.gui.linkedfile; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.TreeSet; | ||
|
||
import javafx.collections.FXCollections; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.externalfiletype.ExternalFileTypes; | ||
import org.jabref.gui.frame.ExternalApplicationsPreferences; | ||
import org.jabref.gui.preferences.GuiPreferences; | ||
import org.jabref.logic.FilePreferences; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.LinkedFile; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.mockito.Answers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class LinkedFileEditDialogViewModelTest { | ||
private final GuiPreferences preferences = mock(GuiPreferences.class, Answers.RETURNS_DEEP_STUBS); | ||
private final FilePreferences filePreferences = mock(FilePreferences.class, Answers.RETURNS_DEEP_STUBS); | ||
private final BibDatabaseContext bibDatabaseContext = mock(BibDatabaseContext.class); | ||
private final DialogService dialogService = mock(DialogService.class); | ||
private final ExternalApplicationsPreferences externalApplicationsPreferences = mock(ExternalApplicationsPreferences.class); | ||
|
||
@BeforeEach | ||
void setup() { | ||
when(externalApplicationsPreferences.getExternalFileTypes()).thenReturn(FXCollections.observableSet(new TreeSet<>(ExternalFileTypes.getDefaultExternalFileTypes()))); | ||
when(preferences.getExternalApplicationsPreferences()).thenReturn(externalApplicationsPreferences); | ||
when(preferences.getFilePreferences()).thenReturn(filePreferences); | ||
} | ||
|
||
@Test | ||
void badFilenameCharWillBeReplacedByUnderscore(@TempDir Path tempDir) throws Exception { | ||
|
||
Path invalidFile = tempDir.resolve("?invalid.pdf"); | ||
Files.createFile(invalidFile); | ||
when(dialogService.showConfirmationDialogAndWait(any(), any(), any())).thenReturn(true); | ||
|
||
LinkedFileEditDialogViewModel viewModel = new LinkedFileEditDialogViewModel(new LinkedFile("", "", ""), bibDatabaseContext, dialogService, externalApplicationsPreferences, filePreferences); | ||
|
||
viewModel.checkForBadFileNameAndAdd(invalidFile); | ||
|
||
LinkedFile expectedFile = new LinkedFile("", tempDir.resolve("_invalid.pdf").toString(), "PDF"); | ||
assertEquals(expectedFile, viewModel.getNewLinkedFile()); | ||
} | ||
} |