11package com .github .hiteshsondhi88 .libffmpeg ;
22
3+ import com .github .hiteshsondhi88 .libffmpeg .utils .AssertionHelper ;
4+
5+ import java .util .concurrent .ExecutorService ;
6+ import java .util .concurrent .Executors ;
7+ import java .util .concurrent .Future ;
8+ import java .util .concurrent .TimeUnit ;
9+ import java .util .concurrent .TimeoutException ;
10+
11+ import static org .assertj .core .api .Assertions .assertThat ;
12+
313public class ShellCommandTest extends CommonTestCase {
414
515 public void testRun () throws Exception {
6- // TODO
16+ ShellCommand shellCommand = new ShellCommand ();
17+ final Process process = shellCommand .run ("logcat" );
18+ assertNotNull (process );
19+ assertEquals (false , Util .isProcessCompleted (process ));
20+
21+ Util .destroyProcess (process );
22+
23+ ExecutorService executor = Executors .newSingleThreadExecutor ();
24+
25+ Future <?> future = executor .submit (new Runnable () {
26+ @ Override
27+ public void run () {
28+ String errorStream = Util .convertInputStreamToString (process .getErrorStream ());
29+ String inputStream = Util .convertInputStreamToString (process .getInputStream ());
30+
31+ assertEquals (null , errorStream );
32+ assertEquals (null , inputStream );
33+ }
34+ });
35+
36+ try {
37+ future .get (1 , TimeUnit .SECONDS );
38+ } catch (TimeoutException e ) {
39+ AssertionHelper .assertError ("could not destroy process" );
40+ }
41+
42+ executor .shutdownNow ();
743 }
844
945 public void testRunWaitFor () throws Exception {
10- // TODO
46+ ShellCommand shellCommand = new ShellCommand ();
47+ CommandResult commandResult = shellCommand .runWaitFor ("ls /sdcard/" );
48+ assertNotNull (commandResult );
49+ assertEquals (true , commandResult .success );
50+ assertThat (commandResult .output ).isNotEmpty ();
1151 }
1252}
0 commit comments