diff --git a/src/jmh/java/org/jabref/benchmarks/Benchmarks.java b/src/jmh/java/org/jabref/benchmarks/Benchmarks.java index 6b5589ed18e..8eae854642c 100644 --- a/src/jmh/java/org/jabref/benchmarks/Benchmarks.java +++ b/src/jmh/java/org/jabref/benchmarks/Benchmarks.java @@ -13,7 +13,7 @@ import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; import org.jabref.logic.exporter.BibWriter; import org.jabref.logic.exporter.BibtexDatabaseWriter; -import org.jabref.logic.exporter.SaveConfiguration; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.BibtexParser; @@ -82,7 +82,7 @@ private StringWriter getOutputWriter() throws IOException { BibWriter bibWriter = new BibWriter(outputWriter, OS.NEWLINE); BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter( bibWriter, - mock(SaveConfiguration.class), + mock(SelfContainedSaveConfiguration.class), mock(FieldPreferences.class), mock(CitationKeyPatternPreferences.class), new BibEntryTypesManager()); diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 9b0d2c1ef59..5d5c2c025d6 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -25,7 +25,7 @@ import org.jabref.logic.exporter.EmbeddedBibFilePdfExporter; import org.jabref.logic.exporter.Exporter; import org.jabref.logic.exporter.ExporterFactory; -import org.jabref.logic.exporter.SaveConfiguration; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.exporter.XmpPdfExporter; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportException; @@ -598,7 +598,7 @@ private void saveDatabase(BibDatabase newBase, String subName) { System.out.println(Localization.lang("Saving") + ": " + subName); try (AtomicFileWriter fileWriter = new AtomicFileWriter(Path.of(subName), StandardCharsets.UTF_8)) { BibWriter bibWriter = new BibWriter(fileWriter, OS.NEWLINE); - SaveConfiguration saveConfiguration = new SaveConfiguration() + SelfContainedSaveConfiguration saveConfiguration = (SelfContainedSaveConfiguration) new SelfContainedSaveConfiguration() .withReformatOnSave(preferencesService.getLibraryPreferences().shouldAlwaysReformatOnSave()); BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter( bibWriter, diff --git a/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java b/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java index 616c806891a..1b9017f192f 100644 --- a/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java +++ b/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java @@ -28,7 +28,7 @@ import org.jabref.logic.exporter.AtomicFileWriter; import org.jabref.logic.exporter.BibWriter; import org.jabref.logic.exporter.BibtexDatabaseWriter; -import org.jabref.logic.exporter.SaveConfiguration; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.util.BackupFileType; import org.jabref.logic.util.CoarseChangeFilter; import org.jabref.logic.util.io.BackupFileUtil; @@ -250,7 +250,7 @@ void performBackup(Path backupPath) { } }) .orElse(SaveOrder.getDefaultSaveOrder()); - SaveConfiguration saveConfiguration = new SaveConfiguration() + SelfContainedSaveConfiguration saveConfiguration = (SelfContainedSaveConfiguration) new SelfContainedSaveConfiguration() .withMakeBackup(false) .withSaveOrder(saveOrder) .withReformatOnSave(preferences.getLibraryPreferences().shouldAlwaysReformatOnSave()); diff --git a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java index 7d279d9a609..78c808dad3c 100644 --- a/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java +++ b/src/main/java/org/jabref/gui/exporter/CreateModifyExporterDialogViewModel.java @@ -67,7 +67,7 @@ public ExporterViewModel saveExporter() { layoutFile.get(), extension.get(), preferences.getLayoutFormatterPreferences(), - preferences.getExportConfiguration().getSaveOrder()); + preferences.getSelfContainedExportConfiguration().getSelfContainedSaveOrder()); format.setCustomExport(true); return new ExporterViewModel(format); } diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 096646fd267..3d451540b2e 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -31,8 +31,8 @@ import org.jabref.logic.exporter.BibDatabaseWriter; import org.jabref.logic.exporter.BibWriter; import org.jabref.logic.exporter.BibtexDatabaseWriter; -import org.jabref.logic.exporter.SaveConfiguration; import org.jabref.logic.exporter.SaveException; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Localization; import org.jabref.logic.shared.DatabaseLocation; @@ -256,11 +256,8 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) { private boolean saveDatabase(Path file, boolean selectedOnly, Charset encoding, BibDatabaseWriter.SaveType saveType, SelfContainedSaveOrder saveOrder) throws SaveException { // if this code is adapted, please also adapt org.jabref.logic.autosaveandbackup.BackupManager.performBackup - - SaveConfiguration saveConfiguration = new SaveConfiguration() - .withSaveType(saveType) - .withSaveOrder(saveOrder) - .withReformatOnSave(preferences.getLibraryPreferences().shouldAlwaysReformatOnSave()); + SelfContainedSaveConfiguration saveConfiguration + = new SelfContainedSaveConfiguration(saveOrder, false, saveType, preferences.getLibraryPreferences().shouldAlwaysReformatOnSave()); BibDatabaseContext bibDatabaseContext = libraryTab.getBibDatabaseContext(); synchronized (bibDatabaseContext) { try (AtomicFileWriter fileWriter = new AtomicFileWriter(file, encoding, saveConfiguration.shouldMakeBackup())) { diff --git a/src/main/java/org/jabref/logic/crawler/StudyRepository.java b/src/main/java/org/jabref/logic/crawler/StudyRepository.java index 9e3abbe0804..dc490090339 100644 --- a/src/main/java/org/jabref/logic/crawler/StudyRepository.java +++ b/src/main/java/org/jabref/logic/crawler/StudyRepository.java @@ -16,8 +16,8 @@ import org.jabref.logic.exporter.AtomicFileWriter; import org.jabref.logic.exporter.BibWriter; import org.jabref.logic.exporter.BibtexDatabaseWriter; -import org.jabref.logic.exporter.SaveConfiguration; import org.jabref.logic.exporter.SaveException; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.git.SlrGitHandler; import org.jabref.logic.importer.OpenDatabase; import org.jabref.logic.importer.SearchBasedFetcher; @@ -427,7 +427,7 @@ private void generateCiteKeys(BibDatabaseContext existingEntries, BibDatabase ta private void writeResultToFile(Path pathToFile, BibDatabaseContext context) throws SaveException { try (AtomicFileWriter fileWriter = new AtomicFileWriter(pathToFile, StandardCharsets.UTF_8)) { - SaveConfiguration saveConfiguration = new SaveConfiguration() + SelfContainedSaveConfiguration saveConfiguration = (SelfContainedSaveConfiguration) new SelfContainedSaveConfiguration() .withSaveOrder(context.getMetaData().getSaveOrder().map(so -> SelfContainedSaveOrder.of(so)).orElse(SaveOrder.getDefaultSaveOrder())) .withReformatOnSave(preferencesService.getLibraryPreferences().shouldAlwaysReformatOnSave()); BibWriter bibWriter = new BibWriter(fileWriter, OS.NEWLINE); diff --git a/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java b/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java index e8c417b157d..68df8656bf1 100644 --- a/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java +++ b/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java @@ -58,13 +58,13 @@ public enum SaveType { WITH_JABREF_META_DATA, PLAIN_BIBTEX } private static final Pattern REFERENCE_PATTERN = Pattern.compile("(#[A-Za-z]+#)"); // Used to detect string references in strings protected final BibWriter bibWriter; - protected final SaveConfiguration saveConfiguration; + protected final SelfContainedSaveConfiguration saveConfiguration; protected final CitationKeyPatternPreferences keyPatternPreferences; protected final List saveActionsFieldChanges = new ArrayList<>(); protected final BibEntryTypesManager entryTypesManager; public BibDatabaseWriter(BibWriter bibWriter, - SaveConfiguration saveConfiguration, + SelfContainedSaveConfiguration saveConfiguration, CitationKeyPatternPreferences keyPatternPreferences, BibEntryTypesManager entryTypesManager) { this.bibWriter = Objects.requireNonNull(bibWriter); @@ -181,7 +181,7 @@ public void savePartOfDatabase(BibDatabaseContext bibDatabaseContext, List sortedEntries = getSortedEntries(entries, saveConfiguration.getSaveOrder()); + List sortedEntries = getSortedEntries(entries, saveConfiguration.getSelfContainedSaveOrder()); List saveActionChanges = applySaveActions(sortedEntries, bibDatabaseContext.getMetaData()); saveActionsFieldChanges.addAll(saveActionChanges); if (keyPatternPreferences.shouldGenerateCiteKeysBeforeSaving()) { diff --git a/src/main/java/org/jabref/logic/exporter/BibtexDatabaseWriter.java b/src/main/java/org/jabref/logic/exporter/BibtexDatabaseWriter.java index 39fa27614bf..558687ca21d 100644 --- a/src/main/java/org/jabref/logic/exporter/BibtexDatabaseWriter.java +++ b/src/main/java/org/jabref/logic/exporter/BibtexDatabaseWriter.java @@ -35,7 +35,7 @@ public class BibtexDatabaseWriter extends BibDatabaseWriter { private final FieldPreferences fieldPreferences; public BibtexDatabaseWriter(BibWriter bibWriter, - SaveConfiguration saveConfiguration, + SelfContainedSaveConfiguration saveConfiguration, FieldPreferences fieldPreferences, CitationKeyPatternPreferences citationKeyPatternPreferences, BibEntryTypesManager entryTypesManager) { @@ -49,7 +49,7 @@ public BibtexDatabaseWriter(BibWriter bibWriter, public BibtexDatabaseWriter(Writer writer, String newline, - SaveConfiguration saveConfiguration, + SelfContainedSaveConfiguration saveConfiguration, FieldPreferences fieldPreferences, CitationKeyPatternPreferences citationKeyPatternPreferences, BibEntryTypesManager entryTypesManager) { diff --git a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index 78373ef98d4..4eaa28e4dea 100644 --- a/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -29,7 +29,7 @@ public static ExporterFactory create(PreferencesService preferencesService, List customFormats = preferencesService.getExportPreferences().getCustomExporters(); LayoutFormatterPreferences layoutPreferences = preferencesService.getLayoutFormatterPreferences(); - SelfContainedSaveOrder saveOrder = SelfContainedSaveOrder.of(preferencesService.getExportConfiguration().getSaveOrder()); + SelfContainedSaveOrder saveOrder = SelfContainedSaveOrder.of(preferencesService.getSelfContainedExportConfiguration().getSaveOrder()); XmpPreferences xmpPreferences = preferencesService.getXmpPreferences(); FieldPreferences fieldPreferences = preferencesService.getFieldPreferences(); BibDatabaseMode bibDatabaseMode = preferencesService.getLibraryPreferences().getDefaultBibDatabaseMode(); diff --git a/src/main/java/org/jabref/logic/exporter/SaveConfiguration.java b/src/main/java/org/jabref/logic/exporter/SaveConfiguration.java index 29742fd4a58..358659113e5 100644 --- a/src/main/java/org/jabref/logic/exporter/SaveConfiguration.java +++ b/src/main/java/org/jabref/logic/exporter/SaveConfiguration.java @@ -2,7 +2,6 @@ import org.jabref.gui.autosaveandbackup.BackupManager; import org.jabref.model.metadata.SaveOrder; -import org.jabref.model.metadata.SelfContainedSaveOrder; public class SaveConfiguration { @@ -10,11 +9,11 @@ public class SaveConfiguration { public static final String ENCODING_PREFIX = "Encoding: "; private boolean reformatFile; - private SelfContainedSaveOrder saveOrder; + private SaveOrder saveOrder; private boolean makeBackup; private BibDatabaseWriter.SaveType saveType; - public SaveConfiguration(SelfContainedSaveOrder saveOrder, + public SaveConfiguration(SaveOrder saveOrder, Boolean makeBackup, BibDatabaseWriter.SaveType saveType, Boolean reformatFile) { @@ -31,11 +30,11 @@ public SaveConfiguration() { false); } - public SelfContainedSaveOrder getSaveOrder() { + public SaveOrder getSaveOrder() { return saveOrder; } - public SaveConfiguration withSaveOrder(SelfContainedSaveOrder newSaveOrder) { + public SaveConfiguration withSaveOrder(SaveOrder newSaveOrder) { this.saveOrder = newSaveOrder; return this; } diff --git a/src/main/java/org/jabref/logic/exporter/SelfContainedSaveConfiguration.java b/src/main/java/org/jabref/logic/exporter/SelfContainedSaveConfiguration.java new file mode 100644 index 00000000000..1e5cb241a1e --- /dev/null +++ b/src/main/java/org/jabref/logic/exporter/SelfContainedSaveConfiguration.java @@ -0,0 +1,25 @@ +package org.jabref.logic.exporter; + +import org.jabref.model.metadata.SaveOrder; +import org.jabref.model.metadata.SelfContainedSaveOrder; + +/** + * This is a {@link SaveOrder} where the contained saveConfiguration is a {@link org.jabref.model.metadata.SelfContainedSaveOrder} + */ +public class SelfContainedSaveConfiguration extends SaveConfiguration { + public SelfContainedSaveConfiguration() { + super(); + } + + public SelfContainedSaveConfiguration( + SelfContainedSaveOrder saveOrder, + Boolean makeBackup, + BibDatabaseWriter.SaveType saveType, + Boolean reformatFile) { + super(saveOrder, makeBackup, saveType, reformatFile); + } + + public SelfContainedSaveOrder getSelfContainedSaveOrder() { + return (SelfContainedSaveOrder) getSaveOrder(); + } +} diff --git a/src/main/java/org/jabref/model/metadata/SelfContainedSaveOrder.java b/src/main/java/org/jabref/model/metadata/SelfContainedSaveOrder.java index 1c40945e9ed..4b5cafc6b9c 100644 --- a/src/main/java/org/jabref/model/metadata/SelfContainedSaveOrder.java +++ b/src/main/java/org/jabref/model/metadata/SelfContainedSaveOrder.java @@ -2,14 +2,23 @@ import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * With this class, the user of an instance can directly sort things. Without looking up anything in the preferences or in the UI. + * + * To avoid confusion at the caller, we offer ORIGINAL and SPECIFIED only. Not TABLE. */ public class SelfContainedSaveOrder extends SaveOrder { + + public static final Logger LOGGER = LoggerFactory.getLogger(SelfContainedSaveOrder.class); + public SelfContainedSaveOrder(OrderType orderType, List sortCriteria) { super(orderType, sortCriteria); if (orderType == OrderType.TABLE) { - throw new IllegalArgumentException("TABLE requires external lookup."); + LOGGER.debug("TABLE with sort criteria {}", sortCriteria); + throw new IllegalArgumentException("TABLE might require external lookup."); } } @@ -22,6 +31,11 @@ public static SelfContainedSaveOrder of(SaveOrder saveOrder) { if (saveOrder instanceof SelfContainedSaveOrder order) { return order; } + if ((saveOrder.getOrderType() == OrderType.TABLE) && (!saveOrder.getSortCriteria().isEmpty())) { + // We map from TABLE to SPECIFIED to have the users of this class just to `switch` between + // ORIGINAL and SPECIFIED + return new SelfContainedSaveOrder(OrderType.SPECIFIED, saveOrder.getSortCriteria()); + } return new SelfContainedSaveOrder(saveOrder.getOrderType(), saveOrder.getSortCriteria()); } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 651ecc4ca85..46f2aab1c96 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -65,8 +65,9 @@ import org.jabref.logic.citationstyle.CitationStyle; import org.jabref.logic.citationstyle.CitationStylePreviewLayout; import org.jabref.logic.cleanup.FieldFormatterCleanups; +import org.jabref.logic.exporter.BibDatabaseWriter; import org.jabref.logic.exporter.MetaDataSerializer; -import org.jabref.logic.exporter.SaveConfiguration; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.exporter.TemplateExporter; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ImporterPreferences; @@ -2256,29 +2257,33 @@ private void storeExportSaveOrder(SaveOrder saveOrder) { putBoolean(EXPORT_TERTIARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(2).descending); } - public SaveOrder getTableSaveOrder() { + /** + * For the export configuration, generates the SelfContainedSaveOrder having the reference to TABLE resolved. + */ + public SelfContainedSaveOrder getSelfContainedTableSaveOrder() { List sortOrder = mainTableColumnPreferences.getColumnSortOrder(); - return new SaveOrder( - SaveOrder.OrderType.TABLE, + return new SelfContainedSaveOrder( + SaveOrder.OrderType.SPECIFIED, sortOrder.stream().flatMap(model -> model.getSortCriteria().stream()).toList()); } @Override - public SaveConfiguration getExportConfiguration() { - SaveOrder saveOrder = switch (getExportSaveOrder().getOrderType()) { - case TABLE -> this.getTableSaveOrder(); - case SPECIFIED -> this.getExportSaveOrder(); + public SelfContainedSaveConfiguration getSelfContainedExportConfiguration() { + SaveOrder exportSaveOrder = getExportSaveOrder(); + SelfContainedSaveOrder saveOrder = switch (exportSaveOrder.getOrderType()) { + case TABLE -> this.getSelfContainedTableSaveOrder(); + case SPECIFIED -> SelfContainedSaveOrder.of(exportSaveOrder); case ORIGINAL -> SaveOrder.getDefaultSaveOrder(); }; - return new SaveConfiguration() - .withSaveOrder(SelfContainedSaveOrder.of(saveOrder)) - .withReformatOnSave(getLibraryPreferences().shouldAlwaysReformatOnSave()); + return new SelfContainedSaveConfiguration( + saveOrder, false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, getLibraryPreferences() + .shouldAlwaysReformatOnSave()); } private List getCustomExportFormats() { LayoutFormatterPreferences layoutPreferences = getLayoutFormatterPreferences(); - SaveConfiguration saveConfiguration = getExportConfiguration(); + SelfContainedSaveConfiguration saveConfiguration = getSelfContainedExportConfiguration(); List formats = new ArrayList<>(); for (String toImport : getSeries(CUSTOM_EXPORT_FORMAT)) { @@ -2288,7 +2293,7 @@ private List getCustomExportFormats() { formatData.get(EXPORTER_FILENAME_INDEX), formatData.get(EXPORTER_EXTENSION_INDEX), layoutPreferences, - saveConfiguration.getSaveOrder()); + saveConfiguration.getSelfContainedSaveOrder()); format.setCustomExport(true); formats.add(format); } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 485e93ded56..554bcf67d71 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -15,7 +15,7 @@ import org.jabref.logic.JabRefException; import org.jabref.logic.bibtex.FieldPreferences; import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; -import org.jabref.logic.exporter.SaveConfiguration; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.fetcher.GrobidPreferences; @@ -73,7 +73,7 @@ public interface PreferencesService { /** * Returns the export configuration. The contained SaveConfiguration is a {@link org.jabref.model.metadata.SelfContainedSaveOrder} */ - SaveConfiguration getExportConfiguration(); + SelfContainedSaveConfiguration getSelfContainedExportConfiguration(); BibEntryTypesManager getCustomEntryTypesRepository(); diff --git a/src/test/java/org/jabref/gui/autosaveandbackup/BackupManagerDiscardedTest.java b/src/test/java/org/jabref/gui/autosaveandbackup/BackupManagerDiscardedTest.java index e7d868ee862..a1ee0b8031e 100644 --- a/src/test/java/org/jabref/gui/autosaveandbackup/BackupManagerDiscardedTest.java +++ b/src/test/java/org/jabref/gui/autosaveandbackup/BackupManagerDiscardedTest.java @@ -8,9 +8,10 @@ import org.jabref.gui.LibraryTab; import org.jabref.logic.exporter.AtomicFileWriter; +import org.jabref.logic.exporter.BibDatabaseWriter; import org.jabref.logic.exporter.BibWriter; import org.jabref.logic.exporter.BibtexDatabaseWriter; -import org.jabref.logic.exporter.SaveConfiguration; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -26,9 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Test for "discarded" flag @@ -38,7 +37,7 @@ class BackupManagerDiscardedTest { private BibDatabaseContext bibDatabaseContext; private BackupManager backupManager; private Path testBib; - private SaveConfiguration saveConfiguration; + private SelfContainedSaveConfiguration saveConfiguration; private PreferencesService preferencesService; private BibEntryTypesManager bibEntryTypesManager; private Path backupDir; @@ -54,17 +53,13 @@ public void setup(@TempDir Path tempDir) throws Exception { bibDatabaseContext.setDatabasePath(testBib); bibEntryTypesManager = new BibEntryTypesManager(); - - saveConfiguration = mock(SaveConfiguration.class); - when(saveConfiguration.shouldMakeBackup()).thenReturn(false); - when(saveConfiguration.getSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); - when(saveConfiguration.withMakeBackup(anyBoolean())).thenReturn(saveConfiguration); - + saveConfiguration = new SelfContainedSaveConfiguration(SaveOrder.getDefaultSaveOrder(), false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, false); preferencesService = mock(PreferencesService.class, Answers.RETURNS_DEEP_STUBS); saveDatabase(); backupManager = new BackupManager(mock(LibraryTab.class), bibDatabaseContext, bibEntryTypesManager, preferencesService); + makeBackup(); } diff --git a/src/test/java/org/jabref/gui/exporter/ExportToClipboardActionTest.java b/src/test/java/org/jabref/gui/exporter/ExportToClipboardActionTest.java index 9602c84fd59..973247fe8f0 100644 --- a/src/test/java/org/jabref/gui/exporter/ExportToClipboardActionTest.java +++ b/src/test/java/org/jabref/gui/exporter/ExportToClipboardActionTest.java @@ -14,7 +14,7 @@ import org.jabref.gui.util.CurrentThreadTaskExecutor; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.exporter.Exporter; -import org.jabref.logic.exporter.SaveConfiguration; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.StandardFileType; import org.jabref.logic.xmp.XmpPreferences; @@ -67,7 +67,7 @@ public void setUp() { taskExecutor = new CurrentThreadTaskExecutor(); when(preferences.getExportPreferences().getCustomExporters()).thenReturn(FXCollections.observableList(List.of())); - when(preferences.getExportConfiguration()).thenReturn(mock(SaveConfiguration.class)); + when(preferences.getSelfContainedExportConfiguration()).thenReturn(mock(SelfContainedSaveConfiguration.class)); when(preferences.getXmpPreferences()).thenReturn(mock(XmpPreferences.class)); exportToClipboardAction = new ExportToClipboardAction(dialogService, stateManager, clipBoardManager, taskExecutor, preferences); } @@ -93,7 +93,7 @@ public void export(BibDatabaseContext databaseContext, Path file, List when(preferences.getFilePreferences()).thenReturn(filePreferences); when(preferences.getLibraryPreferences()).thenReturn(libraryPreferences); when(preferences.getExportPreferences().getLastExportExtension()).thenReturn("HTML"); - when(preferences.getExportConfiguration().getSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); + when(preferences.getSelfContainedExportConfiguration().getSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); when(stateManager.getSelectedEntries()).thenReturn(selectedEntries); when(stateManager.getActiveDatabase()).thenReturn(Optional.ofNullable(databaseContext)); // noinspection ConstantConditions since databaseContext is mocked diff --git a/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java index 5094e60b8ad..be277db4e5b 100644 --- a/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -72,7 +72,7 @@ public class BibtexDatabaseWriterTest { private MetaData metaData; private BibDatabaseContext bibtexContext; private ImportFormatPreferences importFormatPreferences; - private SaveConfiguration saveConfiguration; + private SelfContainedSaveConfiguration saveConfiguration; private FieldPreferences fieldPreferences; private CitationKeyPatternPreferences citationKeyPatternPreferences; private BibEntryTypesManager entryTypesManager; @@ -82,7 +82,7 @@ public class BibtexDatabaseWriterTest { @BeforeEach void setUp() { fieldPreferences = new FieldPreferences(true, Collections.emptyList(), Collections.emptyList()); - saveConfiguration = new SaveConfiguration(SaveOrder.getDefaultSaveOrder(), false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, false); + saveConfiguration = new SelfContainedSaveConfiguration(SaveOrder.getDefaultSaveOrder(), false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, false); citationKeyPatternPreferences = mock(CitationKeyPatternPreferences.class, Answers.RETURNS_DEEP_STUBS); entryTypesManager = new BibEntryTypesManager(); stringWriter = new StringWriter(); @@ -680,7 +680,7 @@ void reformatEntryIfAskedToDoSo() throws Exception { entry.setChanged(false); database.insertEntry(entry); - saveConfiguration = new SaveConfiguration(SaveOrder.getDefaultSaveOrder(), false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, true); + saveConfiguration = new SelfContainedSaveConfiguration(SaveOrder.getDefaultSaveOrder(), false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, true); initializeDatabaseWriter(); databaseWriter.savePartOfDatabase(bibtexContext, Collections.singletonList(entry)); @@ -706,7 +706,7 @@ void reformatStringIfAskedToDoSo() throws Exception { string.setParsedSerialization("wrong serialization"); database.addString(string); - saveConfiguration = new SaveConfiguration(SaveOrder.getDefaultSaveOrder(), false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, true); + saveConfiguration = new SelfContainedSaveConfiguration(SaveOrder.getDefaultSaveOrder(), false, BibDatabaseWriter.SaveType.WITH_JABREF_META_DATA, true); initializeDatabaseWriter(); databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList());