### Question:
GcpStorageRepository implements StorageRepository { @Override public SignedObject createSignedObject(String bucketName, String filepath) { log.debug("Creating the signed blob in bucket {} for path {}", bucketName, filepath); BlobId blobId = BlobId.of(bucketName, filepath); BlobInfo blobInfo = BlobInfo.newBuilder(blobId) .setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE) .build(); Blob blob = storage.create(blobInfo, ArrayUtils.EMPTY_BYTE_ARRAY); URL signedUrl = storage.signUrl(blobInfo, 7L, TimeUnit.DAYS, SignUrlOption.httpMethod(HttpMethod.PUT), SignUrlOption.withV4Signature()); log.debug("Signed URL for created storage object. Object ID : {} , Signed URL : {}", blob.getGeneratedId(), signedUrl); return SignedObject.builder() .uri(getObjectUri(blob)) .url(signedUrl) .build(); }  @Override SignedObject createSignedObject(String bucketName, String filepath);  }### Answer:
@Test void shouldCreateSignedObject() { Storage storage = spyLocalStorage(TestCredential.getSa()); StorageRepository storageRepository = new GcpStorageRepository(storage); SignedObject signedObject = storageRepository.createSignedObject(BUCKET_NAME, FILEPATH); then(signedObject).isNotNull(); verify(storage).create(any(BlobInfo.class), contentCaptor.capture()); verify(storage).signUrl(any(BlobInfo.class), eq(7L), eq(TimeUnit.DAYS), optionsCaptor.capture()); then(contentCaptor.getValue()).isEmpty(); then(optionsCaptor.getAllValues()) .extracting("option", "value") .extracting(toStringMethod()) .containsExactly( "(HTTP_METHOD, PUT)", "(SIGNATURE_VERSION, V4)"); }
@Test void shouldThrowExceptionWhenCallerIsNotSigner () { Storage storage = spyLocalStorage(TestCredential.getUserCredentials()); StorageRepository storageRepository = new GcpStorageRepository(storage); Throwable thrown = catchThrowable(() -> storageRepository.createSignedObject(BUCKET_NAME, FILEPATH)); then(thrown) .isInstanceOf(IllegalStateException.class) .hasMessage("Signing key was not provided and could not be derived"); verify(storage).create(any(BlobInfo.class), any(byte[].class)); verify(storage).signUrl(any(BlobInfo.class), eq(7L), eq(TimeUnit.DAYS), any(SignUrlOption.class), any(SignUrlOption.class)); }