add powermock

dev
ehlxr 2017-11-03 14:29:04 +08:00
parent 1266ef7db5
commit 64210c469f
2 changed files with 14 additions and 5 deletions

View File

@ -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");
}
}

View File

@ -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());
}