Skip to content

Commit

Permalink
GUI tests now use new preferences (same as when the system is used th…
Browse files Browse the repository at this point in the history
…e first time ever)
  • Loading branch information
simonharrer committed Jan 18, 2016
1 parent e0f6ea4 commit 3785fdb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
15 changes: 3 additions & 12 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import javax.swing.*;

import net.sf.jabref.gui.*;
import net.sf.jabref.gui.actions.CleanUpAction;
import net.sf.jabref.gui.entryeditor.EntryEditorTabList;
Expand All @@ -60,6 +58,8 @@
import net.sf.jabref.specialfields.SpecialFieldsUtils;
import net.sf.jabref.logic.util.strings.StringUtil;

import javax.swing.*;

public final class JabRefPreferences {
private static final Log LOGGER = LogFactory.getLog(JabRefPreferences.class);
private static final String EXTERNAL_FILE_TYPES = "externalFileTypes";
Expand Down Expand Up @@ -427,29 +427,20 @@ private JabRefPreferences() {
defaults.put(TEXSTUDIO_PATH, OS.guessProgramPath("texstudio", "TeXstudio"));

if (OS.OS_X) {
//defaults.put(JabRefPreferences.PDFVIEWER, "/Applications/Preview.app");
//defaults.put(JabRefPreferences.PSVIEWER, "/Applications/Preview.app");
//defaults.put("htmlviewer", "/Applications/Safari.app");
defaults.put(EMACS_PATH, "emacsclient");
defaults.put(EMACS_23, true);
defaults.put(EMACS_ADDITIONAL_PARAMETERS, "-n -e");
defaults.put(FONT_FAMILY, "SansSerif");
defaults.put(WIN_LOOK_AND_FEEL, UIManager.getSystemLookAndFeelClassName());

} else if (OS.WINDOWS) {
//defaults.put(JabRefPreferences.PDFVIEWER, "cmd.exe /c start /b");
//defaults.put(JabRefPreferences.PSVIEWER, "cmd.exe /c start /b");
//defaults.put("htmlviewer", "cmd.exe /c start /b");
defaults.put(WIN_LOOK_AND_FEEL, "com.jgoodies.looks.windows.WindowsLookAndFeel");
defaults.put(EMACS_PATH, "emacsclient.exe");
defaults.put(EMACS_23, true);
defaults.put(EMACS_ADDITIONAL_PARAMETERS, "-n -e");
defaults.put(FONT_FAMILY, "Arial");

} else {
//defaults.put(JabRefPreferences.PDFVIEWER, "evince");
//defaults.put(JabRefPreferences.PSVIEWER, "gv");
//defaults.put("htmlviewer", "firefox");
defaults.put(WIN_LOOK_AND_FEEL, "com.jgoodies.plaf.plastic.Plastic3DLookAndFeel");
defaults.put(FONT_FAMILY, "SansSerif");

Expand All @@ -476,7 +467,7 @@ private JabRefPreferences() {
defaults.put(SIZE_X, 840);
defaults.put(SIZE_Y, 680);
defaults.put(WINDOW_MAXIMISED, Boolean.FALSE);
defaults.put(AUTO_RESIZE_MODE, JTable.AUTO_RESIZE_ALL_COLUMNS);
defaults.put(AUTO_RESIZE_MODE, 4); // JTable.AUTO_RESIZE_ALL_COLUMNS
defaults.put(PREVIEW_PANEL_HEIGHT, 200);
defaults.put(ENTRY_EDITOR_HEIGHT, 400);
defaults.put(TABLE_COLOR_CODES_ON, Boolean.FALSE);
Expand Down
43 changes: 41 additions & 2 deletions src/test/java/net/sf/jabref/gui/GUITest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package net.sf.jabref.gui;

import net.sf.jabref.JabRefException;
import net.sf.jabref.JabRefMain;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.gui.preftabs.PreferencesDialog;
import net.sf.jabref.logic.l10n.Localization;
import org.assertj.swing.core.GenericTypeMatcher;
import org.assertj.swing.dependency.jsr305.Nonnull;
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.swing.*;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.assertj.swing.finder.WindowFinder.findDialog;
import static org.assertj.swing.finder.WindowFinder.findFrame;
import static org.assertj.swing.launcher.ApplicationLauncher.application;
Expand All @@ -18,10 +29,36 @@ public class GUITest extends AssertJSwingJUnitTestCase {

private AWTExceptionHandler awtExceptionHandler;

@BeforeClass
public static void savePreferences() throws JabRefException, InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(() -> {
try {
JabRefPreferences.getInstance().exportPreferences("jabref.prefs.tmp");
} catch (JabRefException e) {
throw new RuntimeException(e);
}
JabRefPreferences.getInstance().defaults.keySet().forEach(key -> JabRefPreferences.getInstance().remove(key));
JabRefPreferences.getInstance().put(JabRefPreferences.LANGUAGE, "en");
});
}

@AfterClass
public static void restorePreferences() throws JabRefException, InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(() -> {
try {
JabRefPreferences.getInstance().importPreferences("jabref.prefs.tmp");
Files.delete(Paths.get("jabref.prefs.tmp"));
} catch (JabRefException | IOException e) {
throw new RuntimeException(e);
}
});
}

@Override
protected void onSetUp() {
awtExceptionHandler = new AWTExceptionHandler();
awtExceptionHandler.installExceptionDetectionInEDT();

application(JabRefMain.class).start();
}

Expand Down Expand Up @@ -57,7 +94,8 @@ public void testCreateBibtexEntry() {
mainFrame.menuItemWithPath("BibTeX", "New entry").click();
findDialog(EntryTypeDialog.class).using(robot()).button(new GenericTypeMatcher<JButton>(JButton.class) {

@Override protected boolean isMatching(@Nonnull JButton jButton) {
@Override
protected boolean isMatching(@Nonnull JButton jButton) {
return "Book".equals(jButton.getText());
}
}).click();
Expand All @@ -72,7 +110,8 @@ public void testOpenAndSavePreferences() {
mainFrame.menuItemWithPath("Options", "Preferences").click();
findDialog(PreferencesDialog.class).using(robot()).button(new GenericTypeMatcher<JButton>(JButton.class) {

@Override protected boolean isMatching(@Nonnull JButton jButton) {
@Override
protected boolean isMatching(@Nonnull JButton jButton) {
return "OK".equals(jButton.getText());
}
}).click();
Expand Down

0 comments on commit 3785fdb

Please sign in to comment.