forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Junit tests cases to verify that commands retrieve the correct database, and that the command defaults to the active database otherwise. Tests cases added in response to a bug fix, see: JabRef#8466
- Loading branch information
1 parent
89bf361
commit 40a28d2
Showing
2 changed files
with
64 additions
and
2 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
56 changes: 56 additions & 0 deletions
56
src/test/java/org/jabref/gui/util/OpenConsoleActionTest.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,56 @@ | ||
package org.jabref.gui.util; | ||
|
||
import java.util.Optional; | ||
|
||
import org.jabref.gui.OpenConsoleAction; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class OpenConsoleActionTest { | ||
|
||
private final StateManager stateManager = mock(StateManager.class); | ||
private final PreferencesService preferences = mock(PreferencesService.class); | ||
private final BibDatabaseContext current = mock(BibDatabaseContext.class); | ||
private final BibDatabaseContext other = mock(BibDatabaseContext.class); | ||
|
||
@BeforeEach | ||
public void setup() { | ||
when(stateManager.activeDatabaseProperty()).thenReturn(OptionalObjectProperty.empty()); | ||
when(stateManager.getActiveDatabase()).thenReturn(Optional.of(current)); | ||
} | ||
|
||
@Test | ||
public void newActionGetsCurrentDatabase() { | ||
OpenConsoleAction action = new OpenConsoleAction(stateManager, preferences); | ||
action.execute(); | ||
verify(stateManager, times(1)).getActiveDatabase(); | ||
verify(current, times(1)).getDatabasePath(); | ||
} | ||
|
||
@Test | ||
public void newActionGetsSuppliedDatabase() { | ||
OpenConsoleAction action = new OpenConsoleAction(() -> other, stateManager, preferences); | ||
action.execute(); | ||
verify(stateManager, never()).getActiveDatabase(); | ||
verify(other, times(1)).getDatabasePath(); | ||
} | ||
|
||
@Test | ||
public void actionDefaultsToCurrentDatabase() { | ||
OpenConsoleAction action = new OpenConsoleAction(() -> null, stateManager, preferences); | ||
action.execute(); | ||
verify(stateManager, times(1)).getActiveDatabase(); | ||
verify(current, times(1)).getDatabasePath(); | ||
} | ||
|
||
} |