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

Add test case for other and unknown type #2152

Merged
merged 4 commits into from
Oct 17, 2016

Conversation

tschechlovdev
Copy link
Contributor

Regarding: #29
I've added a test case for reading and writing a file with other and unknwon type.

@boceckts boceckts added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed stupro-ready-for-internal-review labels Oct 11, 2016
@boceckts boceckts changed the title [WIP] Add test case for other and unknown type Add test case for other and unknown type Oct 11, 2016
"}";

// read in bibtex string
ParserResult result = BibtexParser.parse(new StringReader(bibtexEntry), importFormatPreferences);
Copy link
Contributor

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);.

Copy link
Contributor Author

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();
Copy link
Contributor

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";
Copy link
Member

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)

Copy link
Contributor Author

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";
Copy link
Member

Choose a reason for hiding this comment

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

same remark as above.

@tobiasdiez tobiasdiez removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Oct 12, 2016
@tschechlovdev tschechlovdev added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Oct 12, 2016

@Test
public void readReallyUnknownTypeTest() throws Exception {
String bibtexEntry = "@ReallyUnknownType{test," + OS.NEWLINE +
Copy link
Member

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.

Copy link
Contributor Author

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).

Copy link
Member

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 ;-)

Copy link
Contributor Author

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 😄

Copy link
Member

@Siedlerchr Siedlerchr left a 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";
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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());

Copy link
Member

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.

Copy link
Contributor Author

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.

@tobiasdiez
Copy link
Member

Thanks for the follow-up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants