-
-
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
Add test case for other and unknown type #2152
Conversation
"}"; | ||
|
||
// read in bibtex string | ||
ParserResult result = BibtexParser.parse(new StringReader(bibtexEntry), importFormatPreferences); |
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.
Please use new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry))
(or Collection<BibEntry> entries = new BibtexParser(importFormatPreferences).parseEntries(bibtexEntry);
.
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.
Done.
|
||
// read in bibtex string | ||
ParserResult result = BibtexParser.parse(new StringReader(bibtexEntry), importFormatPreferences); | ||
Collection<BibEntry> entries = result.getDatabase().getEntries(); |
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.
Same here.
Collection<BibEntry> entries = result.getDatabase().getEntries(); | ||
BibEntry entry = entries.iterator().next(); | ||
|
||
String resourceName = "/testbib/othertype.bib"; |
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.
Please remove the assert statement here. Only one assert / failure reason per test. If you think that is valuable to test that the other type is written correctly, then extract this test to a new test method (I would actually prefer two tests for writing and reading separately instead of a roundtrip test)
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.
Done. I've moved the assert to a new test method.
Collection<BibEntry> entries = result.getDatabase().getEntries(); | ||
BibEntry entry = entries.iterator().next(); | ||
|
||
String resourceName = "/testbib/reallyunknowntype.bib"; |
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.
same remark as above.
|
||
@Test | ||
public void readReallyUnknownTypeTest() throws Exception { | ||
String bibtexEntry = "@ReallyUnknownType{test," + OS.NEWLINE + |
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.
If you just write it, then there is no need to read it from a string...thus please create the BibEntry by hand in these cases.
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.
The purpose of this method was to ensure that the String was read in correctly. The other test method is still a roundtrip test. Then I don't think it makes much sense to just create the entry here by hand.
So I think I should change the roundtrip test to a test to just write the entry (and there I will create the entry by hand).
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.
If you have a test for reading something, then you should place it in the ParserTest ;-)
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.
Ok, removed it from here and placed it to the ParserTest 😄
2803c8c
to
6b93549
Compare
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.
Looks good!
Collection<BibEntry> entries = new BibtexParser(importFormatPreferences).parseEntries(bibtexEntry); | ||
BibEntry entry = entries.iterator().next(); | ||
|
||
String resourceName = "/testbib/reallyunknowntype.bib"; |
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.
Why is the resourceName necessary? The other tests don't use it
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've wanted to test explicit against the testfile "reallyunknowntype.bib". If I see right, the other tests don't use such test files.
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 is not necessary in this case. If you really want to test it, then please use the Resources directory handling, like in theBibTexImportetTest.class
and do not hardcode the relative dir.
Paths.get(BibtexImporterTest.class.getResource("BibtexImporter.examples.bib").toURI());
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.
Yes better compare it directly against a hand-created bibEntry (copy from above).
Then you can use assertEquals(singletonlist of expected entry, entries)
.
Apart from this last remark (sorry for being pedantic) this looks good to me and can be merged.
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.
Ok, I've created the bibentry now by hand.
ef44cf9
to
d4a73d4
Compare
d4a73d4
to
6b79a29
Compare
Thanks for the follow-up! |
Regarding: #29
I've added a test case for reading and writing a file with other and unknwon type.