|
17 | 17 | import org.junit.jupiter.api.Assertions; |
18 | 18 | import org.junit.jupiter.api.BeforeEach; |
19 | 19 | import org.junit.jupiter.api.Test; |
| 20 | +import org.mockito.Mock; |
20 | 21 | import org.mockito.Mockito; |
21 | 22 |
|
22 | 23 | import java.time.Instant; |
23 | 24 |
|
| 25 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 26 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 27 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 28 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
24 | 29 | import static org.mockito.ArgumentMatchers.any; |
25 | 30 | import static org.mockito.Mockito.when; |
26 | 31 | import static org.mockito.Mockito.verify; |
| 32 | +import static org.mockito.Mockito.mock; |
27 | 33 | import static org.mockito.Mockito.times; |
28 | 34 |
|
29 | 35 | public class FileClientImplTest { |
30 | 36 | ProtocolLayerClient protocolLayerClient; |
31 | 37 | FileClientImpl fileClientImpl; |
| 38 | + |
| 39 | + @Mock |
| 40 | + private FileClientImpl fileClient; |
32 | 41 |
|
33 | 42 | @BeforeEach |
34 | 43 | void setup() { |
35 | 44 | protocolLayerClient = Mockito.mock(ProtocolLayerClient.class); |
36 | 45 | fileClientImpl = new FileClientImpl(protocolLayerClient); |
| 46 | + fileClient = new FileClientImpl(protocolLayerClient); |
37 | 47 | } |
38 | 48 |
|
39 | 49 | @Test |
@@ -266,6 +276,50 @@ void testGetFileSizeThrowsExceptionForNullId() { |
266 | 276 | Assertions.assertTrue(exception.getMessage().contains(message)); |
267 | 277 | } |
268 | 278 |
|
| 279 | + |
| 280 | +//tests for deletefile method |
| 281 | +@Test |
| 282 | +public void testIsDeleted_FileIsDeleted() throws HieroException { |
| 283 | + // Given |
| 284 | + FileId fileId = FileId.fromString("0.0.123"); |
| 285 | + FileInfoResponse response = mock(FileInfoResponse.class); |
| 286 | + when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class))).thenReturn(response); |
| 287 | + when(response.deleted()).thenReturn(true); |
| 288 | + |
| 289 | + // When |
| 290 | + boolean result = fileClient.isDeleted(fileId); |
| 291 | + |
| 292 | + // Then |
| 293 | + assertTrue(result); |
| 294 | +} |
| 295 | + |
| 296 | +@Test |
| 297 | +public void testIsDeleted_FileIsNotDeleted() throws HieroException { |
| 298 | + // Given |
| 299 | + FileId fileId = FileId.fromString("0.0.123"); |
| 300 | + FileInfoResponse response = mock(FileInfoResponse.class); |
| 301 | + when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class))).thenReturn(response); |
| 302 | + when(response.deleted()).thenReturn(false); |
| 303 | + |
| 304 | + // When |
| 305 | + boolean result = fileClient.isDeleted(fileId); |
| 306 | + |
| 307 | + // Then |
| 308 | + assertFalse(result); |
| 309 | +} |
| 310 | + |
| 311 | +@Test |
| 312 | +public void testIsDeleted_NullFileId() { |
| 313 | + // When |
| 314 | + NullPointerException exception = assertThrows(NullPointerException.class, () -> { |
| 315 | + fileClient.isDeleted(null); |
| 316 | + }); |
| 317 | + |
| 318 | + // Then |
| 319 | + assertEquals("fileId must not be null", exception.getMessage()); |
| 320 | +} |
| 321 | + |
| 322 | + |
269 | 323 | @Test |
270 | 324 | void testReadFile() throws HieroException { |
271 | 325 | // mock |
|
0 commit comments