28
28
import com .google .cloud .storage .BucketInfo ;
29
29
import com .google .cloud .storage .Storage ;
30
30
import com .google .cloud .storage .StorageOptions ;
31
+ import com .google .cloud .testing .junit4 .StdOutCaptureRule ;
31
32
import com .google .protobuf .Empty ;
32
- import java .io .ByteArrayOutputStream ;
33
33
import java .io .IOException ;
34
- import java .io .PrintStream ;
35
34
import java .util .UUID ;
36
35
import java .util .concurrent .ExecutionException ;
37
36
import org .hamcrest .CoreMatchers ;
38
37
import org .junit .After ;
39
38
import org .junit .Before ;
40
39
import org .junit .BeforeClass ;
40
+ import org .junit .Rule ;
41
41
import org .junit .Test ;
42
42
import org .junit .runner .RunWith ;
43
43
import org .junit .runners .JUnit4 ;
@@ -60,7 +60,8 @@ public class QuickstartTest {
60
60
+ "rdd = sc.parallelize((1,2,3,4,5))\n "
61
61
+ "sum = rdd.reduce(lambda x, y: x + y)\n " ;
62
62
63
- private ByteArrayOutputStream bout ;
63
+ @ Rule
64
+ public StdOutCaptureRule stdOutCapture = new StdOutCaptureRule ();
64
65
private Bucket bucket ;
65
66
private Blob blob ;
66
67
@@ -78,9 +79,6 @@ public static void checkRequirements() {
78
79
79
80
@ Before
80
81
public void setUp () {
81
- bout = new ByteArrayOutputStream ();
82
- System .setOut (new PrintStream (bout ));
83
-
84
82
Storage storage = StorageOptions .getDefaultInstance ().getService ();
85
83
bucket = storage .create (BucketInfo .of (BUCKET_NAME ));
86
84
blob = bucket .create (JOB_FILE_NAME , SORT_CODE .getBytes (UTF_8 ), "text/plain" );
@@ -89,7 +87,7 @@ public void setUp() {
89
87
@ Test
90
88
public void quickstartTest () throws IOException , InterruptedException {
91
89
Quickstart .main (PROJECT_ID , REGION , CLUSTER_NAME , JOB_FILE_PATH );
92
- String output = bout . toString ();
90
+ String output = stdOutCapture . getCapturedOutputAsUtf8String ();
93
91
94
92
assertThat (output , CoreMatchers .containsString ("Cluster created successfully" ));
95
93
assertThat (output , CoreMatchers .containsString ("Job finished successfully:" ));
0 commit comments