-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.zheng.common.util; | ||
|
||
import static org.mockito.Matchers.anyDouble; | ||
import com.diffblue.deeptestutils.Reflector; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PowerMockIgnore({"javax.management.*"}) | ||
public class PaginatorTest { | ||
|
||
/* testedClasses: Paginator */ | ||
@Test | ||
public void initTotalPageOutputVoid() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test provides 100% coverage for the method :-) |
||
final Paginator paginator = new Paginator(); | ||
paginator.initTotalPage(); | ||
Assert.assertEquals(0L, paginator.getTotalPage()); | ||
} | ||
|
||
@PrepareForTest({Paginator.class, Math.class}) | ||
@Test | ||
public void getHtmlOutputNotNull() throws Exception, | ||
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 commentThe 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. |
||
paginator.setStep(0); | ||
paginator.setUrl(null); | ||
paginator.setQuery(null); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Reflection |
||
PowerMockito.when(Math.ceil(anyDouble())) | ||
.thenReturn(-0x1.ffffffffffffep+31 /* -4.29497e+09 */); | ||
Assert.assertEquals("", paginator.getHtml()); | ||
} | ||
|
||
@Test | ||
public void getHtmlOutputNotNull2() throws Exception, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Reflection |
||
paginator.setStep(0); | ||
paginator.setUrl(null); | ||
paginator.setQuery("foo"); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Reflection |
||
PowerMockito.when(Math.ceil(anyDouble())) | ||
.thenReturn(-0x1.ffffffffffffep+31 /* -4.29497e+09 */); | ||
Assert.assertEquals("", paginator.getHtml()); | ||
} | ||
} |
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