Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build... #4128

Merged
merged 2 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,6 @@ Mark\ new\ entries\ with\ owner\ name=Mark new entries with owner name

Memory\ stick\ mode=Memory stick mode

Menu\ and\ label\ font\ size=Menu and label font size

Merged\ external\ changes=Merged external changes
Merge\ fields=Merge fields

Expand Down Expand Up @@ -779,8 +777,6 @@ Override=Override

Override\ default\ file\ directories=Override default file directories

Override\ default\ font\ settings=Override default font settings

Override\ the\ BibTeX\ field\ by\ the\ selected\ text=Override the BibTeX field by the selected text


Expand Down Expand Up @@ -979,7 +975,6 @@ Select\ all=Select all
Select\ encoding=Select encoding

Select\ entry\ type=Select entry type
Select\ external\ application=Select external application

Select\ file\ from\ ZIP-archive=Select file from ZIP-archive

Expand Down Expand Up @@ -1327,7 +1322,6 @@ Autocomplete\ names\ in\ 'Firstname\ Lastname'\ format\ only=Autocomplete names
Autocomplete\ names\ in\ 'Lastname,\ Firstname'\ format\ only=Autocomplete names in 'Lastname, Firstname' format only
Autocomplete\ names\ in\ both\ formats=Autocomplete names in both formats
The\ name\ 'comment'\ cannot\ be\ used\ as\ an\ entry\ type\ name.=The name 'comment' cannot be used as an entry type name.
You\ must\ enter\ an\ integer\ value\ in\ the\ text\ field\ for=You must enter an integer value in the text field for
Send\ as\ email=Send as email
References=References
Sending\ of\ emails=Sending of emails
Expand Down Expand Up @@ -2137,8 +2131,6 @@ journal\ not\ found\ in\ abbreviation\ list=journal not found in abbreviation li
Unhandled\ exception\ occurred.=Unhandled exception occurred.

strings\ included=strings included
Size\ of\ large\ icons=Size of large icons
Size\ of\ small\ icons=Size of small icons
Default\ table\ font\ size=Default table font size
Escape\ underscores=Escape underscores
Color=Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package org.jabref.gui.fieldeditors;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.metadata.FileDirectoryPreferences;
import org.jabref.preferences.JabRefPreferences;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit$pioneer.jupiter.TempDirectory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -34,32 +32,31 @@
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;

public class LinkedFileViewModelTest {
@ExtendWith(TempDirectory.class)
class LinkedFileViewModelTest {

@Rule public TemporaryFolder tempFolder = new TemporaryFolder();
private Path tempFile;
private final JabRefPreferences preferences = mock(JabRefPreferences.class);
private final JournalAbbreviationLoader abbreviationLoader = mock(JournalAbbreviationLoader.class);
private LinkedFile linkedFile;
private BibEntry entry;
private BibDatabaseContext databaseContext;
private TaskExecutor taskExecutor;
private DialogService dialogService;
private final FileDirectoryPreferences fileDirectoryPreferences = mock(FileDirectoryPreferences.class);

@Before
public void setUp() {
@BeforeEach
void setUp(@TempDirectory.TempDir Path tempFolder) throws Exception {
entry = new BibEntry();
databaseContext = new BibDatabaseContext();
taskExecutor = mock(TaskExecutor.class);
dialogService = mock(DialogService.class);
Globals.prefs = mock(JabRefPreferences.class);
when(Globals.prefs.getDefaultEncoding()).thenReturn(StandardCharsets.UTF_8);
FileDirectoryPreferences fileDirectoryPreferences = mock(FileDirectoryPreferences.class);
when(Globals.prefs.getFileDirectoryPreferences()).thenReturn(fileDirectoryPreferences);

tempFile = tempFolder.resolve("temporaryFile");
Files.createFile(tempFile);
}

@Test
public void deleteWhenFilePathNotPresentReturnsTrue() {
void deleteWhenFilePathNotPresentReturnsTrue() {
// Making this a spy, so we can inject an empty optional without digging into the implementation
linkedFile = spy(new LinkedFile("", "nonexistent file", ""));
doReturn(Optional.empty()).when(linkedFile).findIn(any(BibDatabaseContext.class), any(FileDirectoryPreferences.class));
Expand All @@ -72,9 +69,8 @@ public void deleteWhenFilePathNotPresentReturnsTrue() {
}

@Test
public void deleteWhenRemoveChosenReturnsTrue() throws IOException {
File tempFile = tempFolder.newFile();
linkedFile = new LinkedFile("", tempFile.getAbsolutePath(), "");
void deleteWhenRemoveChosenReturnsTrueButDoesNotDeletesFile() throws IOException {
linkedFile = new LinkedFile("", tempFile.toString(), "");
when(dialogService.showCustomButtonDialogAndWait(
any(AlertType.class),
anyString(),
Expand All @@ -87,13 +83,12 @@ public void deleteWhenRemoveChosenReturnsTrue() throws IOException {
boolean removed = viewModel.delete(fileDirectoryPreferences);

assertTrue(removed);
assertTrue(tempFile.exists());
assertTrue(Files.exists(tempFile));
}

@Test
public void deleteWhenDeleteChosenReturnsTrueAndDeletesFile() throws IOException {
File tempFile = tempFolder.newFile();
linkedFile = new LinkedFile("", tempFile.getAbsolutePath(), "");
void deleteWhenDeleteChosenReturnsTrueAndDeletesFile() throws IOException {
linkedFile = new LinkedFile("", tempFile.toString(), "");
when(dialogService.showCustomButtonDialogAndWait(
any(AlertType.class),
anyString(),
Expand All @@ -106,11 +101,11 @@ public void deleteWhenDeleteChosenReturnsTrueAndDeletesFile() throws IOException
boolean removed = viewModel.delete(fileDirectoryPreferences);

assertTrue(removed);
assertFalse(tempFile.exists());
assertFalse(Files.exists(tempFile));
}

@Test
public void deleteWhenDeleteChosenAndFileMissingReturnsFalse() throws IOException {
void deleteWhenDeleteChosenAndFileMissingReturnsFalse() throws IOException {
linkedFile = new LinkedFile("", "!!nonexistent file!!", "");
when(dialogService.showCustomButtonDialogAndWait(
any(AlertType.class),
Expand All @@ -128,9 +123,8 @@ public void deleteWhenDeleteChosenAndFileMissingReturnsFalse() throws IOExceptio
}

@Test
public void deleteWhenDialogCancelledReturnsFalse() throws IOException {
File tempFile = tempFolder.newFile();
linkedFile = new LinkedFile("desc", tempFile.getAbsolutePath(), "pdf");
void deleteWhenDialogCancelledReturnsFalseAndDoesNotRemoveFile() throws IOException {
linkedFile = new LinkedFile("desc", tempFile.toString(), "pdf");
when(dialogService.showCustomButtonDialogAndWait(
any(AlertType.class),
anyString(),
Expand All @@ -143,6 +137,6 @@ public void deleteWhenDialogCancelledReturnsFalse() throws IOException {
boolean removed = viewModel.delete(fileDirectoryPreferences);

assertFalse(removed);
assertTrue(tempFile.exists());
assertTrue(Files.exists(tempFile));
}
}