Code review comment: Didn't touch these lines but I'll dedupe.

Code before review:
public void setUp() throws IOException {
this.mockGcsUtil = mock(GcsUtil.class);
when(mockGcsUtil.create(any(GcsPath.class), anyString()))
.then(
new Answer<SeekableByteChannel>() {
@Override
public SeekableByteChannel answer(InvocationOnMock invocation) throws Throwable {
return FileChannel.open(
Files.createTempFile("channel-", ".tmp"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.DELETE_ON_CLOSE);
}
});
when(mockGcsUtil.create(any(GcsPath.class), anyString(), anyInt()))
.then(
new Answer<SeekableByteChannel>() {
@Override
public SeekableByteChannel answer(InvocationOnMock invocation) throws Throwable {
return FileChannel.open(
Files.createTempFile("channel-", ".tmp"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.DELETE_ON_CLOSE);
}
});
when(mockGcsUtil.expand(any(GcsPath.class))).then(new Answer<List<GcsPath>>() {
@Override
public List<GcsPath> answer(InvocationOnMock invocation) throws Throwable {
return ImmutableList.of((GcsPath) invocation.getArguments()[0]);
}
});
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_STAGING_BUCKET))).thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_STAGING_BUCKET))).thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_TEMP_BUCKET))).thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_TEMP_BUCKET + "/staging/"))).
thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_PROFILE_BUCKET))).thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(NON_EXISTENT_BUCKET))).thenReturn(false);
when(mockGcsUtil.getObjects(anyListOf(GcsPath.class)))
.thenAnswer(
new Answer<List<GcsUtil.StorageObjectOrIOException>>() {
@Override
public List<GcsUtil.StorageObjectOrIOException> answer(
InvocationOnMock invocationOnMock) throws Throwable {
List<GcsPath> gcsPaths = (List<GcsPath>) invocationOnMock.getArguments()[0];
List<GcsUtil.StorageObjectOrIOException> results = new ArrayList<>();
for (GcsPath gcsPath : gcsPaths) {
if (gcsPath.getBucket().equals(VALID_BUCKET)) {
StorageObject resultObject = new StorageObject();
resultObject.setBucket(gcsPath.getBucket());
resultObject.setName(gcsPath.getObject());
results.add(GcsUtil.StorageObjectOrIOException.create(resultObject));
}
}
return results;
}
});
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri("gs:
mockJobs = mock(Dataflow.Projects.Locations.Jobs.class);
}

Line under review: new Answer<List<GcsUtil.StorageObjectOrIOException>>() {

Code after addressing the review:
public void setUp() throws IOException {
this.mockGcsUtil = mock(GcsUtil.class);
when(mockGcsUtil.create(any(GcsPath.class), anyString()))
.then(
new Answer<SeekableByteChannel>() {
@Override
public SeekableByteChannel answer(InvocationOnMock invocation) throws Throwable {
return FileChannel.open(
Files.createTempFile("channel-", ".tmp"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.DELETE_ON_CLOSE);
}
});
when(mockGcsUtil.create(any(GcsPath.class), anyString(), anyInt()))
.then(
new Answer<SeekableByteChannel>() {
@Override
public SeekableByteChannel answer(InvocationOnMock invocation) throws Throwable {
return FileChannel.open(
Files.createTempFile("channel-", ".tmp"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.DELETE_ON_CLOSE);
}
});
when(mockGcsUtil.expand(any(GcsPath.class))).then(new Answer<List<GcsPath>>() {
@Override
public List<GcsPath> answer(InvocationOnMock invocation) throws Throwable {
return ImmutableList.of((GcsPath) invocation.getArguments()[0]);
}
});
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_STAGING_BUCKET))).thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_TEMP_BUCKET))).thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_TEMP_BUCKET + "/staging/"))).
thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(VALID_PROFILE_BUCKET))).thenReturn(true);
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri(NON_EXISTENT_BUCKET))).thenReturn(false);
when(mockGcsUtil.getObjects(anyListOf(GcsPath.class)))
.thenAnswer(
new Answer<List<GcsUtil.StorageObjectOrIOException>>() {
@Override
public List<GcsUtil.StorageObjectOrIOException> answer(
InvocationOnMock invocationOnMock) throws Throwable {
List<GcsPath> gcsPaths = (List<GcsPath>) invocationOnMock.getArguments()[0];
List<GcsUtil.StorageObjectOrIOException> results = new ArrayList<>();
for (GcsPath gcsPath : gcsPaths) {
if (gcsPath.getBucket().equals(VALID_BUCKET)) {
StorageObject resultObject = new StorageObject();
resultObject.setBucket(gcsPath.getBucket());
resultObject.setName(gcsPath.getObject());
results.add(GcsUtil.StorageObjectOrIOException.create(resultObject));
}
}
return results;
}
});
when(mockGcsUtil.bucketAccessible(GcsPath.fromUri("gs:
mockJobs = mock(Dataflow.Projects.Locations.Jobs.class);
}