-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Implement performSearchPaged for ACMPortalFetcher #12922
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
base: main
Are you sure you want to change the base?
Changes from all commits
0267eb3
26fdb6a
289a79a
7abc393
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,12 @@ | |
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.jabref.logic.UiCommand; | ||
import org.jabref.logic.journals.JournalAbbreviationLoader; | ||
|
@@ -48,7 +50,7 @@ | |
/// Does not do any preference migrations. | ||
public class JabKit { | ||
private static Logger LOGGER; | ||
|
||
private static Optional<String> deleteWhenClosingPath = Optional.empty(); | ||
public static void main(String[] args) { | ||
initLogging(args); | ||
|
||
|
@@ -71,7 +73,14 @@ private static void systemExit() { | |
} | ||
|
||
public static List<UiCommand> processArguments(String[] args, JabRefCliPreferences preferences, FileUpdateMonitor fileUpdateMonitor) { | ||
try { | ||
try {Optional<String> deleteWhenClosingPath = Optional.empty(); | ||
JabKit.deleteWhenClosingPath = deleteWhenClosingPath; | ||
|
||
for (String arg : args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this is from other PRs of yours, right? Is this code related to this PR or not? |
||
if (arg.startsWith("--deleteWhenClosing=")) { | ||
deleteWhenClosingPath = Optional.of(arg.substring("--deleteWhenClosing=".length())); | ||
} | ||
} | ||
Injector.setModelOrService(BuildInfo.class, new BuildInfo()); | ||
|
||
// Early exit in case another instance is already running | ||
|
@@ -84,7 +93,17 @@ public static List<UiCommand> processArguments(String[] args, JabRefCliPreferenc | |
|
||
Injector.setModelOrService(JournalAbbreviationRepository.class, JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences())); | ||
Injector.setModelOrService(ProtectedTermsLoader.class, new ProtectedTermsLoader(preferences.getProtectedTermsPreferences())); | ||
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | ||
deleteWhenClosingPath.ifPresent(path -> { | ||
try { | ||
Files.deleteIfExists(Paths.get(path)); | ||
} catch (IOException e) { | ||
LOGGER.warn("Failed to delete temporary file: " + path, e); | ||
} | ||
}); | ||
})); | ||
Comment on lines
+96
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'new Thread()' is discouraged. Instead, 'org.jabref.logic.util.BackgroundTask' and its 'executeWith' should be used for better resource management and consistency. |
||
|
||
System.exit(status); | ||
configureProxy(preferences.getProxyPreferences()); | ||
configureSSL(preferences.getSSLPreferences()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,9 +70,30 @@ void getURLForQuery() throws FetcherException, MalformedURLException, URISyntaxE | |
assertEquals(expected, url.toString()); | ||
} | ||
|
||
@Test | ||
void performSearchPagedReturnsResults() throws FetcherException { | ||
List<BibEntry> results = fetcher.performSearchPaged(new JabRefSearchTerm("machine learning"), 0); | ||
|
||
assertNotNull(results); | ||
assertFalse(results.isEmpty()); | ||
Comment on lines
+77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test should assert the contents of the results using assertEquals instead of checking for Boolean conditions with assertNotNull and assertFalse. |
||
} | ||
@Test | ||
void getParser() { | ||
ACMPortalParser expected = new ACMPortalParser(); | ||
assertEquals(expected.getClass(), fetcher.getParser().getClass()); | ||
|
||
} | ||
@Test | ||
void performSearchPagedReturnsExpectedResults() throws FetcherException { | ||
ACMPortalFetcher fetcherSpy = spy(new ACMPortalFetcher()); | ||
|
||
BibEntry expectedEntry = new BibEntry(); | ||
expectedEntry.setField("title", "Machine Learning: A Probabilistic Perspective"); | ||
Comment on lines
+90
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When creating a new BibEntry object, 'withers' should be used instead of 'setField' to improve code readability and maintainability. |
||
List<BibEntry> expectedResults = List.of(expectedEntry); | ||
|
||
doReturn(expectedResults).when(fetcherSpy).performSearchPaged(new JabRefSearchTerm("machine learning"), 0); | ||
|
||
List<BibEntry> results = fetcherSpy.performSearchPaged(new JabRefSearchTerm("machine learning"), 0); | ||
|
||
assertEquals(expectedResults, results); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shouldn't be modified