62,614
社区成员
发帖
与我相关
我的任务
分享
package Test.ProcessTest;
import java.io.IOException;
public class ProcessUtils {
public static int execute(String... command) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectErrorStream(true);
Process p = pb.start();
p.waitFor();
return p.exitValue();
}
}
package Test.ProcessTest;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import mockit.Mock;
import mockit.MockUp;
public class ProcessUtilsTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Test
public void executeTest() throws IOException, InterruptedException {
new MockUp<Process>() {
@Mock
public int exitValue() {
return 999;
}
};
int re = ProcessUtils.execute("ping", "localhsot");
System.out.println("ExitValue : " + re);
}
}
ExitValue : 1