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 GUI tests #5781

Merged
merged 9 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 15 additions & 3 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,47 @@

public class Globals {

// JabRef version info
/**
* JabRef version info
*/
public static final BuildInfo BUILD_INFO = new BuildInfo();

// Remote listener
public static final RemoteListenerServerLifecycle REMOTE_LISTENER = new RemoteListenerServerLifecycle();

public static final ImportFormatReader IMPORT_FORMAT_READER = new ImportFormatReader();
public static final TaskExecutor TASK_EXECUTOR = new DefaultTaskExecutor();
// In the main program, this field is initialized in JabRefMain.java
// Each test case initializes this field if required

/**
* Each test case initializes this field if required
*/
public static JabRefPreferences prefs;

/**
* This field is initialized upon startup.
* Only GUI code is allowed to access it, logic code should use dependency injection.
*/
public static JournalAbbreviationLoader journalAbbreviationLoader;

/**
* This field is initialized upon startup.
* Only GUI code is allowed to access it, logic code should use dependency injection.
*/
public static ProtectedTermsLoader protectedTermsLoader;

/**
* Manager for the state of the GUI.
*/
public static StateManager stateManager = new StateManager();

public static ExporterFactory exportFactory;
public static CountingUndoManager undoManager = new CountingUndoManager();
public static BibEntryTypesManager entryTypesManager = new BibEntryTypesManager();
public static ClipBoardManager clipboardManager = new ClipBoardManager();

// Key binding preferences
private static KeyBindingRepository keyBindingRepository;

private static DefaultFileUpdateMonitor fileUpdateMonitor;
private static ThemeLoader themeLoader;
private static TelemetryClient telemetryClient;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/help/VersionWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class VersionWorker {
* The version which was previously ignored by the user
*/
private final Version toBeIgnored;

private final DialogService dialogService;
private final TaskExecutor taskExecutor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.push;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.jabref.Globals;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class PushToApplicationAction extends SimpleCommand {
private PushToApplication application;

public PushToApplicationAction(StateManager stateManager, PushToApplicationsManager pushToApplicationsManager, DialogService dialogService) {
this.application = Globals.prefs.getActivePushToApplication(pushToApplicationsManager);
this.application = Objects.requireNonNull(Globals.prefs.getActivePushToApplication(pushToApplicationsManager));
this.stateManager = stateManager;
this.dialogService = dialogService;

Expand All @@ -40,7 +41,7 @@ public PushToApplicationAction(StateManager stateManager, PushToApplicationsMana
}

public void updateApplication(PushToApplication application) {
this.application = application;
this.application = Objects.requireNonNull(application);
}

public Action getActionInformation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public TextFlow getDescription() {
}

textList.add(getCaseSensitiveDescription());
textList.add(TooltipTextUtil.createText("\n\nHint: To search specific fields only, enter for example:\n"));
koppor marked this conversation as resolved.
Show resolved Hide resolved
textList.add(TooltipTextUtil.createText("author=smith and title=electrical"));

TextFlow searchDescription = new TextFlow();
searchDescription.getChildren().setAll(textList);
return searchDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ public void putStringList(String key, List<String> value) {
public List<String> getStringList(String key) {
String names = get(key);
if (names == null) {
return new ArrayList<>();
return Collections.emptyList();
}

StringReader rd = new StringReader(names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class TestArchitectureTests {
private static final String CLASS_ORG_JABREF_UPDATE_TIMESTAMP_LISTENER_TEST = "UpdateTimestampListenerTest";
private static final String CLASS_ORG_JABREF_ENTRY_EDITOR_TEST = "EntryEditorTest";
private static final String CLASS_ORG_JABREF_LINKED_FILE_VIEW_MODEL_TEST = "LinkedFileViewModelTest";
private static final String CLASS_ORG_JABREF_SOURCE_TAB_TEST = "SourceTabTest";

private final List<String> exceptions;

public TestArchitectureTests() {

// Add exceptions for the architectural test here
// Note that bending the architectural constraints should not be done inconsiderately
exceptions = new ArrayList<>();
Expand All @@ -41,6 +41,7 @@ public TestArchitectureTests() {
exceptions.add(CLASS_ORG_JABREF_UPDATE_TIMESTAMP_LISTENER_TEST);
exceptions.add(CLASS_ORG_JABREF_ENTRY_EDITOR_TEST);
exceptions.add(CLASS_ORG_JABREF_LINKED_FILE_VIEW_MODEL_TEST);
exceptions.add(CLASS_ORG_JABREF_SOURCE_TAB_TEST);
}

public static Stream<String[]> data() {
Expand Down
71 changes: 0 additions & 71 deletions src/test/java/org/jabref/gui/BasePanelTest.java

This file was deleted.

21 changes: 19 additions & 2 deletions src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package org.jabref.gui.entryeditor;

import java.util.Collections;

import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.bibtex.FieldContentParserPreferences;
import org.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.testutils.category.GUITest;

import org.fxmisc.richtext.CodeArea;
Expand All @@ -25,10 +32,11 @@
import org.testfx.framework.junit5.Start;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@GUITest
@ExtendWith(ApplicationExtension.class)
public class SourceTabTest {
class SourceTabTest {

private Stage stage;
private Scene scene;
Expand All @@ -40,7 +48,16 @@ public class SourceTabTest {
public void onStart(Stage stage) {
area = new CodeArea();
area.appendText("some example\n text to go here\n across a couple of \n lines....");
sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), mock(ImportFormatPreferences.class), new DummyFileUpdateMonitor(), mock(DialogService.class), mock(StateManager.class));
StateManager stateManager = mock(StateManager.class);
when(stateManager.activeSearchQueryProperty()).thenReturn(OptionalObjectProperty.empty());
Globals.prefs = mock(JabRefPreferences.class);
koppor marked this conversation as resolved.
Show resolved Hide resolved
KeyBindingRepository keyBindingRepository = new KeyBindingRepository(Collections.emptyList(), Collections.emptyList());
when(Globals.prefs.getKeyBindingRepository()).thenReturn(keyBindingRepository);
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class);
when(importFormatPreferences.getFieldContentParserPreferences())
.thenReturn(mock(FieldContentParserPreferences.class));

sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), new LatexFieldFormatterPreferences(), importFormatPreferences, new DummyFileUpdateMonitor(), mock(DialogService.class), stateManager);
pane = new TabPane(
new Tab("main area", area),
new Tab("other tab", new Label("some text")),
Expand Down