17
17
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
18
18
import static org .mockito .ArgumentMatchers .any ;
19
19
import static org .mockito .ArgumentMatchers .eq ;
20
+ import static org .mockito .Mockito .doThrow ;
20
21
import static org .mockito .Mockito .mock ;
21
22
import static org .mockito .Mockito .when ;
22
23
import static tech .pegasys .teku .infrastructure .http .HttpStatusCodes .SC_BAD_REQUEST ;
30
31
import static tech .pegasys .teku .spec .generator .signatures .NoOpLocalSigner .NO_OP_SIGNER ;
31
32
32
33
import com .fasterxml .jackson .core .JsonProcessingException ;
34
+ import java .io .IOException ;
33
35
import java .util .Optional ;
34
36
import org .junit .jupiter .api .Test ;
35
37
import tech .pegasys .teku .bls .BLSPublicKey ;
@@ -57,12 +59,11 @@ class SetGraffitiTest {
57
59
.build ();
58
60
59
61
@ Test
60
- void shouldSuccessfullySetGraffiti () throws JsonProcessingException {
62
+ void shouldSuccessfullySetGraffiti () throws IOException {
61
63
request .setRequestBody (graffiti );
62
64
63
65
final Validator validator = new Validator (publicKey , NO_OP_SIGNER , Optional ::empty );
64
66
when (keyManager .getValidatorByPublicKey (any ())).thenReturn (Optional .of (validator ));
65
- when (graffitiManager .setGraffiti (any (), any ())).thenReturn (Optional .empty ());
66
67
67
68
handler .handleRequest (request );
68
69
@@ -71,23 +72,24 @@ void shouldSuccessfullySetGraffiti() throws JsonProcessingException {
71
72
}
72
73
73
74
@ Test
74
- void shouldReturnErrorWhenIssueSetting () throws JsonProcessingException {
75
+ void shouldReturnErrorWhenIssueSetting () throws IOException {
75
76
request .setRequestBody (graffiti );
76
77
77
78
final Validator validator = new Validator (publicKey , NO_OP_SIGNER , Optional ::empty );
78
79
when (keyManager .getValidatorByPublicKey (any ())).thenReturn (Optional .of (validator ));
79
- when (graffitiManager .setGraffiti (any (), eq (graffiti )))
80
- .thenReturn (Optional .of ("Error deleting graffiti" ));
80
+ doThrow (IOException .class ).when (graffitiManager ).setGraffiti (any (), eq (graffiti ));
81
81
82
82
handler .handleRequest (request );
83
83
84
84
assertThat (request .getResponseCode ()).isEqualTo (SC_INTERNAL_SERVER_ERROR );
85
85
assertThat (request .getResponseBody ())
86
- .isEqualTo (new HttpErrorResponse (SC_INTERNAL_SERVER_ERROR , "Error deleting graffiti" ));
86
+ .isEqualTo (
87
+ new HttpErrorResponse (
88
+ SC_INTERNAL_SERVER_ERROR , "Unable to update graffiti for validator " + publicKey ));
87
89
}
88
90
89
91
@ Test
90
- void shouldThrowExceptionWhenInvalidGraffitiInput () {
92
+ void shouldThrowExceptionWhenInvalidGraffitiInput () throws IOException {
91
93
final String invalidGraffiti = "This graffiti is a bit too long!!" ;
92
94
final String errorMessage =
93
95
String .format (
@@ -96,8 +98,9 @@ void shouldThrowExceptionWhenInvalidGraffitiInput() {
96
98
97
99
final Validator validator = new Validator (publicKey , NO_OP_SIGNER , Optional ::empty );
98
100
when (keyManager .getValidatorByPublicKey (any ())).thenReturn (Optional .of (validator ));
99
- when (graffitiManager .setGraffiti (any (), eq (invalidGraffiti )))
100
- .thenThrow (new IllegalArgumentException (errorMessage ));
101
+ doThrow (new IllegalArgumentException (errorMessage ))
102
+ .when (graffitiManager )
103
+ .setGraffiti (any (), eq (invalidGraffiti ));
101
104
102
105
assertThatThrownBy (() -> handler .handleRequest (request ))
103
106
.isInstanceOf (IllegalArgumentException .class )
0 commit comments