Skip to content

Commit

Permalink
Refactor LinkedFileViewModelTest removing redundant code (JabRef#7452)
Browse files Browse the repository at this point in the history
  • Loading branch information
binsu-kth committed Mar 6, 2021
1 parent 32b9433 commit 263178a
Showing 1 changed file with 1 addition and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import javafx.scene.control.ButtonType;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.externalfiletype.StandardExternalFileType;
Expand Down Expand Up @@ -65,7 +64,6 @@ class LinkedFileViewModelTest {
private final ExternalFileTypes externalFileType = mock(ExternalFileTypes.class);
private final FilePreferences filePreferences = mock(FilePreferences.class);
private final XmpPreferences xmpPreferences = mock(XmpPreferences.class);
private final JabRefPreferences jabRefPreferences = mock(JabRefPreferences.class);
private CookieManager cookieManager;

@BeforeEach
Expand Down Expand Up @@ -186,11 +184,8 @@ void deleteWhenDialogCancelledReturnsFalseAndDoesNotRemoveFile() {
// Structure taken from deleteWhenDialogCancelledReturnsFalseAndDoesNotRemoveFile method
@Test
void downloadHtmlFileCausesWarningDisplay() throws MalformedURLException {
Globals.prefs = jabRefPreferences.getInstance(); // required for task execution

// From BibDatabaseContextTest::setUp
when(filePreferences.shouldStoreFilesRelativeToBib()).thenReturn(true);

when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]"); // used in other tests in this class
when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]"); // used in movesFileWithFileDirPattern at MoveFilesCleanupTest.java

Expand Down Expand Up @@ -233,10 +228,7 @@ void downloadHtmlWhenLinkedFilePointsToHtml() throws MalformedURLException {
String fileType = StandardExternalFileType.URL.getName();
linkedFile = new LinkedFile(new URL(url), fileType);

Globals.prefs = jabRefPreferences.getInstance();

when(filePreferences.shouldStoreFilesRelativeToBib()).thenReturn(true);

when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]");
when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]");

Expand Down Expand Up @@ -284,18 +276,14 @@ void isSamePath() {
// Tests if added parameters to mimeType gets parsed to correct format.
@Test
void mimeTypeStringWithParameterIsReturnedAsWithoutParameter() {
Globals.prefs = jabRefPreferences.getInstance(); // required for task execution
ExternalFileTypes externalFileTypesInstance = externalFileType.getInstance();
Optional<ExternalFileType> test = externalFileTypesInstance.getExternalFileTypeByMimeType("text/html; charset=UTF-8");
Optional<ExternalFileType> test = externalFileType.getExternalFileTypeByMimeType("text/html; charset=UTF-8");
String actual = test.get().toString();
assertEquals("URL", actual);
}

@Test
void downloadPdfFileWhenLinkedFilePointsToPdfUrl() throws MalformedURLException {
Globals.prefs = jabRefPreferences.getInstance();
linkedFile = new LinkedFile(new URL("http://arxiv.org/pdf/1207.0408v1"), "pdf");

// Needed Mockito stubbing methods to run test
when(filePreferences.shouldStoreFilesRelativeToBib()).thenReturn(true);
when(filePreferences.getFileNamePattern()).thenReturn("[citationkey]");
Expand Down

0 comments on commit 263178a

Please sign in to comment.