Skip to content

Commit 9766afe

Browse files
authored
Show xlint warnings and some fixes (#249)
* build: Add Xlint to compiler to output warnings * fix(xlint): Warnings related to any(Consumer.class) * fix(xlint): Unchecked warning in S3NioSpiConfigurationTest
1 parent bf77c9d commit 9766afe

File tree

9 files changed

+63
-44
lines changed

9 files changed

+63
-44
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ java {
3939

4040
tasks.withType(JavaCompile).configureEach {
4141
options.release.set(11)
42+
options.compilerArgs += ['-Xlint:all,-serial']
4243
}
4344

4445
sourceSets {

src/test/java/software/amazon/nio/spi/s3/S3ClientProviderTest.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
package software.amazon.nio.spi.s3;
77

88
import java.util.NoSuchElementException;
9-
import java.util.function.Consumer;
109
import static org.assertj.core.api.BDDAssertions.then;
1110
import static org.junit.jupiter.api.Assertions.*;
1211
import org.junit.jupiter.api.BeforeEach;
1312
import org.junit.jupiter.api.Test;
1413
import org.junit.jupiter.api.extension.ExtendWith;
15-
import static org.mockito.ArgumentMatchers.any;
1614
import org.mockito.InOrder;
1715
import org.mockito.Mock;
1816
import static org.mockito.Mockito.inOrder;
1917
import static org.mockito.Mockito.when;
18+
import static software.amazon.nio.spi.s3.S3Matchers.anyConsumer;
19+
2020
import org.mockito.junit.jupiter.MockitoExtension;
2121
import software.amazon.awssdk.awscore.exception.AwsErrorDetails;
2222
import 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

src/test/java/software/amazon/nio/spi/s3/S3FileSystemProviderTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
import static org.mockito.Mockito.times;
6666
import static org.mockito.Mockito.verify;
6767
import static org.mockito.Mockito.when;
68+
import static software.amazon.nio.spi.s3.S3Matchers.anyConsumer;
69+
6870
import software.amazon.awssdk.services.s3.S3AsyncClient;
6971

7072
@SuppressWarnings("unchecked")
@@ -80,7 +82,7 @@ public class S3FileSystemProviderTest {
8082
@BeforeEach
8183
public void init() {
8284
provider = new S3FileSystemProvider();
83-
lenient().when(mockClient.headObject(any(Consumer.class))).thenReturn(
85+
lenient().when(mockClient.headObject(anyConsumer())).thenReturn(
8486
CompletableFuture.supplyAsync(() -> HeadObjectResponse.builder().contentLength(100L).build()));
8587
fs = provider.getFileSystem(URI.create(pathUri), true);
8688
fs.clientProvider(new FixedS3ClientProvider(mockClient));
@@ -178,7 +180,7 @@ public void newDirectoryStream() throws IOException, ExecutionException, Interru
178180
S3Object object1 = S3Object.builder().key(pathUri+"/key1").build();
179181
S3Object object2 = S3Object.builder().key(pathUri+"/key2").build();
180182

181-
when(mockClient.listObjectsV2Paginator(any(Consumer.class))).thenReturn(new ListObjectsV2Publisher(mockClient,
183+
when(mockClient.listObjectsV2Paginator(anyConsumer())).thenReturn(new ListObjectsV2Publisher(mockClient,
182184
ListObjectsV2Request.builder()
183185
.bucket(fs.bucketName())
184186
.prefix(pathUri + "/")
@@ -204,7 +206,7 @@ public void pathIteratorForPublisher_withPagination() throws IOException {
204206
S3Object object2 = S3Object.builder().key(pathUri+"/key2").build();
205207
S3Object object3 = S3Object.builder().key(pathUri+"/").build();
206208

207-
when(mockClient.listObjectsV2Paginator(any(Consumer.class))).thenReturn(publisher);
209+
when(mockClient.listObjectsV2Paginator(anyConsumer())).thenReturn(publisher);
208210
when(mockClient.listObjectsV2(any(ListObjectsV2Request.class))).thenReturn(CompletableFuture.supplyAsync(() ->
209211
ListObjectsV2Response.builder().contents(object1, object2, object3).build()));
210212

@@ -231,7 +233,7 @@ public void pathIteratorForPublisher_appliesFilter() throws IOException {
231233
S3Object object2 = S3Object.builder().key(pathUri+"/key2").build();
232234
S3Object object3 = S3Object.builder().key(pathUri+"/").build();
233235

234-
when(mockClient.listObjectsV2Paginator(any(Consumer.class))).thenReturn(publisher);
236+
when(mockClient.listObjectsV2Paginator(anyConsumer())).thenReturn(publisher);
235237
when(mockClient.listObjectsV2(any(ListObjectsV2Request.class))).thenReturn(CompletableFuture.supplyAsync(() ->
236238
ListObjectsV2Response.builder().contents(object1, object2, object3).build()));
237239

@@ -270,7 +272,7 @@ public void createDirectory() throws Exception {
270272
public void delete() throws Exception {
271273
S3Object object1 = S3Object.builder().key("dir/key1").build();
272274
S3Object object2 = S3Object.builder().key("dir/subdir/key2").build();
273-
when(mockClient.listObjectsV2(any(Consumer.class))).thenReturn(CompletableFuture.supplyAsync(() ->
275+
when(mockClient.listObjectsV2(anyConsumer())).thenReturn(CompletableFuture.supplyAsync(() ->
274276
ListObjectsV2Response.builder().contents(object1, object2).isTruncated(false).nextContinuationToken(null).build()));
275277
when(mockClient.deleteObjects(any(DeleteObjectsRequest.class))).thenReturn(CompletableFuture.supplyAsync(() ->
276278
DeleteObjectsResponse.builder().build()));
@@ -291,7 +293,7 @@ public void delete() throws Exception {
291293
public void copy() throws Exception {
292294
S3Object object1 = S3Object.builder().key("dir1/key1").build();
293295
S3Object object2 = S3Object.builder().key("dir1/subdir/key2").build();
294-
when(mockClient.listObjectsV2(any(Consumer.class))).thenReturn(CompletableFuture.supplyAsync(() ->
296+
when(mockClient.listObjectsV2(anyConsumer())).thenReturn(CompletableFuture.supplyAsync(() ->
295297
ListObjectsV2Response.builder().contents(object1, object2).isTruncated(false).nextContinuationToken(null).build()));
296298
HeadObjectRequest headObjectRequest1 = HeadObjectRequest.builder().bucket("foo").key("dir2/key1").build();
297299
when(mockClient.headObject(headObjectRequest1)).thenReturn(CompletableFuture.supplyAsync(() ->
@@ -321,7 +323,7 @@ public void copy() throws Exception {
321323
public void move() throws Exception {
322324
S3Object object1 = S3Object.builder().key("dir1/key1").build();
323325
S3Object object2 = S3Object.builder().key("dir1/subdir/key2").build();
324-
when(mockClient.listObjectsV2(any(Consumer.class))).thenReturn(CompletableFuture.supplyAsync(() ->
326+
when(mockClient.listObjectsV2(anyConsumer())).thenReturn(CompletableFuture.supplyAsync(() ->
325327
ListObjectsV2Response.builder().contents(object1, object2).isTruncated(false).nextContinuationToken(null).build()));
326328
HeadObjectRequest headObjectRequest1 = HeadObjectRequest.builder().bucket("foo").key("dir2/key1").build();
327329
when(mockClient.headObject(headObjectRequest1)).thenReturn(CompletableFuture.supplyAsync(() ->
@@ -459,7 +461,7 @@ public void testReadAttributes() {
459461
Path foo = fs.getPath("/foo");
460462
Path fooDir = fs.getPath("/foo/");
461463

462-
when(mockClient.headObject(any(Consumer.class))).thenReturn(CompletableFuture.completedFuture(
464+
when(mockClient.headObject(anyConsumer())).thenReturn(CompletableFuture.completedFuture(
463465
HeadObjectResponse.builder()
464466
.lastModified(Instant.EPOCH)
465467
.contentLength(100L)

src/test/java/software/amazon/nio/spi/s3/S3FileSystemTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.Collections;
1616
import java.util.Iterator;
1717
import java.util.concurrent.CompletableFuture;
18-
import java.util.function.Consumer;
1918

2019
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2120
import static org.assertj.core.api.BDDAssertions.then;
@@ -24,10 +23,10 @@
2423
import org.junit.jupiter.api.BeforeEach;
2524
import org.junit.jupiter.api.Test;
2625
import org.junit.jupiter.api.extension.ExtendWith;
27-
import static org.mockito.ArgumentMatchers.any;
2826
import org.mockito.Mock;
2927
import static org.mockito.Mockito.lenient;
3028
import static software.amazon.nio.spi.s3.Constants.PATH_SEPARATOR;
29+
import static software.amazon.nio.spi.s3.S3Matchers.anyConsumer;
3130

3231
import org.mockito.junit.jupiter.MockitoExtension;
3332
import software.amazon.awssdk.core.exception.SdkClientException;
@@ -48,7 +47,7 @@ public void init() {
4847
provider = new S3FileSystemProvider();
4948
s3FileSystem = provider.getFileSystem(s3Uri, true);
5049
s3FileSystem.clientProvider = new FixedS3ClientProvider(mockClient);
51-
lenient().when(mockClient.headObject(any(Consumer.class))).thenReturn(
50+
lenient().when(mockClient.headObject(anyConsumer())).thenReturn(
5251
CompletableFuture.supplyAsync(() -> HeadObjectResponse.builder().contentLength(100L).build()));
5352
}
5453

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package software.amazon.nio.spi.s3;
2+
3+
import org.mockito.ArgumentMatchers;
4+
5+
import java.util.function.Consumer;
6+
7+
public class S3Matchers {
8+
public static <T> Consumer<T> anyConsumer() {
9+
return ArgumentMatchers.any();
10+
}
11+
}

src/test/java/software/amazon/nio/spi/s3/S3PathTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313
import java.util.ArrayList;
1414
import java.util.List;
1515
import java.util.concurrent.CompletableFuture;
16-
import java.util.function.Consumer;
1716
import org.junit.jupiter.api.AfterEach;
1817

1918
import static org.assertj.core.api.BDDAssertions.then;
2019
import static org.junit.jupiter.api.Assertions.*;
2120
import org.junit.jupiter.api.BeforeEach;
2221
import org.junit.jupiter.api.Test;
2322
import org.junit.jupiter.api.extension.ExtendWith;
24-
import static org.mockito.ArgumentMatchers.any;
2523
import org.mockito.Mock;
2624
import static org.mockito.Mockito.lenient;
2725
import static software.amazon.nio.spi.s3.Constants.PATH_SEPARATOR;
26+
import static software.amazon.nio.spi.s3.S3Matchers.anyConsumer;
2827

2928
import org.mockito.junit.jupiter.MockitoExtension;
3029
import software.amazon.awssdk.services.s3.S3AsyncClient;
@@ -50,7 +49,7 @@ public class S3PathTest {
5049
public void init(){
5150
fileSystem = provider.getFileSystem(URI.create(uriString), true);
5251
fileSystem.clientProvider(new FixedS3ClientProvider(mockClient));
53-
lenient().when(mockClient.headObject(any(Consumer.class))).thenReturn(
52+
lenient().when(mockClient.headObject(anyConsumer())).thenReturn(
5453
CompletableFuture.supplyAsync(() -> HeadObjectResponse.builder().contentLength(100L).build()));
5554

5655
root = S3Path.getPath(fileSystem, PATH_SEPARATOR);

src/test/java/software/amazon/nio/spi/s3/S3ReadAheadByteChannelTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.nio.ByteBuffer;
1717
import java.nio.charset.StandardCharsets;
1818
import java.util.concurrent.CompletableFuture;
19-
import java.util.function.Consumer;
2019
import static org.junit.jupiter.api.Assertions.*;
2120
import org.junit.jupiter.api.BeforeEach;
2221
import org.junit.jupiter.api.Test;
@@ -25,6 +24,8 @@
2524
import static org.mockito.ArgumentMatchers.any;
2625
import static org.mockito.Mockito.lenient;
2726
import static org.mockito.Mockito.when;
27+
import static software.amazon.nio.spi.s3.S3Matchers.anyConsumer;
28+
2829
import org.mockito.junit.jupiter.MockitoExtension;
2930

3031
@ExtendWith(MockitoExtension.class)
@@ -54,7 +55,7 @@ public void setup() throws IOException {
5455
final GetObjectResponse response = GetObjectResponse.builder().build();
5556
final ResponseBytes<GetObjectResponse> bytes1 = ResponseBytes.fromByteArray(response, "abcdefghijklmnopqrstuvwxyz".getBytes(StandardCharsets.UTF_8));
5657
final ResponseBytes<GetObjectResponse> bytes2 = ResponseBytes.fromByteArray(response, "ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes(StandardCharsets.UTF_8));
57-
lenient().when(client.getObject(any(Consumer.class), any(ByteArrayAsyncResponseTransformer.class))).thenReturn(CompletableFuture.supplyAsync(() -> bytes1), CompletableFuture.supplyAsync(() -> bytes2));
58+
lenient().when(client.getObject(anyConsumer(), any(ByteArrayAsyncResponseTransformer.class))).thenReturn(CompletableFuture.supplyAsync(() -> bytes1), CompletableFuture.supplyAsync(() -> bytes2));
5859

5960
readAheadByteChannel = new S3ReadAheadByteChannel(path, 26, 2, client, delegator, null, null);
6061
}

src/test/java/software/amazon/nio/spi/s3/S3SeekableByteChannelTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.HashSet;
2323
import java.util.Set;
2424
import java.util.concurrent.CompletableFuture;
25-
import java.util.function.Consumer;
2625
import org.junit.jupiter.api.AfterEach;
2726
import static org.junit.jupiter.api.Assertions.*;
2827
import org.junit.jupiter.api.BeforeEach;
@@ -32,6 +31,8 @@
3231
import static org.mockito.Mockito.any;
3332
import static org.mockito.Mockito.lenient;
3433
import static org.mockito.Mockito.when;
34+
import static software.amazon.nio.spi.s3.S3Matchers.anyConsumer;
35+
3536
import org.mockito.junit.jupiter.MockitoExtension;
3637

3738
@ExtendWith(MockitoExtension.class)
@@ -48,10 +49,10 @@ public class S3SeekableByteChannelTest {
4849
@BeforeEach
4950
public void init() {
5051
// forward to the method that uses the HeadObjectRequest parameter
51-
lenient().when(mockClient.headObject(any(Consumer.class))).thenCallRealMethod();
52+
lenient().when(mockClient.headObject(anyConsumer())).thenCallRealMethod();
5253
lenient().when(mockClient.headObject(any(HeadObjectRequest.class))).thenReturn(
5354
CompletableFuture.supplyAsync(() -> HeadObjectResponse.builder().contentLength(100L).build()));
54-
lenient().when(mockClient.getObject(any(Consumer.class), any(AsyncResponseTransformer.class))).thenCallRealMethod();
55+
lenient().when(mockClient.getObject(anyConsumer(), any(AsyncResponseTransformer.class))).thenCallRealMethod();
5556
lenient().when(mockClient.getObject(any(GetObjectRequest.class), any(AsyncResponseTransformer.class))).thenReturn(
5657
CompletableFuture.supplyAsync(() -> ResponseBytes.fromByteArray(
5758
GetObjectResponse.builder().contentLength(6L).build(),

0 commit comments

Comments
 (0)