-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
MedlineImporterTest #547
Merged
Merged
MedlineImporterTest #547
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
100 changes: 100 additions & 0 deletions
100
src/test/java/net/sf/jabref/importer/fileformat/MedlineImporterTest.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,100 @@ | ||
package net.sf.jabref.importer.fileformat; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
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.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.importer.OutputPrinterToNull; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Articles in the medline format can be downloaded from http://www.ncbi.nlm.nih.gov/pubmed/. | ||
* 1. Search for a term and make sure you have selected the PubMed database | ||
* 2. Select the results you want to export by checking their checkboxes | ||
* 3. Press on the 'Send to' drop down menu on top of the search results | ||
* 4. Select 'File' as Destination and 'XML' as Format | ||
* 5. Press 'Create File' to download your search results in a medline xml file | ||
* | ||
* @author Daniel Mair/Bruehl | ||
* | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class MedlineImporterTest { | ||
|
||
private MedlineImporter medlineImporter; | ||
private static final String FILEFORMAT_PATH = "src/test/resources/net/sf/jabref/importer/fileformat"; | ||
|
||
/** | ||
* Generates a List of all files in the package "/src/test/resources/net/sf/jabref/importer/fileformat" | ||
* @return A list of Names | ||
* @throws IOException | ||
*/ | ||
public List<String> getTestFiles() throws IOException { | ||
List<String> files = new ArrayList<>(); | ||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(FILEFORMAT_PATH))) { | ||
stream.forEach(n -> files.add(n.getFileName().toString())); | ||
} | ||
return files; | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
this.medlineImporter = new MedlineImporter(); | ||
} | ||
|
||
@Test | ||
public void testExceptionOnInputStream() throws IOException { | ||
try (InputStream is = Mockito.mock(InputStream.class)) { | ||
Mockito.doThrow(new IOException()).when(is).read(); | ||
List<BibEntry> entry = medlineImporter.importEntries(is, new OutputPrinterToNull()); | ||
Assert.assertTrue(entry.isEmpty()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetItemsEmpty() { | ||
MedlineHandler handler = new MedlineHandler(); | ||
assertEquals(Collections.emptyList(), handler.getItems()); | ||
} | ||
|
||
@Test | ||
public void testGetFormatName() { | ||
assertEquals("Medline", medlineImporter.getFormatName()); | ||
} | ||
|
||
@Test | ||
public void testGetCLIId() { | ||
assertEquals("medline", medlineImporter.getCLIId()); | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormatReject() throws IOException { | ||
List<String> list = getTestFiles().stream().filter(n -> !n.startsWith("MedlineImporter")) | ||
.collect(Collectors.toList()); | ||
|
||
for (String str : list) { | ||
try (InputStream is = MedlineImporter.class.getResourceAsStream(str)) { | ||
Assert.assertFalse(medlineImporter.isRecognizedFormat(is)); | ||
} | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/test/java/net/sf/jabref/importer/fileformat/MedlineImporterTestFiles.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,79 @@ | ||
package net.sf.jabref.importer.fileformat; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
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.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.importer.OutputPrinterToNull; | ||
import net.sf.jabref.logic.bibtex.BibEntryAssert; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameter; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(Parameterized.class) | ||
public class MedlineImporterTestFiles { | ||
|
||
private final static String FILEFORMAT_PATH = "src/test/resources/net/sf/jabref/importer/fileformat"; | ||
|
||
private MedlineImporter medlineImporter; | ||
|
||
@Parameter | ||
public String fileName; | ||
|
||
|
||
@Before | ||
public void setUp() { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
medlineImporter = new MedlineImporter(); | ||
} | ||
|
||
@Parameters(name = "{0}") | ||
public static Collection<String> fileNames() throws IOException { | ||
List<String> files = new ArrayList<>(); | ||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(FILEFORMAT_PATH))) { | ||
stream.forEach(n -> files.add(n.getFileName().toString())); | ||
} | ||
return files.stream().filter(n -> n.startsWith("MedlineImporterTest")).filter(n -> n.endsWith(".xml")) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormat() throws IOException { | ||
try (InputStream stream = MedlineImporterTest.class.getResourceAsStream(fileName)) { | ||
Assert.assertTrue(medlineImporter.isRecognizedFormat(stream)); | ||
} | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void testImportEntries() throws IOException { | ||
try (InputStream inputStream = MedlineImporterTest.class.getResourceAsStream(fileName)) { | ||
List<BibEntry> medlineEntries = medlineImporter.importEntries(inputStream, new OutputPrinterToNull()); | ||
String bibFileName = fileName.replace(".xml", ".bib"); | ||
if (medlineEntries.isEmpty()) { | ||
assertEquals(Collections.emptyList(), medlineEntries); | ||
} else { | ||
BibEntryAssert.assertEquals(MedlineImporterTest.class, bibFileName, medlineEntries); | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/resources/net/sf/jabref/importer/fileformat/MedlineImporterTestArticleID.bib
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,14 @@ | ||
% Encoding: UTF-8 | ||
|
||
@article{, | ||
abstract = {This abstract is a dummy.}, | ||
author = {Rhein, Joshua and Bahr, Nathan C. and Hemmert, Andrew C. and Cloud, Joann L. and Bellamkonda, Satya and Oswald, Cody and Lo, Eric and Nabeta, Henry and Kiggundu, Reuben and Akampurira, Andrew and Musubire, Abdu and Williams, Darlisha A. and Meya, David B. and Boulware, David R. and , A. S. T. R. O.-C. M. Team}, | ||
institution = {Division of Infectious Disease and International Health, Department of Medicine, University of Minnesota, Minneapolis, MN, USA.}, | ||
journal = {Diagn Microbiol Infect Dis}, | ||
language = {eng}, | ||
medline-pst = {aheadofprint}, | ||
month = {Dec}, | ||
pmid = {26711635}, | ||
title = {Diagnostic performance of a multiplex PCR assay for meningitis in an HIV-infected population in Uganda.}, | ||
year = {2015} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Mind the formatting, please.