|
| 1 | +package org.jabref.gui.externalfiles; |
| 2 | + |
| 3 | +import java.nio.file.Path; |
| 4 | +import java.util.Optional; |
| 5 | + |
| 6 | +import org.jabref.gui.DialogService; |
| 7 | +import org.jabref.gui.StateManager; |
| 8 | +import org.jabref.logic.shared.DatabaseLocation; |
| 9 | +import org.jabref.model.database.BibDatabaseContext; |
| 10 | + |
| 11 | +import org.junit.jupiter.api.BeforeEach; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | +import org.mockito.Mock; |
| 14 | +import org.mockito.MockitoAnnotations; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 18 | +import static org.mockito.Mockito.when; |
| 19 | + |
| 20 | +class FindUnlinkedFilesActionTest { |
| 21 | + |
| 22 | + @Mock |
| 23 | + private DialogService dialogService; |
| 24 | + |
| 25 | + @Mock |
| 26 | + private BibDatabaseContext databaseContext; |
| 27 | + |
| 28 | + private StateManager stateManager; |
| 29 | + private FindUnlinkedFilesAction action; |
| 30 | + |
| 31 | + @BeforeEach |
| 32 | + void setUp() { |
| 33 | + MockitoAnnotations.openMocks(this); |
| 34 | + stateManager = new StateManager(); |
| 35 | + action = new FindUnlinkedFilesAction(dialogService, stateManager); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + void isEnabledWhenNewDatabaseIsSavedTest() { |
| 40 | + when(databaseContext.getDatabasePath()).thenReturn(Optional.of(Path.of("test.bib"))); |
| 41 | + when(databaseContext.getLocation()).thenReturn(DatabaseLocation.LOCAL); |
| 42 | + |
| 43 | + stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext)); |
| 44 | + |
| 45 | + assertTrue(action.executableProperty().get()); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + void isDisabledWhenNewDatabasePathIsEmptyTest() { |
| 50 | + when(databaseContext.getDatabasePath()).thenReturn(Optional.empty()); |
| 51 | + when(databaseContext.getLocation()).thenReturn(DatabaseLocation.LOCAL); |
| 52 | + |
| 53 | + stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext)); |
| 54 | + |
| 55 | + assertFalse(action.executableProperty().get()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void isDisabledWhenNewDatabaseIsNotLocalTest() { |
| 60 | + when(databaseContext.getDatabasePath()).thenReturn(Optional.of(Path.of("test.bib"))); |
| 61 | + when(databaseContext.getLocation()).thenReturn(DatabaseLocation.SHARED); |
| 62 | + |
| 63 | + stateManager.activeDatabaseProperty().setValue(Optional.of(databaseContext)); |
| 64 | + |
| 65 | + assertFalse(action.executableProperty().get()); |
| 66 | + } |
| 67 | +} |
0 commit comments