19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static junit .framework .TestCase .assertNotNull ;
21
21
22
+ import com .google .cloud .testing .junit4 .MultipleAttemptsRule ;
22
23
import java .io .ByteArrayOutputStream ;
23
24
import java .io .IOException ;
24
25
import java .io .PrintStream ;
27
28
import org .junit .After ;
28
29
import org .junit .Before ;
29
30
import org .junit .BeforeClass ;
31
+ import org .junit .Rule ;
30
32
import org .junit .Test ;
31
33
import org .junit .runner .RunWith ;
32
34
import org .junit .runners .JUnit4 ;
@@ -39,7 +41,7 @@ public class TranslateCreateDatasetTest {
39
41
private ByteArrayOutputStream bout ;
40
42
private PrintStream out ;
41
43
private PrintStream originalPrintStream ;
42
- private String datasetId ;
44
+ private String got ;
43
45
44
46
private static void requireEnvVar (String varName ) {
45
47
assertNotNull (
@@ -63,11 +65,15 @@ public void setUp() {
63
65
64
66
@ After
65
67
public void tearDown () throws InterruptedException , ExecutionException , IOException {
68
+ String datasetId = got .split ("Dataset id: " )[1 ].split ("\n " )[0 ];
69
+
66
70
// Delete the created dataset
67
71
DeleteDataset .deleteDataset (PROJECT_ID , datasetId );
68
72
System .setOut (originalPrintStream );
69
73
}
70
74
75
+ @ Rule public MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule (3 );
76
+
71
77
@ Test
72
78
public void testCreateDataset () throws IOException , ExecutionException , InterruptedException {
73
79
// Create a random dataset name with a length of 32 characters (max allowed by AutoML)
@@ -77,8 +83,7 @@ public void testCreateDataset() throws IOException, ExecutionException, Interrup
77
83
String .format ("test_%s" , UUID .randomUUID ().toString ().replace ("-" , "_" ).substring (0 , 26 ));
78
84
TranslateCreateDataset .createDataset (PROJECT_ID , datasetName );
79
85
80
- String got = bout .toString ();
86
+ got = bout .toString ();
81
87
assertThat (got ).contains ("Dataset id:" );
82
- datasetId = got .split ("Dataset id: " )[1 ].split ("\n " )[0 ];
83
88
}
84
89
}
0 commit comments