Add simple Unit Tests#7542
Conversation
|
Hey @Davfon , great to see someone takes a look at our test suite! |
|
Hi there @calixtus ! Thanks for the quick feedback! I willl look into it and will try to convert them to parameterized tests wherever possible. |
| } | ||
|
|
||
| @Test | ||
| public void parseGermanShortMonthTest() { |
There was a problem hiding this comment.
Is there more potential for parameterized tests here?
There was a problem hiding this comment.
Yes, there is. Thanks for the hint. I wasn't aware that you can also pass the expected result to the test.
Really nice feature :D
I changed all of them to parameterized Tests now.
|
|
||
| @Test | ||
| public void hashCodeTest() { | ||
| assertEquals(Objects.hash(path, 10, 1, 4, "lineText"), citation.hashCode()); |
There was a problem hiding this comment.
Tests for Hashcode and toString do not really add any value and especially toString is more of an internal representation.
There was a problem hiding this comment.
Oh ok, seemed like a rather easy way to increase the code coverage. Thanks for letting me know, I'll try to avoid them in them in the future. (I removed them with commit 21050ff)
| * form | ||
| */ | ||
| private static Optional<Month> parseGermanShortMonth(String value) { | ||
| public static Optional<Month> parseGermanShortMonth(String value) { |
There was a problem hiding this comment.
Maybe just remove the public prefix and make it "default"
There was a problem hiding this comment.
I'm not sure I understand it correctly, you mean like this: 5022f10?
There was a problem hiding this comment.
Yes, this makes it package visible, so it can be accessed by the unit test but not from others https://www.baeldung.com/java-access-modifiers
| } | ||
|
|
||
| @Test | ||
| void KeyFromAuthorAndTitle() { |
There was a problem hiding this comment.
I detect that this code is problematic. According to the Bad practice (BAD_PRACTICE), Nm: Method names should start with a lower case letter (NM_METHOD_NAMING_CONVENTION).
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
There was a problem hiding this comment.
Thanks for the feedback! Changed it in commit 93ab8a4
| public void equalsTest() { | ||
| Citation citation1 = new Citation(path, 10, 1, 4, "lineText"); | ||
| Citation citation2 = null; | ||
| assertTrue(citation.equals(citation1)); |
There was a problem hiding this comment.
This does not make any sense, why don't you use assertEquals? assertEquals calls the equals of the underlying objects. There is also a assertNotEquals method
There was a problem hiding this comment.
Yeah, that one is on me. Thanks for the feedback! :) Fixed in commit 6195973
Siedlerchr
left a comment
There was a problem hiding this comment.
Just some minor issue, rest is okay
calixtus
left a comment
There was a problem hiding this comment.
Looks good to me too, thanks! Merging now.
* upstream/master: (191 commits) Fix for issue 7416: font size of the preferences dialog does not update with the rest of the GUI. (#7509) Fix school/instituation is printed twice (#7574) Dsiable notarisation until we hae an account for JabRef e.V. (#7572) Fix citation keys unintentionally being overwritten on import (#7443) Fix AuthentificationPlugin not declared in mergedModule (#7570) Suggestions for changes in caching latex free authors (#7301) Add simple Unit Tests (#7542) Fix drag and drop into empty library (#7555) Bump richtextfx from 0.10.4 to 0.10.6 (#7563) Bump pdfbox from 2.0.22 to 2.0.23 (#7561) Bump org.eclipse.jgit (#7560) Bump fontbox from 2.0.22 to 2.0.23 (#7562) Bump guava from 30.1-jre to 30.1.1-jre (#7564) Bump xmpbox from 2.0.22 to 2.0.23 (#7565) Bump hmarr/auto-approve-action from v2.0.0 to v2.1.0 (#7566) Add gource (#7193) UI: Fix for group icon (#7552) Fix for issue 6487: Opening BibTex file (doubleclick) from Folder with spaces not working (#7551) add ability to insert arxivId (#7549) Fixed missing trigger for linked file operations (#7548) ...
I have added some simple unit tests that will increase code coverage / branch coverage.
They contribute to issue #6207
CHANGELOG.mddescribed in a way that is understandable for the average user (if applicable)