-
Notifications
You must be signed in to change notification settings - Fork 831
/
Copy pathShellCommandTest.java
executable file
·52 lines (40 loc) · 1.77 KB
/
ShellCommandTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.github.hiteshsondhi88.libffmpeg;
import com.github.hiteshsondhi88.libffmpeg.utils.AssertionHelper;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.assertj.core.api.Assertions.assertThat;
public class ShellCommandTest extends CommonTestCase {
public void testRun() throws Exception {
ShellCommand shellCommand = new ShellCommand();
final Process process = shellCommand.run(new String[] {"logcat"});
assertNotNull(process);
assertEquals(false, Util.isProcessCompleted(process));
Util.destroyProcess(process);
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<?> future = executor.submit(new Runnable() {
@Override
public void run() {
String errorStream = Util.convertInputStreamToString(process.getErrorStream());
String inputStream = Util.convertInputStreamToString(process.getInputStream());
assertEquals(null, errorStream);
assertEquals(null, inputStream);
}
});
try {
future.get(1, TimeUnit.SECONDS);
} catch (TimeoutException e) {
AssertionHelper.assertError("could not destroy process");
}
executor.shutdownNow();
}
public void testRunWaitFor() throws Exception {
ShellCommand shellCommand = new ShellCommand();
CommandResult commandResult = shellCommand.runWaitFor(new String[] {"ls"});
assertNotNull(commandResult);
assertEquals(true, commandResult.success);
assertThat(commandResult.output).isNotEmpty();
}
}