66package software .amazon .nio .spi .s3 ;
77
88import java .util .NoSuchElementException ;
9- import java .util .function .Consumer ;
109import static org .assertj .core .api .BDDAssertions .then ;
1110import static org .junit .jupiter .api .Assertions .*;
1211import org .junit .jupiter .api .BeforeEach ;
1312import org .junit .jupiter .api .Test ;
1413import org .junit .jupiter .api .extension .ExtendWith ;
15- import static org .mockito .ArgumentMatchers .any ;
1614import org .mockito .InOrder ;
1715import org .mockito .Mock ;
1816import static org .mockito .Mockito .inOrder ;
1917import static org .mockito .Mockito .when ;
18+ import static software .amazon .nio .spi .s3 .S3Matchers .anyConsumer ;
19+
2020import org .mockito .junit .jupiter .MockitoExtension ;
2121import software .amazon .awssdk .awscore .exception .AwsErrorDetails ;
2222import software .amazon .awssdk .http .SdkHttpResponse ;
@@ -59,7 +59,7 @@ public void initialization() {
5959
6060 @ Test
6161 public void testGenerateAsyncClientWithNoErrors () {
62- when (mockClient .getBucketLocation (any ( Consumer . class )))
62+ when (mockClient .getBucketLocation (anyConsumer ( )))
6363 .thenReturn (GetBucketLocationResponse .builder ().locationConstraint ("us-west-2" ).build ());
6464 final S3AsyncClient s3Client = provider .generateAsyncClient ("test-bucket" , mockClient );
6565 assertNotNull (s3Client );
@@ -68,11 +68,11 @@ public void testGenerateAsyncClientWithNoErrors() {
6868 @ Test
6969 public void testGenerateClientWith403Response () {
7070 // when you get a forbidden response from getBucketLocation
71- when (mockClient .getBucketLocation (any ( Consumer . class ))).thenThrow (
71+ when (mockClient .getBucketLocation (anyConsumer ( ))).thenThrow (
7272 S3Exception .builder ().statusCode (403 ).build ()
7373 );
7474 // you should fall back to a head bucket attempt
75- when (mockClient .headBucket (any ( Consumer . class )))
75+ when (mockClient .headBucket (anyConsumer ( )))
7676 .thenReturn ((HeadBucketResponse ) HeadBucketResponse .builder ()
7777 .sdkHttpResponse (SdkHttpResponse .builder ()
7878 .putHeader ("x-amz-bucket-region" , "us-west-2" )
@@ -84,19 +84,19 @@ public void testGenerateClientWith403Response() {
8484 assertNotNull (s3Client );
8585
8686 final InOrder inOrder = inOrder (mockClient );
87- inOrder .verify (mockClient ).getBucketLocation (any ( Consumer . class ));
88- inOrder .verify (mockClient ).headBucket (any ( Consumer . class ));
87+ inOrder .verify (mockClient ).getBucketLocation (anyConsumer ( ));
88+ inOrder .verify (mockClient ).headBucket (anyConsumer ( ));
8989 inOrder .verifyNoMoreInteractions ();
9090 }
9191
9292 @ Test
9393 public void testGenerateAsyncClientWith403Response () {
9494 // when you get a forbidden response from getBucketLocation
95- when (mockClient .getBucketLocation (any ( Consumer . class ))).thenThrow (
95+ when (mockClient .getBucketLocation (anyConsumer ( ))).thenThrow (
9696 S3Exception .builder ().statusCode (403 ).build ()
9797 );
9898 // you should fall back to a head bucket attempt
99- when (mockClient .headBucket (any ( Consumer . class )))
99+ when (mockClient .headBucket (anyConsumer ( )))
100100 .thenReturn ((HeadBucketResponse ) HeadBucketResponse .builder ()
101101 .sdkHttpResponse (SdkHttpResponse .builder ()
102102 .putHeader ("x-amz-bucket-region" , "us-west-2" )
@@ -108,19 +108,19 @@ public void testGenerateAsyncClientWith403Response() {
108108 assertNotNull (s3Client );
109109
110110 final InOrder inOrder = inOrder (mockClient );
111- inOrder .verify (mockClient ).getBucketLocation (any ( Consumer . class ));
112- inOrder .verify (mockClient ).headBucket (any ( Consumer . class ));
111+ inOrder .verify (mockClient ).getBucketLocation (anyConsumer ( ));
112+ inOrder .verify (mockClient ).headBucket (anyConsumer ( ));
113113 inOrder .verifyNoMoreInteractions ();
114114 }
115115
116116 @ Test
117117 public void testGenerateAsyncClientWith403Then301Responses (){
118118 // when you get a forbidden response from getBucketLocation
119- when (mockClient .getBucketLocation (any ( Consumer . class ))).thenThrow (
119+ when (mockClient .getBucketLocation (anyConsumer ( ))).thenThrow (
120120 S3Exception .builder ().statusCode (403 ).build ()
121121 );
122122 // and you get a 301 response on headBucket
123- when (mockClient .headBucket (any ( Consumer . class ))).thenThrow (
123+ when (mockClient .headBucket (anyConsumer ( ))).thenThrow (
124124 S3Exception .builder ()
125125 .statusCode (301 )
126126 .awsErrorDetails (AwsErrorDetails .builder ()
@@ -136,19 +136,19 @@ public void testGenerateAsyncClientWith403Then301Responses(){
136136 assertNotNull (s3Client );
137137
138138 final InOrder inOrder = inOrder (mockClient );
139- inOrder .verify (mockClient ).getBucketLocation (any ( Consumer . class ));
140- inOrder .verify (mockClient ).headBucket (any ( Consumer . class ));
139+ inOrder .verify (mockClient ).getBucketLocation (anyConsumer ( ));
140+ inOrder .verify (mockClient ).headBucket (anyConsumer ( ));
141141 inOrder .verifyNoMoreInteractions ();
142142 }
143143
144144 @ Test
145145 public void testGenerateClientWith403Then301ResponsesNoHeader (){
146146 // when you get a forbidden response from getBucketLocation
147- when (mockClient .getBucketLocation (any ( Consumer . class ))).thenThrow (
147+ when (mockClient .getBucketLocation (anyConsumer ( ))).thenThrow (
148148 S3Exception .builder ().statusCode (403 ).build ()
149149 );
150150 // and you get a 301 response on headBucket but no header for region
151- when (mockClient .headBucket (any ( Consumer . class ))).thenThrow (
151+ when (mockClient .headBucket (anyConsumer ( ))).thenThrow (
152152 S3Exception .builder ()
153153 .statusCode (301 )
154154 .awsErrorDetails (AwsErrorDetails .builder ()
@@ -162,20 +162,20 @@ public void testGenerateClientWith403Then301ResponsesNoHeader(){
162162 assertThrows (NoSuchElementException .class , () -> provider .generateClient ("test-bucket" , mockClient ));
163163
164164 final InOrder inOrder = inOrder (mockClient );
165- inOrder .verify (mockClient ).getBucketLocation (any ( Consumer . class ));
166- inOrder .verify (mockClient ).headBucket (any ( Consumer . class ));
165+ inOrder .verify (mockClient ).getBucketLocation (anyConsumer ( ));
166+ inOrder .verify (mockClient ).headBucket (anyConsumer ( ));
167167 inOrder .verifyNoMoreInteractions ();
168168 }
169169
170170
171171 @ Test
172172 public void testGenerateAsyncClientWith403Then301ResponsesNoHeader (){
173173 // when you get a forbidden response from getBucketLocation
174- when (mockClient .getBucketLocation (any ( Consumer . class ))).thenThrow (
174+ when (mockClient .getBucketLocation (anyConsumer ( ))).thenThrow (
175175 S3Exception .builder ().statusCode (403 ).build ()
176176 );
177177 // and you get a 301 response on headBucket but no header for region
178- when (mockClient .headBucket (any ( Consumer . class ))).thenThrow (
178+ when (mockClient .headBucket (anyConsumer ( ))).thenThrow (
179179 S3Exception .builder ()
180180 .statusCode (301 )
181181 .awsErrorDetails (AwsErrorDetails .builder ()
@@ -189,8 +189,8 @@ public void testGenerateAsyncClientWith403Then301ResponsesNoHeader(){
189189 assertThrows (NoSuchElementException .class , () -> provider .generateAsyncClient ("test-bucket" , mockClient ));
190190
191191 final InOrder inOrder = inOrder (mockClient );
192- inOrder .verify (mockClient ).getBucketLocation (any ( Consumer . class ));
193- inOrder .verify (mockClient ).headBucket (any ( Consumer . class ));
192+ inOrder .verify (mockClient ).getBucketLocation (anyConsumer ( ));
193+ inOrder .verify (mockClient ).headBucket (anyConsumer ( ));
194194 inOrder .verifyNoMoreInteractions ();
195195 }
196196
0 commit comments