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

Enable auto sync per default for Open/Libre Office #6985

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Changed

- We changed the default preferences for OpenOffice/LibreOffice integration to automatically sync the bibliography when
inserting new citations in a OpenOffic/LibreOffice document. [#6957](https://github.com/JabRef/jabref/issues/6957)
- We restructured the 'File' tab and extracted some parts into the 'Linked files' tab [#6779](https://github.com/JabRef/jabref/pull/6779)
- JabRef now offers journal lists from <https://abbrv.jabref.org>. JabRef the lists which use a dot inside the abbreviations. [#5749](https://github.com/JabRef/jabref/pull/5749)
- We removed two useless preferences in the groups preferences dialog. [#6836](https://github.com/JabRef/jabref/pull/6836)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private JabRefPreferences() {
defaults.put(OO_JARS_PATH, OpenOfficePreferences.DEFAULT_LINUX_PATH);
}

defaults.put(OO_SYNC_WHEN_CITING, Boolean.FALSE);
defaults.put(OO_SYNC_WHEN_CITING, Boolean.TRUE);
defaults.put(OO_SHOW_PANEL, Boolean.FALSE);
defaults.put(OO_USE_ALL_OPEN_BASES, Boolean.TRUE);
defaults.put(OO_BIBLIOGRAPHY_STYLE_FILE, StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.jabref.preferences;
import org.jabref.logic.openoffice.OpenOfficePreferences;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class OpenOfficeSyncWhenCitingTest {

private static boolean previousValue;
private final JabRefPreferences preferences = JabRefPreferences.getInstance();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for thinking of a test, but you don't need one here as you are just testing that a variable is stored in the preferences which is not that critical. In JabRef we focus on testing the important things, e.g. model/logic.

To sum up => Just remove the test and it's all good.

And there is a general side effect you have here with the preferences in test , by using the JabRefPreferences Instance Object you are modifying the real preferences values which are also stored/persisted in the registry etc. Therefore, if you need to test something which depends on the preferencesm you need to mock them and "fake" the return values.
See for example:

   importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
        when(importFormatPreferences.getKeywordSeparator()).thenReturn(',');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback! I went ahead and removed that test. Thanks for your advice, I wasn't sure what would be worth testing.


@BeforeAll
public static void savePreferenceSyncWhenCiting() {
previousValue = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.OO_SYNC_WHEN_CITING);
}

@AfterAll
public static void restorePreferenceSyncWhenCiting() {
JabRefPreferences.getInstance().putBoolean(JabRefPreferences.OO_SYNC_WHEN_CITING, previousValue);
}

@Test
public void testDefaultSyncWhenCiting() {
OpenOfficePreferences prefs = preferences.getOpenOfficePreferences();
assertTrue(prefs.getSyncWhenCiting());
}

@Test
public void testChangedSyncWhenCiting() {
OpenOfficePreferences prefs = preferences.getOpenOfficePreferences();
prefs.setSyncWhenCiting(false);
assertFalse(prefs.getSyncWhenCiting());
}

}