2727import java .security .GeneralSecurityException ;
2828import java .util .Arrays ;
2929import java .util .List ;
30- import org .junit .jupiter .api .AfterEach ;
31- import org .junit .jupiter .api .AfterAll ;
32- import org .junit .jupiter .api .BeforeEach ;
33- import org .junit .jupiter .api .BeforeAll ;
34- import org .junit .jupiter .api .Test ;
30+ import org .junit .After ;
31+ import org .junit .AfterClass ;
32+ import org .junit .Before ;
33+ import org .junit .BeforeClass ;
34+ import org .junit .Test ;
35+ import org .junit .runner .RunWith ;
36+ import org .junit .runners .JUnit4 ;
3537
36- class SnippetsIT {
38+ @ RunWith (JUnit4 .class )
39+ public class SnippetsIT {
3740
3841 private static final String PROJECT_ID = System .getenv ("GOOGLE_CLOUD_PROJECT" );
3942 private static final String CREDENTIALS = System .getenv ("GOOGLE_APPLICATION_CREDENTIALS" );
4043 private ByteArrayOutputStream stdOut ;
4144
4245 // Check if the required environment variables are set.
43- static void requireEnvVar (String envVarName ) {
46+ public static void requireEnvVar (String envVarName ) {
4447 assertWithMessage (String .format ("Missing environment variable '%s' " , envVarName ))
4548 .that (System .getenv (envVarName ))
4649 .isNotEmpty ();
4750 }
4851
49- @ BeforeAll
50- static void setup () throws IOException {
52+ @ BeforeClass
53+ public static void setup () throws IOException {
5154 final PrintStream out = System .out ;
5255 ByteArrayOutputStream stdOut = new ByteArrayOutputStream ();
5356 System .setOut (new PrintStream (stdOut ));
@@ -58,17 +61,17 @@ static void setup() throws IOException {
5861 System .setOut (out );
5962 }
6063
61- @ AfterAll
62- static void cleanup () {}
64+ @ AfterClass
65+ public static void cleanup () {}
6366
64- @ BeforeEach
65- void beforeEach () {
67+ @ Before
68+ public void beforeEach () {
6669 stdOut = new ByteArrayOutputStream ();
6770 System .setOut (new PrintStream (stdOut ));
6871 }
6972
70- @ AfterEach
71- void afterEach () {
73+ @ After
74+ public void afterEach () {
7275 stdOut = null ;
7376 System .setOut (null );
7477 }
@@ -91,33 +94,33 @@ private static String getIdTokenFromServiceAccount(
9194 }
9295
9396 @ Test
94- void testIdTokenFromServiceAccount () throws IOException {
97+ public void testIdTokenFromServiceAccount () throws IOException {
9598 IdTokenFromServiceAccount .getIdTokenFromServiceAccount (CREDENTIALS , "https://example.com" );
9699 assertThat (stdOut .toString ()).contains ("Generated ID token." );
97100 }
98101
99102 @ Test
100- void testVerifyGoogleIdToken () throws IOException {
103+ public void testVerifyGoogleIdToken () throws IOException {
101104 String idToken = getIdTokenFromServiceAccount (CREDENTIALS , "https://example.com" );
102105
103106 VerifyGoogleIdToken .verifyGoogleIdToken (
104107 idToken , "https://example.com" , "https://www.googleapis.com/oauth2/v3/certs" );
105108 }
106109
107110 @ Test
108- void testIdTokenFromMetadataServer () throws GeneralSecurityException , IOException {
111+ public void testIdTokenFromMetadataServer () throws GeneralSecurityException , IOException {
109112 IdTokenFromMetadataServer .getIdTokenFromMetadataServer ("https://www.google.com" );
110113 assertThat (stdOut .toString ()).contains ("Generated ID token." );
111114 }
112115
113116 @ Test
114- void testAuthenticateImplicitWithAdc () throws IOException {
117+ public void testAuthenticateImplicitWithAdc () throws IOException {
115118 AuthenticateImplicitWithAdc .authenticateImplicitWithAdc (PROJECT_ID );
116119 assertThat (stdOut .toString ()).contains ("Listed all storage buckets." );
117120 }
118121
119122 @ Test
120- void testAuthenticateExplicit () throws IOException {
123+ public void testAuthenticateExplicit () throws IOException {
121124 AuthenticateExplicit .authenticateExplicit (PROJECT_ID );
122125 assertThat (stdOut .toString ()).contains ("Listed all storage buckets." );
123126 }
0 commit comments