-
Notifications
You must be signed in to change notification settings - Fork 0
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 unit tests for com.zheng.common.util.Paginator #2
base: master
Are you sure you want to change the base?
Conversation
These tests were written using Diffblue Cover.
These tests were written using Diffblue Cover.
Updated as per Peter's feedback:
|
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.
Formatting looks good.
@PowerMockIgnore({"javax.management.*"}) | ||
public class PaginatorTest { | ||
|
||
/* testedClasses: Paginator */ |
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.
Remove comment
|
||
/* testedClasses: Paginator */ | ||
@Test | ||
public void initTotalPageOutputVoid() { |
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 test provides 100% coverage for the method :-)
I wonder if we could use some of the setters so that the expected value is non-zero?
paginator.setParam(null); | ||
paginator.setPage(0); | ||
paginator.setTotalPage(0L); | ||
Reflector.setField(paginator, "rows", 2); |
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.
Reflection
InvocationTargetException { | ||
PowerMockito.mockStatic(Math.class); | ||
final Paginator paginator = new Paginator(); | ||
Reflector.setField(paginator, "total", 0L); |
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.
We don't want to see reflection in our tests. We might be able to work around this using constructor/getters/setters.
InvocationTargetException { | ||
PowerMockito.mockStatic(Math.class); | ||
final Paginator paginator = new Paginator(); | ||
Reflector.setField(paginator, "total", 0L); |
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.
Reflection
paginator.setParam("foo"); | ||
paginator.setPage(0); | ||
paginator.setTotalPage(0L); | ||
Reflector.setField(paginator, "rows", -786_432); |
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.
Reflection
I've analysed your codebase and noticed that com.zheng.common.util.Paginator is not fully tested.
I've written some tests for the methods in this class with the help of Diffblue Cover.
Hopefully, these tests will help you detect any regressions caused by future code changes. If you would find it useful to have additional tests written for this repository, I would be more than happy to look at other classes that you consider important in a subsequent PR.