Skip to content

Commit

Permalink
Add test for when a linked file points to a PDF url (JabRef#7452)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniyi authored and grundb committed Mar 4, 2021
1 parent 0f5a819 commit e2f4c6f
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Optional;
import java.util.TreeSet;
import java.util.*;
import java.util.regex.Pattern;
import java.util.List;

import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
Expand Down Expand Up @@ -280,4 +277,32 @@ void mimeTypeStringWithParameterIsReturnedAsWithoutParameter() {
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]");
when(filePreferences.getFileDirectoryPattern()).thenReturn("[entrytype]");

databaseContext.setDatabasePath(tempFile);

LinkedFileViewModel viewModel = new LinkedFileViewModel(linkedFile, entry, databaseContext, new CurrentThreadTaskExecutor(), dialogService, xmpPreferences, filePreferences, externalFileType);
viewModel.download();

//Loop through downloaded files to check for filetype='pdf'
List<LinkedFile> linkedFiles = entry.getFiles();
for(LinkedFile files : linkedFiles){
if(files.getLink().equalsIgnoreCase("Misc/asdf.pdf")){
assertEquals("pdf" , files.getFileType().toLowerCase());
return;
}
}
//Assert fail if no PDF type was found
fail();
}

}

0 comments on commit e2f4c6f

Please sign in to comment.