Add simple unit tests#7543
Conversation
FieldChange.java 18% -> 94% Abbreviation.java 63% -> 88% SuggestionProviders.java 0% -> 100%
FileHelper.java -> Boundary testing of an empty file CitationKeyGenerator.java -> Boundary testing of testlagepage parser for 0-00 & 1-1 HTMLCharacterChecker.java -> Null Value Boundary test
ParsedEntryLink.java -> Partition testing of ParsingEntryLink UpperCaseFormatter.java -> Partition testing for special characters CitationStyleCacheTest.java -> Partition testing of cache storage
SPTest typo fix
|
will adjust and fix checkstyle this evening/tomorrow. |
Checkstyle passed
| @Test | ||
| void testEquals() { | ||
| Abbreviation abbreviation = new Abbreviation("Long Name", "L N", "LN"); | ||
| assertTrue(abbreviation.equals(abbreviation)); |
There was a problem hiding this comment.
I detect that this code is problematic. According to the Correctness (CORRECTNESS), SA: Self comparison of value with itself (SA_LOCAL_SELF_COMPARISON).
This method compares a local variable with itself, and may indicate a typo or a logic error. Make sure that you are comparing the right things.
There was a problem hiding this comment.
Thanks for the feedback! This test originally was meant to cover the branch in the implementation of the equals method, where it returns true for being compared to itself. But seeing your linked references, I agree that it makes more sense to leave it out - I have adjusted the test now.
Adjustments for @ellieMayVelasquez feedback #7543 (review)
koppor
left a comment
There was a problem hiding this comment.
Some comments in there. The main comment is that toString doesn't need to be tested if the software does not rely on that contract.
| entry.setField(journalEntryField, "Journal"); | ||
| entry.setField(publisherEntryField, "Publisher"); | ||
| entry.setField(specialEntryField, "2000"); | ||
| database.insertEntry(entry); |
There was a problem hiding this comment.
Why is the database constructed here? Where is it used? Maybe, the whole part can be removed?
| entry.setField(specialEntryField, "2000"); | ||
| database.insertEntry(entry); | ||
|
|
||
| assertSame("org.jabref.gui.autocompleter.EmptySuggestionProvider", empty.getForField(personEntryField).getClass().getName()); |
There was a problem hiding this comment.
Pls use assertEquals, because of consistency reasons to other tests (assertSame is seldmoly used).
| assertSame("org.jabref.gui.autocompleter.EmptySuggestionProvider", empty.getForField(personEntryField).getClass().getName()); | |
| assertEquals(org.jabref.gui.autocompleter.EmptySuggestionProvider.class, empty.getForField(personEntryField).getClass()); |
| assertEquals("43", CitationKeyGenerator.lastPage("43+")); | ||
| assertEquals("0", CitationKeyGenerator.lastPage("00--0")); | ||
| assertEquals("1", CitationKeyGenerator.lastPage("1--1")); | ||
|
|
There was a problem hiding this comment.
Please no empty line at the end of the method
There was a problem hiding this comment.
Please convert the whole test to a @ParameterizedTest. See #7544 for an inspiration
| BibEntry bibEntry = new BibEntry(); | ||
| bibEntry.setCitationKey("test"); | ||
| List<BibEntry> entries = new ArrayList<>(); | ||
| entries.add(0, bibEntry); | ||
| BibDatabase database = new BibDatabase(entries); |
There was a problem hiding this comment.
Can't one do the following?
| BibEntry bibEntry = new BibEntry(); | |
| bibEntry.setCitationKey("test"); | |
| List<BibEntry> entries = new ArrayList<>(); | |
| entries.add(0, bibEntry); | |
| BibDatabase database = new BibDatabase(entries); | |
| BibDatabase database = new BibDatabase(List.of(new BibEntry("test")); |
| BibDatabaseContext databaseContext = new BibDatabaseContext(database); | ||
| CitationStyleCache csCache = new CitationStyleCache(databaseContext); | ||
|
|
||
| assertNotNull(csCache.getCitationFor(bibEntry)); |
There was a problem hiding this comment.
Please test for a concrete result.
| @Test | ||
| void testHashCode() { | ||
| FieldChange fcNull = new FieldChange(null, null, null, null); | ||
| assertEquals(923521, fcNull.hashCode()); | ||
| } |
There was a problem hiding this comment.
Please no test for hashCode.
You can include https://jqno.nl/equalsverifier/ as dependency and work on that. Please do not test for that manually.
|
|
||
| @Test | ||
| void testEquals() { | ||
| BibEntry entry = new BibEntry(); |
There was a problem hiding this comment.
This is a very hard to read test. Please use https://jqno.nl/equalsverifier/ or just delete the test.
I never used https://jqno.nl/equalsverifier/ for myself. Please add a proposal based on that and we can investigate whether this is really worth it or causes much trouble.
| } | ||
|
|
||
| @Test | ||
| void testToString() { |
There was a problem hiding this comment.
Even though "Effective Java" recomments that toString is a contract; JabRef does not rely on that in this case. Please remove that test.
| } | ||
|
|
||
| @Test | ||
| void testToString() { |
There was a problem hiding this comment.
JabRef does not rely on the toString contract in this case. Please remove the test.
If you want, you can check for nonNull of toString.
| link = links.get(0); | ||
| source = create("source"); | ||
| target = create("target"); | ||
| entry = create("entry"); |
There was a problem hiding this comment.
Please do not initalize the variable here. It is used only in one test. Just move the variable to givenBibEntryWhenParsingThenExpectLink.
|
I think your course is over @ellieMayVelasquez, thus no more activity here? |
Thanks a lot for all the feedback @koppor ! - I will resolve all of these issues within this month hopefully, just haven't gotten around to it yet due to lots of parallel coursework atm :) |
|
@nasdas-dev May I ask which month you meant? 😇 |
addressed all comments & suggestions to test files
* upstream/main: (71 commits) [Bot] Update CSL styles (#7735) Fix for issue 6966: open all files of multiple entries (#7709) Add simple unit tests (#7696) Add simple unit tests (#7543) Update check-outdated-dependencies.yml Added preset for new entry keybindings and reintroduced defaults (#7705) Select the entry which has smaller dictonary order when merge (#7708) Update CHANGELOG.md fix: make more fields, fomatters, ids and languages sorted by alphabetical order (#7717) Bump libreoffice from 7.1.2 to 7.1.3 (#7721) Bump unoloader from 7.1.2 to 7.1.3 (#7724) Bump org.beryx.jlink from 2.23.7 to 2.23.8 (#7723) Bump org.openjfx.javafxplugin from 0.0.9 to 0.0.10 (#7725) fix: make fields sorted by lexicographical order (#7711) Fix tests Refactoring existing unit tests (#7687) Refactoring and addition of unit tests (#7581) Refactor simple Unit Tests (#7571) Add simple unit tests (#7544) add and extend unit tests (#7685) ...
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)