-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add TeXworks (Icon needs fixing) (#3197) Co-Authored-By: JohannBiorck <85625348+johannbiorck@users.noreply.github.com> * feat: add test for pushToTeXworks (#3197) * refactor: change icon to default icon (#3197) Co-Authored-By: JohannBiorck <85625348+johannbiorck@users.noreply.github.com> * fix: add TeXworks to applicationCommands (#3197) * doc: javadoc for PushToTeXworks (#3197) Co-Authored-By: JohannBiorck <85625348+johannbiorck@users.noreply.github.com> * Fix: find the test error + add other test (#3197) * add more tests and setCommandPath in PushToTeXworks (#3197) Co-Authored-By: JohannBiorck <85625348+johannbiorck@users.noreply.github.com> Co-Authored-By: LACHIRI ILIAS <67273129+lachiri-ilias@users.noreply.github.com> * doc: Update CHANGELOG.md #3197 Updated changelong to reflect changes. * fix: Fix Checkstyle for PushToTeXworksTest #3197 Co-Authored-By: Vlad Dobre <29517124+vladdobre@users.noreply.github.com> Co-Authored-By: Kr1st1an-F <100246316+kr1st1an-f@users.noreply.github.com> * fix: checkstyle for PushToTeXworksTest (end with newline) and openrewrite #3197 Co-Authored-By: Vlad Dobre <29517124+vladdobre@users.noreply.github.com> Co-Authored-By: Kr1st1an-F <100246316+kr1st1an-f@users.noreply.github.com> * Fix: fix suggestion for the pull request (#3197) * Update src/main/java/org/jabref/gui/push/PushToTeXworks.java * Modified tests, moved comments to interface --------- Co-authored-by: maxisr <maxism29.mi@gmail.com> Co-authored-by: JohannBiorck <85625348+johannbiorck@users.noreply.github.com> Co-authored-by: LACHIRI <lachiri@kth.se> Co-authored-by: LACHIRI ILIAS <67273129+lachiri-ilias@users.noreply.github.com> Co-authored-by: Kr1st1an-F <100246316+kr1st1an-f@users.noreply.github.com> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
- Loading branch information
1 parent
84ddaf5
commit 43eb3ef
Showing
7 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.jabref.gui.push; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.icon.IconTheme; | ||
import org.jabref.gui.icon.JabRefIcon; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
public class PushToTeXworks extends AbstractPushToApplication { | ||
|
||
public static final String NAME = PushToApplications.TEXWORKS; | ||
|
||
/** | ||
* Constructs a new {@code PushToTeXworks} instance. | ||
* | ||
* @param dialogService The dialog service for displaying messages to the user. | ||
* @param preferencesService The service for accessing user preferences. | ||
*/ | ||
public PushToTeXworks(DialogService dialogService, PreferencesService preferencesService) { | ||
super(dialogService, preferencesService); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public JabRefIcon getApplicationIcon() { | ||
// TODO: replace the placeholder icon with the real one. | ||
return IconTheme.JabRefIcons.APPLICATION_GENERIC; | ||
} | ||
|
||
@Override | ||
protected String[] getCommandLine(String keyString) { | ||
return new String[] {commandPath, "--insert-text", "%s%s%s".formatted(getCitePrefix(), keyString, getCiteSuffix())}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/test/java/org/jabref/gui/push/PushToTeXworksTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.jabref.gui.push; | ||
|
||
import java.util.Map; | ||
|
||
import javafx.beans.property.SimpleMapProperty; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableMap; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.logic.push.CitationCommandString; | ||
import org.jabref.preferences.ExternalApplicationsPreferences; | ||
import org.jabref.preferences.PreferencesService; | ||
import org.jabref.preferences.PushToApplicationPreferences; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Answers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
class PushToTeXworksTest { | ||
|
||
private static final String TEXWORKS_CLIENT_PATH = "/usr/bin/texworks"; | ||
private static final String DISPLAY_NAME = "TeXworks"; | ||
|
||
private PushToTeXworks pushToTeXworks; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
DialogService dialogService = mock(DialogService.class, Answers.RETURNS_DEEP_STUBS); | ||
PreferencesService preferencesService = mock(PreferencesService.class); | ||
PushToApplicationPreferences pushToApplicationPreferences = mock(PushToApplicationPreferences.class); | ||
|
||
// Mock the command path | ||
Map<String, String> commandPaths = Map.of(DISPLAY_NAME, TEXWORKS_CLIENT_PATH); | ||
ObservableMap<String, String> observableCommandPaths = FXCollections.observableMap(commandPaths); | ||
when(pushToApplicationPreferences.getCommandPaths()).thenReturn(new SimpleMapProperty<>(observableCommandPaths)); | ||
when(preferencesService.getPushToApplicationPreferences()).thenReturn(pushToApplicationPreferences); | ||
|
||
// Mock the return value for getCiteCommand() | ||
ExternalApplicationsPreferences externalApplicationsPreferences = mock(ExternalApplicationsPreferences.class); | ||
CitationCommandString mockCiteCommand = mock(CitationCommandString.class); | ||
when(mockCiteCommand.prefix()).thenReturn(""); | ||
when(mockCiteCommand.suffix()).thenReturn(""); | ||
when(externalApplicationsPreferences.getCiteCommand()).thenReturn(mockCiteCommand); | ||
when(preferencesService.getExternalApplicationsPreferences()).thenReturn(externalApplicationsPreferences); | ||
|
||
// Create a new instance of PushToTeXworks | ||
pushToTeXworks = new PushToTeXworks(dialogService, preferencesService); | ||
} | ||
|
||
/** | ||
* To verify that the PushToTeXworks class correctly returns its designated display name. | ||
* The display name is used to identify the application in the GUI. | ||
*/ | ||
@Test | ||
void displayName() { | ||
assertEquals(DISPLAY_NAME, pushToTeXworks.getDisplayName()); | ||
} | ||
|
||
/** | ||
* To verify that the PushToTeXworks class correctly returns the command line for TeXworks. | ||
* The command line is used to execute the application from the command line. | ||
*/ | ||
@Test | ||
void getCommandLine() { | ||
String keyString = "TestKey"; | ||
String[] expectedCommand = new String[] {null, "--insert-text", keyString}; // commandPath is only set in pushEntries | ||
|
||
String[] actualCommand = pushToTeXworks.getCommandLine(keyString); | ||
|
||
assertArrayEquals(expectedCommand, actualCommand); | ||
} | ||
|
||
/** | ||
* Check for the actual command and path with path is run. | ||
*/ | ||
@Test | ||
void pushEntries() { | ||
ProcessBuilder processBuilder = mock(ProcessBuilder.class); | ||
|
||
String testKey = "TestKey"; | ||
String[] expectedCommand = new String[] {TEXWORKS_CLIENT_PATH, "--insert-text", testKey}; | ||
|
||
pushToTeXworks.pushEntries(null, null, testKey, processBuilder); | ||
|
||
verify(processBuilder).command(expectedCommand); | ||
} | ||
|
||
/** | ||
* To verify that the PushToTeXworks class correctly returns the tooltip for TeXworks. | ||
* The tooltip is used to display a short description of the application in the GUI. | ||
*/ | ||
@Test | ||
void getTooltip() { | ||
assertEquals("Push entries to external application (TeXworks)", pushToTeXworks.getTooltip()); | ||
} | ||
} |