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

Medline plain importer test #354

Merged
merged 1 commit into from
Jan 7, 2016

Conversation

boceckts
Copy link
Contributor

Fixed IndexOutOfBounds for MedlinePlainImporter when Testfile has lines with too few characters. Removed unreachable code. Created 100% Testcoverage for MedlinePlainImporter.

@simonharrer
Copy link
Contributor

Please use rebase --interactive to squash the commits with messages like "" or see last commit.


//Test with txt File who is in recognized Format
Assert.assertTrue(Testimporter
.isRecognizedFormat(MedlinePlainImporter.class.getResourceAsStream("MedlinePlainImporterTest.txt")));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please see #310 for how to handle tests for this part.

@koppor
Copy link
Member

koppor commented Nov 17, 2015

@boceckts java.lang.StringIndexOutOfBoundsException: String index out of range: -1 during test. Please fix 😇

@koppor
Copy link
Member

koppor commented Nov 21, 2015

@boceckts Please squash the whole branch history into one commit. The magic command is git rebase master. See #379 (comment) for a longer discussion.

@boceckts boceckts force-pushed the MedlinePlainImporterTest branch from e373db3 to 92f2318 Compare November 22, 2015 11:00
@boceckts
Copy link
Contributor Author

Commits sind nun zu einem Commit zusammengefasst, index out of bounds exception gefixt und die Testmethoden sind nun leicht abgeändert zu AssertEquals.

@koppor
Copy link
Member

koppor commented Nov 22, 2015

Commit looks good 👍, but the test fail. Could you please investigate?

@boceckts
Copy link
Contributor Author

Welche Tests genau? Wenn ich die Klasse MedlinePlainImporterTest.java als JUnit Test ausführe, laufen alle Test bei mir ohne Fehler..

@@ -99,7 +99,7 @@ public boolean isRecognizedFormat(InputStream stream) throws IOException {

for (String entry1 : entries) {

if (entry1.trim().isEmpty()) {
if (entry1.trim().isEmpty() || (entry1.indexOf('-') < 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

!contains is better readable then indexOf, I think.

@koppor
Copy link
Member

koppor commented Nov 22, 2015

Siehst du hier beim Pull-Request die Meldung "All checks have failed"? Screenshot:

grabbed_20151122-153227

Du kannst dann auf "Details" bei "ci/circleci" klicken. Dort steht dann "junit failures: testIsRecognizedFormat - in net.sf.jabref.importer.fileformat.MedlinePlainImporterTest". Hier kannst du auf "more info" klicken. Da steht dann

java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java:78)
    at java.io.InputStreamReader.<init>(InputStreamReader.java:97)
    at net.sf.jabref.importer.ImportFormatReader.getReaderDefaultEncoding(ImportFormatReader.java:352)
    at net.sf.jabref.importer.fileformat.MedlinePlainImporter.isRecognizedFormat(MedlinePlainImporter.java:69)
    at net.sf.jabref.importer.fileformat.MedlinePlainImporterTest.testIsRecognizedFormat(MedlinePlainImporterTest.java:50)

@boceckts boceckts force-pushed the MedlinePlainImporterTest branch 2 times, most recently from 3278d90 to 5b50388 Compare November 22, 2015 16:50
@boceckts
Copy link
Contributor Author

@simonharrer changed it to !contains.
@koppor Seems like one character in the name of the test file was a different case than what I wrote in the java test class.

@koppor
Copy link
Member

koppor commented Nov 22, 2015

Your test file looks good. Seems to cover seven different entry types with different fields and different settings (doi, multine line titles). However, your test only treats two of them. Why don't you check all test entries?

You could check the result via prepared bibtex files. See https://github.com/JabRef/jabref/blob/6293b4d8ee9409afb25b402643a31904b56e33a0/src/test/java/net/sf/jabref/importer/fetcher/GVKParserTest.java. We are trying to get #378 through so that others can use these test improvements, too.

@koppor
Copy link
Member

koppor commented Nov 26, 2015

@boceckts We are ready to go from our side. Please have a look at GVKParserTest.java.

@boceckts boceckts force-pushed the MedlinePlainImporterTest branch from 0faabca to c201d7c Compare December 1, 2015 11:48
@boceckts boceckts force-pushed the MedlinePlainImporterTest branch from 4155d5f to 33382d0 Compare December 16, 2015 10:23
@boceckts
Copy link
Contributor Author

The Unit Test failes because multiple comments are being imported with a newline separator. However in the bibtex source the new lines are being ommitted therefore the assertion fails when testing with a import file using multiple comments such as "MedlinePlainImporterTest2.txt vs MedlinePlainImporterTestBib2.bib".

@boceckts boceckts force-pushed the MedlinePlainImporterTest branch 2 times, most recently from c693eb8 to eed59bb Compare December 19, 2015 13:49
public void testEmptyImport() throws Exception {
//Test entries with empty txt File
List<BibEntry> emptyEntries = importer.importEntries(
MedlinePlainImporter.class.getResourceAsStream("MedlinePlainImporterTestEmpty.txt"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Always use try-with-resources for getResourceAsStream usages.

}
}

list = Arrays.asList("MedlinePlainImporterTest.txt", "MedlinePlainImporterTest1.txt",
Copy link
Member

Choose a reason for hiding this comment

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

Split tests. Definitely a separate test for recognized and one for not-recognized files. I would even say that there should be a separate test for every file (maybe not for all files, just the ones which actually test a new behavior...say one for txt files and one for isi).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split tests is a great idea. I think one test method for isRecognized and one for isNotRecognized should be enough since this methods should not test any data but only check if the format is recognized or not.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you are right, normally one should be enough. But have a look at the isRecognized method and see if you cover all cases. Also it does not harm to check edge cases, like empty files.

@tobiasdiez
Copy link
Member

Good work 👍 .
Some tests are hard to read since they compare a medline import with a bib import. So it may be hard to see why they fail.

Better test specific features in small test cases (and maybe leave one big "integration" test). For example, (using pseudo-code)

public importParsesDoi() {
  Stream stream = StreamFromString("PMID-22664220" + "\n" + "AID - doi:10.1016/j.cpr.2005.02.002");
  List<Entries> entries = Import(stream);

  BibEntry expected = new BibEntry();
  expected.setField("doi", "10.1016/j.cpr.2005.02.002"); 
  Assert(entries = Collections.singletonList(expected));
}

could replace the test 4. See also https://github.com/JabRef/jabref/wiki/Code-Howtos#test-cases and http://stackoverflow.com/questions/782178/how-do-i-convert-a-string-to-an-inputstream-in-java.

@tobiasdiez tobiasdiez mentioned this pull request Dec 21, 2015
@boceckts boceckts force-pushed the MedlinePlainImporterTest branch 2 times, most recently from a9eda92 to 1f08f0c Compare December 22, 2015 12:35
@koppor
Copy link
Member

koppor commented Dec 23, 2015

Your test fail, because equals is not working on the canonical representation. We are afraid that changing equals (and hashCode) leads to unwanted side effects.

Therefore, please add a method to BibtexEntryAssert for comparing Lists (please use the List interface, not the ArrayList implementation). There, you can use assertEquals(BibEntry shouldBeEntry, BibEntry entry) for comparing the entries themselves.

@koppor
Copy link
Member

koppor commented Dec 23, 2015

Please also try to get rid of the warnings by eclipse. I think try-with-resources is the solution, isn't it?

grabbed_20151223-182645

@boceckts boceckts force-pushed the MedlinePlainImporterTest branch 2 times, most recently from d5b2c18 to 5c7f342 Compare December 24, 2015 12:05
@boceckts
Copy link
Contributor Author

#579

@boceckts boceckts force-pushed the MedlinePlainImporterTest branch from ea200ff to db9c5b3 Compare December 28, 2015 10:39
@boceckts
Copy link
Contributor Author

Added more test methodes to cover more if conditions and included the suggestions of the comments.

@koppor koppor added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Dec 31, 2015
public void testGetFormatName() {
Assert.assertNotEquals("", importer.getFormatName());
Assert.assertNotEquals("medlineplain", importer.getFormatName());
Assert.assertEquals("MedlinePlain", importer.getFormatName());
Copy link
Member

Choose a reason for hiding this comment

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

Only the last (positive) assert statement is necessary.

@tobiasdiez
Copy link
Member

Looks very good to me! I just pointed out some smaller things. If they are fixed, this can be merged in (from my point of view).

@boceckts boceckts force-pushed the MedlinePlainImporterTest branch from db9c5b3 to 4568400 Compare January 6, 2016 20:09
@boceckts
Copy link
Contributor Author

boceckts commented Jan 6, 2016

Thank you for the comments, I removed the unnecessary NotEquals and added tests for the remaining entries in the test file.

- Test import and resulting bibtex files added
- Testing imported entries vs bibtex files
- Fixed IndexOutOfBoundsExeption
- Fixed unreachable Code
@boceckts boceckts force-pushed the MedlinePlainImporterTest branch from 4568400 to 6d09b72 Compare January 6, 2016 20:55
@koppor
Copy link
Member

koppor commented Jan 7, 2016

Coverage 98.65%. I assume that covering line 126 was difficult, because there is no entry where the fourth character of the second line is NOT -. Or similar 😃

koppor added a commit that referenced this pull request Jan 7, 2016
@koppor koppor merged commit f1d7c2b into JabRef:master Jan 7, 2016
@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jan 7, 2016
@boceckts boceckts deleted the MedlinePlainImporterTest branch January 11, 2016 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants