|
13 | 13 | import org.junit.jupiter.api.Assertions; |
14 | 14 | import org.junit.jupiter.api.BeforeEach; |
15 | 15 | import org.junit.jupiter.api.Test; |
| 16 | +import org.mockito.Mock; |
16 | 17 | import org.mockito.Mockito; |
17 | 18 |
|
18 | 19 | import java.time.Instant; |
19 | 20 |
|
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
20 | 25 | import static org.mockito.ArgumentMatchers.any; |
21 | 26 | import static org.mockito.Mockito.when; |
22 | 27 | import static org.mockito.Mockito.verify; |
| 28 | +import static org.mockito.Mockito.mock; |
23 | 29 | import static org.mockito.Mockito.times; |
24 | 30 |
|
25 | 31 | public class FileClientImplTest { |
26 | 32 | ProtocolLayerClient protocolLayerClient; |
27 | 33 | FileClientImpl fileClientImpl; |
| 34 | + @Mock |
| 35 | + private FileClientImpl fileClient; |
28 | 36 |
|
29 | 37 | @BeforeEach |
30 | 38 | void setup() { |
31 | 39 | protocolLayerClient = Mockito.mock(ProtocolLayerClient.class); |
32 | 40 | fileClientImpl = new FileClientImpl(protocolLayerClient); |
| 41 | + fileClient = new FileClientImpl(protocolLayerClient); |
33 | 42 | } |
34 | 43 |
|
35 | 44 | @Test |
@@ -163,4 +172,47 @@ void testGetFileSizeThrowsExceptionForNullId() { |
163 | 172 | ); |
164 | 173 | Assertions.assertTrue(exception.getMessage().contains(message)); |
165 | 174 | } |
| 175 | + |
| 176 | +//tests for deletefile method |
| 177 | +@Test |
| 178 | +public void testIsDeleted_FileIsDeleted() throws HieroException { |
| 179 | + // Given |
| 180 | + FileId fileId = FileId.fromString("0.0.123"); |
| 181 | + FileInfoResponse response = mock(FileInfoResponse.class); |
| 182 | + when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class))).thenReturn(response); |
| 183 | + when(response.deleted()).thenReturn(true); |
| 184 | + |
| 185 | + // When |
| 186 | + boolean result = fileClient.isDeleted(fileId); |
| 187 | + |
| 188 | + // Then |
| 189 | + assertTrue(result); |
| 190 | +} |
| 191 | + |
| 192 | +@Test |
| 193 | +public void testIsDeleted_FileIsNotDeleted() throws HieroException { |
| 194 | + // Given |
| 195 | + FileId fileId = FileId.fromString("0.0.123"); |
| 196 | + FileInfoResponse response = mock(FileInfoResponse.class); |
| 197 | + when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class))).thenReturn(response); |
| 198 | + when(response.deleted()).thenReturn(false); |
| 199 | + |
| 200 | + // When |
| 201 | + boolean result = fileClient.isDeleted(fileId); |
| 202 | + |
| 203 | + // Then |
| 204 | + assertFalse(result); |
| 205 | +} |
| 206 | + |
| 207 | +@Test |
| 208 | +public void testIsDeleted_NullFileId() { |
| 209 | + // When |
| 210 | + NullPointerException exception = assertThrows(NullPointerException.class, () -> { |
| 211 | + fileClient.isDeleted(null); |
| 212 | + }); |
| 213 | + |
| 214 | + // Then |
| 215 | + assertEquals("fileId must not be null", exception.getMessage()); |
| 216 | +} |
| 217 | + |
166 | 218 | } |
0 commit comments