-
-
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.
Merge remote-tracking branch 'upstream/master' into ooPanel
* upstream/master: Correct PNAS abbrev. (#4524) Create test (#4518) Bump junit-jupiter-params from 5.3.1 to 5.3.2 (#4514) Bump junit-vintage-engine from 5.3.1 to 5.3.2 (#4511) Bump junit-jupiter-engine from 5.3.1 to 5.3.2 (#4513) Bump richtextfx from 0.9.1 to 0.9.2 (#4512) Bump junit-jupiter-api from 5.3.1 to 5.3.2 (#4510) Bump junit-platform-launcher from 1.3.1 to 1.3.2 (#4515)
- Loading branch information
Showing
4 changed files
with
97 additions
and
14 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
77 changes: 77 additions & 0 deletions
77
src/test/java/org/jabref/gui/exporter/SaveAllActionTest.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,77 @@ | ||
package org.jabref.gui.exporter; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
import org.jabref.gui.BasePanel; | ||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.JabRefFrame; | ||
import org.jabref.gui.actions.Actions; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.anyString; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class SaveAllActionTest { | ||
|
||
private BasePanel firstPanel = mock(BasePanel.class); | ||
private BasePanel secondPanel = mock(BasePanel.class); | ||
private JabRefFrame jabRefFrame = mock(JabRefFrame.class); | ||
private DialogService dialogService = mock(DialogService.class); | ||
private BibDatabaseContext bibDatabaseContext = mock(BibDatabaseContext.class); | ||
private Optional<Path> databasePath = Optional.of(Paths.get("C:\\Users\\John_Doe\\Jabref")); | ||
private SaveAllAction saveAllAction; | ||
|
||
@Before | ||
public void setUp() { | ||
when(firstPanel.getBibDatabaseContext()).thenReturn(bibDatabaseContext); | ||
when(secondPanel.getBibDatabaseContext()).thenReturn(bibDatabaseContext); | ||
when(bibDatabaseContext.getDatabasePath()).thenReturn(databasePath); | ||
|
||
when(jabRefFrame.getBasePanelList()).thenReturn(Arrays.asList(firstPanel, secondPanel)); | ||
when(jabRefFrame.getDialogService()).thenReturn(dialogService); | ||
|
||
saveAllAction = new SaveAllAction(jabRefFrame); | ||
} | ||
|
||
@Test | ||
public void executeShouldRunSaveCommandInEveryPanel() { | ||
doNothing().when(dialogService).notify(anyString()); | ||
|
||
saveAllAction.execute(); | ||
|
||
verify(firstPanel, times(1)).runCommand(Actions.SAVE); | ||
verify(secondPanel, times(1)).runCommand(Actions.SAVE); | ||
} | ||
|
||
@Test | ||
public void executeShouldNotifyAboutSavingProcess() { | ||
when(bibDatabaseContext.getDatabasePath()).thenReturn(databasePath); | ||
|
||
saveAllAction.execute(); | ||
|
||
verify(dialogService, times(1)).notify(Localization.lang("Saving all libraries...")); | ||
verify(dialogService, times(1)).notify(Localization.lang("Save all finished.")); | ||
} | ||
|
||
@Test | ||
public void executeShouldShowSaveAsWindowIfDatabaseNotSelected() { | ||
when(bibDatabaseContext.getDatabasePath()).thenReturn(Optional.empty()); | ||
doNothing().when(dialogService).notify(anyString()); | ||
|
||
saveAllAction.execute(); | ||
|
||
verify(firstPanel, times(1)).runCommand(Actions.SAVE_AS); | ||
verify(secondPanel, times(1)).runCommand(Actions.SAVE_AS); | ||
} | ||
} |