55import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
66import static org .junit .jupiter .api .Assertions .assertNotNull ;
77import static org .junit .jupiter .api .Assertions .assertNull ;
8+ import static org .junit .jupiter .api .Assertions .assertThrows ;
89import static org .junit .jupiter .api .Assertions .assertTrue ;
910
1011import java .net .URI ;
@@ -48,6 +49,7 @@ void testBuildCredentialsProviderWithSessionCredentials() {
4849 void testBuildCredentialsProviderWithNoCredentials () {
4950 AWSBaseConfig config = new AWSBaseConfig ();
5051 config .setRegion ("us-east-1" );
52+ config .setEnabled (true );
5153
5254 AwsCredentialsProvider provider = AwsCredentialsUtil .buildCredentialsProvider (config );
5355
@@ -60,6 +62,7 @@ void testBuildCredentialsProviderWithOnlyAccessKey() {
6062 AWSBaseConfig config = new AWSBaseConfig ();
6163 config .setRegion ("us-east-1" );
6264 config .setAccessKeyId ("AKIAIOSFODNN7EXAMPLE" );
65+ config .setEnabled (true );
6366
6467 AwsCredentialsProvider provider = AwsCredentialsUtil .buildCredentialsProvider (config );
6568
@@ -73,6 +76,7 @@ void testBuildCredentialsProviderWithEmptyCredentials() {
7376 config .setRegion ("us-east-1" );
7477 config .setAccessKeyId ("" );
7578 config .setSecretAccessKey ("" );
79+ config .setEnabled (true );
7680
7781 AwsCredentialsProvider provider = AwsCredentialsUtil .buildCredentialsProvider (config );
7882
@@ -180,4 +184,17 @@ void testEndpointUrlConfiguration() {
180184 assertEquals (URI .create ("http://localhost:4566" ), config .getEndpointUrl ());
181185 assertTrue (AwsCredentialsUtil .isAwsConfigured (config ));
182186 }
187+
188+ @ Test
189+ void testBuildCredentialsProviderThrowsWhenNotConfigured () {
190+ AWSBaseConfig config = new AWSBaseConfig ();
191+ config .setRegion ("us-east-1" );
192+
193+ IllegalArgumentException exception =
194+ assertThrows (
195+ IllegalArgumentException .class ,
196+ () -> AwsCredentialsUtil .buildCredentialsProvider (config ));
197+
198+ assertTrue (exception .getMessage ().contains ("AWS credentials not configured" ));
199+ }
183200}
0 commit comments