Skip to content

Commit

Permalink
Rename get with throwable
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 23, 2024
1 parent b2b70a1 commit d9f196e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private Optional<Bytes32> getFromStorage() {
}
}

public Optional<Bytes32> getWithThrowable() throws Throwable {
public Optional<Bytes32> getUnsafe() throws Throwable {
return storageProvider.get().or(defaultProvider::get);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,27 @@ public void get_shouldDelegateToDefaultProviderWhenStorageProviderFails() throws
@Test
void getWithThrowable_shouldGetStorageGraffitiWhenAvailable() throws Throwable {
provider = new UpdatableGraffitiProvider(() -> Optional.of(storageGraffiti), Optional::empty);
assertThat(provider.getWithThrowable()).hasValue(storageGraffiti);
assertThat(provider.getUnsafe()).hasValue(storageGraffiti);
}

@Test
void getWithThrowable_shouldGetStorageGraffitiWhenBothAvailable() throws Throwable {
provider =
new UpdatableGraffitiProvider(
() -> Optional.of(storageGraffiti), () -> Optional.of(defaultGraffiti));
assertThat(provider.getWithThrowable()).hasValue(storageGraffiti);
assertThat(provider.getUnsafe()).hasValue(storageGraffiti);
}

@Test
void getWithThrowable_shouldGetDefaultGraffitiWhenStorageEmpty() throws Throwable {
provider = new UpdatableGraffitiProvider(Optional::empty, () -> Optional.of(defaultGraffiti));
assertThat(provider.getWithThrowable()).hasValue(defaultGraffiti);
assertThat(provider.getUnsafe()).hasValue(defaultGraffiti);
}

@Test
void getWithThrowable_shouldBeEmptyWhenBothEmpty() throws Throwable {
provider = new UpdatableGraffitiProvider(Optional::empty, Optional::empty);
assertThat(provider.getWithThrowable()).isEmpty();
assertThat(provider.getUnsafe()).isEmpty();
}

@Test
Expand All @@ -104,6 +104,6 @@ public void getWithThrowable_shouldThrowExceptionWhenStorageProviderFails() thro
when(storageProvider.get()).thenThrow(exception);

provider = new UpdatableGraffitiProvider(storageProvider, () -> Optional.of(defaultGraffiti));
assertThatThrownBy(() -> provider.getWithThrowable()).isEqualTo(exception);
assertThatThrownBy(() -> provider.getUnsafe()).isEqualTo(exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc
try {
final UpdatableGraffitiProvider provider =
(UpdatableGraffitiProvider) maybeValidator.get().getGraffitiProvider();
request.respondOk(new GraffitiResponse(publicKey, provider.getWithThrowable()));
request.respondOk(new GraffitiResponse(publicKey, provider.getUnsafe()));
} catch (Throwable e) {
request.respondError(SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void shouldHandleGraffitiManagementException() throws Throwable {
final GraffitiManagementException exception =
new GraffitiManagementException("Unable to retrieve graffiti from storage");
final UpdatableGraffitiProvider provider = mock(UpdatableGraffitiProvider.class);
doThrow(exception).when(provider).getWithThrowable();
doThrow(exception).when(provider).getUnsafe();
final Validator validator = new Validator(publicKey, NO_OP_SIGNER, provider);
when(keyManager.getValidatorByPublicKey(eq(publicKey))).thenReturn(Optional.of(validator));

Expand All @@ -85,7 +85,7 @@ void shouldHandleGraffitiManagementException() throws Throwable {
assertThat(request.getResponseCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
assertThat(request.getResponseBody())
.isEqualTo(new HttpErrorResponse(SC_INTERNAL_SERVER_ERROR, exception.getMessage()));
verify(provider).getWithThrowable();
verify(provider).getUnsafe();
}

@Test
Expand Down Expand Up @@ -133,7 +133,7 @@ void metadata_shouldHandle500() throws JsonProcessingException {

private void checkGraffiti(final Optional<Bytes32> graffiti) throws Throwable {
final UpdatableGraffitiProvider provider = mock(UpdatableGraffitiProvider.class);
when(provider.getWithThrowable()).thenReturn(graffiti);
when(provider.getUnsafe()).thenReturn(graffiti);
final Validator validator = new Validator(publicKey, NO_OP_SIGNER, provider);
when(keyManager.getValidatorByPublicKey(eq(publicKey))).thenReturn(Optional.of(validator));

Expand All @@ -143,6 +143,6 @@ private void checkGraffiti(final Optional<Bytes32> graffiti) throws Throwable {
new GetGraffiti.GraffitiResponse(publicKey, graffiti);
assertThat(request.getResponseCode()).isEqualTo(SC_OK);
assertThat(request.getResponseBody()).isEqualTo(expectedResponse);
verify(provider).getWithThrowable();
verify(provider).getUnsafe();
}
}

0 comments on commit d9f196e

Please sign in to comment.