use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class MoveFilesCleanupTest method movesFileFromSubfolder.
@Test
public void movesFileFromSubfolder() throws IOException {
File subfolder = bibFolder.newFolder();
File fileBefore = new File(subfolder, "test.pdf");
assertTrue(fileBefore.createNewFile());
assertTrue(new File(subfolder, "test.pdf").exists());
LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs, mock(LayoutFormatterPreferences.class));
cleanup.cleanup(entry);
assertFalse(fileBefore.exists());
File fileAfter = new File(pdfFolder, "test.pdf");
assertTrue(fileAfter.exists());
assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(new LinkedFile("", fileAfter.getName(), ""))), entry.getField("file"));
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class RenamePdfCleanupTest method cleanupSingleField.
@Test
public void cleanupSingleField() throws IOException {
String fileNamePattern = "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}";
testFolder.newFile("Toot.pdf");
LinkedFile fileField = new LinkedFile("", "Toot.pdf", "PDF");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
entry.setField("title", "test title");
RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, layoutFormatterPreferences, fileDirPrefs, fileField);
cleanup.cleanup(entry);
LinkedFile newFileField = new LinkedFile("", "Toot - test title.pdf", "PDF");
assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class RenamePdfCleanupTest method cleanupGetTargetFilename.
@Test
public void cleanupGetTargetFilename() throws IOException {
String fileNamePattern = "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}";
testFolder.newFile("Toot.pdf");
LinkedFile fileField = new LinkedFile("", "Toot.pdf", "PDF");
RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, layoutFormatterPreferences, fileDirPrefs);
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
entry.setField("title", "test title");
assertEquals("Toot - test title.pdf", cleanup.getTargetFileName(fileField, entry));
}
Aggregations