add powermock
parent
1266ef7db5
commit
64210c469f
|
@ -3,7 +3,9 @@ package me.ehlxr.powermock;
|
|||
/**
|
||||
* Created by lixiangrong on 2017/11/3.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/7/21.
|
||||
*/
|
||||
|
@ -11,34 +13,43 @@ public class ClassUnderTest {
|
|||
public boolean callArgumentInstance(File file) {
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
public boolean callInternalInstance(String path) {
|
||||
File file = new File(path);
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
public boolean callFinalMethod(ClassDependency refer) {
|
||||
return refer.isAlive();
|
||||
}
|
||||
|
||||
public boolean callSystemFinalMethod(String str) {
|
||||
return str.isEmpty();
|
||||
}
|
||||
|
||||
public boolean callStaticMethod() {
|
||||
return ClassDependency.isExist();
|
||||
}
|
||||
|
||||
public String callSystemStaticMethod(String str) {
|
||||
return System.getProperty(str);
|
||||
}
|
||||
|
||||
public boolean callPrivateMethod() {
|
||||
return isExist();
|
||||
}
|
||||
public boolean callVoidPrivateMethod(){
|
||||
|
||||
public boolean callVoidPrivateMethod() {
|
||||
testVoid();
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isExist() {
|
||||
// do something
|
||||
return false;
|
||||
}
|
||||
private void testVoid(){
|
||||
|
||||
private void testVoid() {
|
||||
System.out.println("do nothing");
|
||||
}
|
||||
}
|
|
@ -9,8 +9,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/7/21.
|
||||
*/
|
||||
|
@ -75,7 +73,7 @@ public class TestClassUnderTest {
|
|||
public void testCallPrivateMethod() throws Exception {
|
||||
ClassUnderTest underTest = PowerMockito.mock(ClassUnderTest.class);
|
||||
PowerMockito.when(underTest.callPrivateMethod()).thenCallRealMethod();
|
||||
PowerMockito.when(underTest, "isExist", anyString()).thenReturn(true);
|
||||
PowerMockito.when(underTest, "isExist").thenReturn(true);
|
||||
Assert.assertTrue(underTest.callPrivateMethod());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue