Skip to content

Commit 1aa9649

Browse files
committed
Update tests
1 parent 4ed37cc commit 1aa9649

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

validator/client/src/test/java/tech/pegasys/teku/validator/client/restapi/apis/DeleteGraffitiTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,18 @@ void shouldSuccessfullyDeleteGraffiti() throws IOException, GraffitiManagementEx
7474
@Test
7575
void shouldReturnErrorWhenIssueDeletingGraffiti()
7676
throws IOException, GraffitiManagementException {
77-
final String errorMessage = "Unable to delete graffiti for validator " + publicKey;
77+
final GraffitiManagementException exception =
78+
new GraffitiManagementException("Unable to delete graffiti for validator " + publicKey);
7879
final Validator validator = new Validator(publicKey, NO_OP_SIGNER, Optional::empty);
7980
when(keyManager.getValidatorByPublicKey(any())).thenReturn(Optional.of(validator));
80-
doThrow(new GraffitiManagementException(errorMessage))
81-
.when(graffitiManager)
82-
.deleteGraffiti(any());
81+
doThrow(exception).when(graffitiManager).deleteGraffiti(any());
8382

8483
handler.handleRequest(request);
8584

8685
verify(graffitiManager).deleteGraffiti(eq(publicKey));
8786
assertThat(request.getResponseCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
8887
assertThat(request.getResponseBody())
89-
.isEqualTo(new HttpErrorResponse(SC_INTERNAL_SERVER_ERROR, errorMessage));
88+
.isEqualTo(new HttpErrorResponse(SC_INTERNAL_SERVER_ERROR, exception.getMessage()));
9089
}
9190

9291
@Test

validator/client/src/test/java/tech/pegasys/teku/validator/client/restapi/apis/GetGraffitiTest.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static org.assertj.core.api.Assertions.assertThat;
1717
import static org.mockito.ArgumentMatchers.any;
1818
import static org.mockito.ArgumentMatchers.eq;
19+
import static org.mockito.Mockito.doThrow;
1920
import static org.mockito.Mockito.mock;
2021
import static org.mockito.Mockito.verify;
2122
import static org.mockito.Mockito.when;
@@ -71,16 +72,11 @@ void shouldGetEmptyGraffiti() throws Throwable {
7172
}
7273

7374
@Test
74-
void shouldHandleGraffitiManagementException() throws JsonProcessingException {
75+
void shouldHandleGraffitiManagementException() throws Throwable {
7576
final GraffitiManagementException exception =
7677
new GraffitiManagementException("Unable to retrieve graffiti from storage");
77-
final UpdatableGraffitiProvider provider =
78-
new UpdatableGraffitiProvider(
79-
() -> {
80-
throw exception;
81-
},
82-
Optional::empty);
83-
78+
final UpdatableGraffitiProvider provider = mock(UpdatableGraffitiProvider.class);
79+
doThrow(exception).when(provider).getWithThrowable();
8480
final Validator validator = new Validator(publicKey, NO_OP_SIGNER, provider);
8581
when(keyManager.getValidatorByPublicKey(eq(publicKey))).thenReturn(Optional.of(validator));
8682

@@ -89,6 +85,7 @@ void shouldHandleGraffitiManagementException() throws JsonProcessingException {
8985
assertThat(request.getResponseCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
9086
assertThat(request.getResponseBody())
9187
.isEqualTo(new HttpErrorResponse(SC_INTERNAL_SERVER_ERROR, exception.getMessage()));
88+
verify(provider).getWithThrowable();
9289
}
9390

9491
@Test

validator/client/src/test/java/tech/pegasys/teku/validator/client/restapi/apis/SetGraffitiTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,20 @@ void shouldSuccessfullySetGraffiti() throws IOException, GraffitiManagementExcep
7777

7878
@Test
7979
void shouldReturnErrorWhenIssueSettingGraffiti() throws IOException, GraffitiManagementException {
80-
final String errorMessage = "Unable to update graffiti for validator " + publicKey;
80+
final GraffitiManagementException exception =
81+
new GraffitiManagementException("Unable to update graffiti for validator " + publicKey);
8182
request.setRequestBody(graffiti);
8283

8384
final Validator validator = new Validator(publicKey, NO_OP_SIGNER, Optional::empty);
8485
when(keyManager.getValidatorByPublicKey(any())).thenReturn(Optional.of(validator));
85-
doThrow(new GraffitiManagementException(errorMessage))
86-
.when(graffitiManager)
87-
.setGraffiti(any(), eq(graffiti));
86+
doThrow(exception).when(graffitiManager).setGraffiti(any(), eq(graffiti));
8887

8988
handler.handleRequest(request);
9089

9190
verify(graffitiManager).setGraffiti(eq(publicKey), eq(graffiti));
9291
assertThat(request.getResponseCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
9392
assertThat(request.getResponseBody())
94-
.isEqualTo(new HttpErrorResponse(SC_INTERNAL_SERVER_ERROR, errorMessage));
93+
.isEqualTo(new HttpErrorResponse(SC_INTERNAL_SERVER_ERROR, exception.getMessage()));
9594
}
9695

9796
@Test

0 commit comments

Comments
 (0)