@@ -56,7 +56,7 @@ void shouldThrowExceptionWhenUnableToCreateManagementDirectory(@TempDir final Pa
56
56
57
57
@ Test
58
58
void setGraffiti_shouldSetGraffitiWhenFileNotExist (@ TempDir final Path tempDir )
59
- throws IOException {
59
+ throws GraffitiManagementException {
60
60
dataDirLayout = new SimpleDataDirLayout (tempDir );
61
61
manager = new GraffitiManager (dataDirLayout );
62
62
assertThat (getGraffitiManagementDir ().toFile ().exists ()).isTrue ();
@@ -66,7 +66,8 @@ void setGraffiti_shouldSetGraffitiWhenFileNotExist(@TempDir final Path tempDir)
66
66
}
67
67
68
68
@ Test
69
- void setGraffiti_shouldSetGraffitiWhenFileExist (@ TempDir final Path tempDir ) throws IOException {
69
+ void setGraffiti_shouldSetGraffitiWhenFileExist (@ TempDir final Path tempDir )
70
+ throws IOException , GraffitiManagementException {
70
71
dataDirLayout = new SimpleDataDirLayout (tempDir );
71
72
manager = new GraffitiManager (dataDirLayout );
72
73
assertThat (getGraffitiManagementDir ().resolve (getFileName (publicKey )).toFile ().createNewFile ())
@@ -117,7 +118,7 @@ void deleteGraffiti_shouldSucceedWhenNoGraffitiToDelete(@TempDir final Path temp
117
118
118
119
@ Test
119
120
void deleteGraffiti_shouldDeleteGraffitiWhenFileExist (@ TempDir final Path tempDir )
120
- throws IOException {
121
+ throws IOException , GraffitiManagementException {
121
122
dataDirLayout = new SimpleDataDirLayout (tempDir );
122
123
manager = new GraffitiManager (dataDirLayout );
123
124
assertThat (getGraffitiManagementDir ().resolve (getFileName (publicKey )).toFile ().createNewFile ())
@@ -145,7 +146,7 @@ void deleteGraffiti_shouldReturnErrorMessageWhenUnableToDeleteFile(@TempDir fina
145
146
146
147
@ Test
147
148
void shouldSetAndDeleteGraffitiWhenManagementPreexisting (@ TempDir final Path tempDir )
148
- throws IOException {
149
+ throws GraffitiManagementException {
149
150
dataDirLayout = new SimpleDataDirLayout (tempDir );
150
151
final Path managementDir = getGraffitiManagementDir ();
151
152
assertThat (managementDir .toFile ().mkdirs ()).isTrue ();
@@ -174,7 +175,8 @@ private void checkNoGraffitiFile(final BLSPublicKey publicKey) {
174
175
}
175
176
176
177
@ Test
177
- void getGraffiti_shouldGetGraffitiFromStorage (@ TempDir final Path tempDir ) throws IOException {
178
+ void getGraffiti_shouldGetGraffitiFromStorage (@ TempDir final Path tempDir )
179
+ throws IOException , GraffitiManagementException {
178
180
dataDirLayout = new SimpleDataDirLayout (tempDir );
179
181
manager = new GraffitiManager (dataDirLayout );
180
182
final Path filePath = getGraffitiManagementDir ().resolve (getFileName (publicKey ));
@@ -185,41 +187,62 @@ void getGraffiti_shouldGetGraffitiFromStorage(@TempDir final Path tempDir) throw
185
187
}
186
188
187
189
@ Test
188
- void getGraffiti_shouldReturnEmptyWhenFileNotExist (@ TempDir final Path tempDir ) {
190
+ void getGraffiti_shouldReturnEmptyWhenFileNotExist (@ TempDir final Path tempDir )
191
+ throws GraffitiManagementException {
189
192
dataDirLayout = new SimpleDataDirLayout (tempDir );
190
193
manager = new GraffitiManager (dataDirLayout );
191
194
192
195
assertThat (manager .getGraffiti (publicKey )).isEmpty ();
193
196
}
194
197
195
198
@ Test
196
- void getGraffiti_shouldReturnEmptyWhenFileTooBig (@ TempDir final Path tempDir ) throws IOException {
199
+ void getGraffiti_shouldThrowExceptionWhenGraffitiOver32Bytes (@ TempDir final Path tempDir )
200
+ throws IOException {
197
201
dataDirLayout = new SimpleDataDirLayout (tempDir );
198
202
manager = new GraffitiManager (dataDirLayout );
199
203
200
204
final String invalidGraffiti = "This graffiti is a bit too long!!" ;
201
205
final Path filePath = getGraffitiManagementDir ().resolve (getFileName (publicKey ));
202
206
Files .writeString (filePath , invalidGraffiti );
203
207
204
- assertThat (manager .getGraffiti (publicKey )).isEmpty ();
208
+ assertThatThrownBy (() -> manager .getGraffiti (publicKey ))
209
+ .isInstanceOf (GraffitiManagementException .class )
210
+ .hasMessage ("Unable to retrieve stored graffiti for validator " + publicKey );
211
+ }
212
+
213
+ @ Test
214
+ void getGraffiti_shouldThrowExceptionWhenFileOver40Bytes (@ TempDir final Path tempDir )
215
+ throws IOException {
216
+ dataDirLayout = new SimpleDataDirLayout (tempDir );
217
+ manager = new GraffitiManager (dataDirLayout );
218
+
219
+ final String invalidGraffiti = "This graffiti is a bit too long to get from file!!" ;
220
+ final Path filePath = getGraffitiManagementDir ().resolve (getFileName (publicKey ));
221
+ Files .writeString (filePath , invalidGraffiti );
222
+
223
+ assertThatThrownBy (() -> manager .getGraffiti (publicKey ))
224
+ .isInstanceOf (GraffitiManagementException .class )
225
+ .hasMessage ("Unable to retrieve stored graffiti for validator " + publicKey );
205
226
}
206
227
207
228
@ Test
208
229
@ DisabledOnOs (OS .WINDOWS ) // Can't set permissions on Windows
209
- void getGraffiti_shouldReturnEmptyWhenNotReadableFile (@ TempDir final Path tempDir )
230
+ void getGraffiti_shouldThrowExceptionWhenNotReadableFile (@ TempDir final Path tempDir )
210
231
throws IOException {
211
232
dataDirLayout = new SimpleDataDirLayout (tempDir );
212
233
manager = new GraffitiManager (dataDirLayout );
213
234
final Path filePath = getGraffitiManagementDir ().resolve (getFileName (publicKey ));
214
235
Files .writeString (filePath , graffiti );
215
236
assertThat (filePath .toFile ().setReadable (false )).isTrue ();
216
237
217
- assertThat (manager .getGraffiti (publicKey )).isEmpty ();
238
+ assertThatThrownBy (() -> manager .getGraffiti (publicKey ))
239
+ .isInstanceOf (GraffitiManagementException .class )
240
+ .hasMessage ("Unable to retrieve stored graffiti for validator " + publicKey );
218
241
}
219
242
220
243
@ Test
221
244
void getGraffiti_shouldReturnEmptyBytesWhenFileEmpty (@ TempDir final Path tempDir )
222
- throws IOException {
245
+ throws IOException , GraffitiManagementException {
223
246
dataDirLayout = new SimpleDataDirLayout (tempDir );
224
247
manager = new GraffitiManager (dataDirLayout );
225
248
final Path filePath = getGraffitiManagementDir ().resolve (getFileName (publicKey ));
0 commit comments