18
18
19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static org .junit .Assert .assertEquals ;
21
+ import static org .junit .Assert .assertNotNull ;
21
22
import static org .junit .Assert .assertTrue ;
22
23
23
24
import com .google .api .gax .rpc .NotFoundException ;
24
25
import com .google .cloud .modelarmor .v1 .Template ;
25
26
import com .google .cloud .modelarmor .v1 .TemplateName ;
26
- import com .google .common .base .Strings ;
27
27
import java .io .ByteArrayOutputStream ;
28
28
import java .io .IOException ;
29
29
import java .io .PrintStream ;
30
30
import java .util .Random ;
31
31
import org .junit .After ;
32
32
import org .junit .AfterClass ;
33
- import org .junit .Assert ;
34
33
import org .junit .Before ;
35
34
import org .junit .BeforeClass ;
36
35
import org .junit .Test ;
@@ -47,16 +46,24 @@ public class SnippetsIT {
47
46
private static String TEST_TEMPLATE_NAME ;
48
47
private ByteArrayOutputStream stdOut ;
49
48
49
+ // Check if the required environment variables are set.
50
+ private static String requireEnvVar (String varName ) {
51
+ String value = System .getenv (varName );
52
+ assertNotNull ("Environment variable " + varName + " is required to run these tests." ,
53
+ System .getenv (varName ));
54
+ return value ;
55
+ }
56
+
50
57
@ BeforeClass
51
- public static void beforeAll () throws IOException {
52
- Assert . assertFalse ( "missing GOOGLE_CLOUD_PROJECT", Strings . isNullOrEmpty ( PROJECT_ID ) );
53
- Assert . assertFalse ( "missing GOOGLE_CLOUD_PROJECT_LOCATION", Strings . isNullOrEmpty ( LOCATION_ID ) );
58
+ public static void beforeAll () {
59
+ requireEnvVar ( " GOOGLE_CLOUD_PROJECT" );
60
+ requireEnvVar ( " GOOGLE_CLOUD_PROJECT_LOCATION" );
54
61
}
55
62
56
63
@ AfterClass
57
64
public static void afterAll () throws IOException {
58
- Assert . assertFalse ( "missing GOOGLE_CLOUD_PROJECT", Strings . isNullOrEmpty ( PROJECT_ID ) );
59
- Assert . assertFalse ( "missing GOOGLE_CLOUD_PROJECT_LOCATION", Strings . isNullOrEmpty ( LOCATION_ID ) );
65
+ requireEnvVar ( " GOOGLE_CLOUD_PROJECT" );
66
+ requireEnvVar ( " GOOGLE_CLOUD_PROJECT_LOCATION" );
60
67
}
61
68
62
69
@ Before
0 commit comments