-
-
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 more unit tests #7638
Add more unit tests #7638
Conversation
|
||
public class ImporterViewModelTest { | ||
|
||
private final CustomImporter importer = mock(CustomImporter.class); |
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.
This whole test does not test any functionality. You are just testing java's getter and setter or property.
Don't just write tests for the sake of increasing testscoverage. Testing should concencrate on testing logic or implementaition
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 can of course exclude this test, if you prefer so. I understand that testing logic and implementation is more valueable than increasing coverage. But higher coverage ultimately reaches the same goal. And according to the comment on issue #6207 the aim is to reach 100% code coverage.
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 changed the text, because the knowledge that increasing coverage in an equal way is not as common as I assumed. I mean: If one class has 10% coverage, another has 90%, it is better to work on the class having 10% than trying to increase the coverage from 90% to 100% in the 90% class.
src/test/java/org/jabref/logic/bibtex/comparator/BibStringDiffTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/bibtex/comparator/BibStringDiffTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/bibtex/comparator/PreambleDiffTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/bibtex/comparator/PreambleDiffTest.java
Outdated
Show resolved
Hide resolved
It would be really nice if you would finish this PR asap! @Davfon |
Thanks for the feedback and sorry for the late response. I will try to do the changes by tomorrow evening. |
Address the requested changes from #7638
Should be all good now. Had to override the equals method. (And add hashCode() for checkstyle) Thanks again for the good inputs. |
@@ -88,4 +88,18 @@ public BibtexString getOriginalString() { | |||
public BibtexString getNewString() { | |||
return newString; | |||
} | |||
|
|||
@Override | |||
public boolean equals(Object other) { |
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.
public boolean equals(Object other) { | |
public boolean equals(Object other) { | |
if (this == other) { | |
return true; | |
} | |
if ((other == null) || (getClass() != other.getClass())) { | |
return false; | |
} | |
BibStringDiff that = (BibStringDiff) other; | |
return Objects.equals(newString, other.newString) && Objects.equals(originalString, that.originalString); |
Do not use toString() beause the BIbTexString class has it's own equals methods which will then be called autoamtically internally.
And tip for the next time: Your IDE has an option to generate equals/hasCode methos
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.
That's a good point, but since the BibtexString equals() method is strict and also compares the IDs of two BibtexStrings, it makes things a bit more complicated.
Is it intended, that two BibtexStrings that only differ in their ID are not considered equal? Because right now these would not be equal:
private final BibtexString bStr1 = new BibtexString("name", "content");
private final BibtexString bStr2 = new BibtexString("name", "content");
Since they get different IDs when they are created.
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.
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.
Strings are IMHO key/value pairs: https://docs.jabref.org/fields/strings.
I think, the Id fiels should not be treated when "equals". However, please, please have a look at the way how a BibEntry is compared and how Ids are treated. There should be a comment on that in the JavaDoc.
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 so too (that they are key/value pairs)
A BibEntry is compared by type, fields & commentsBeforeEntry. The Ids are not used for comparing. There was no JavaDoc for the equals method. I would suggest removing the Id comparison in the BibtexString.equals() method. (see last commit)
src/main/java/org/jabref/logic/bibtex/comparator/PreambleDiff.java
Outdated
Show resolved
Hide resolved
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.
Some comments on tests
src/test/java/org/jabref/logic/bibtex/comparator/PreambleDiffTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/bibtex/comparator/BibStringDiffTest.java
Outdated
Show resolved
Hide resolved
Thanks for the follow up fixes and as you can see you discovered an error in the equals implementation for the BibTexStrings |
This pull request contributes to issue #6207, which is to add more unit tests to the project. The tests make use of mocks (stubbing) to simulate the behavior of some classes.
Tests added:
ImporterViewModelTest
BibStringDiffTest
PreambleDiffTest
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)