Skip to content

Commit fe40da4

Browse files
Merge pull request #139 from Lemeri123/working
Added tests for deleteFile method
2 parents 625f3be + 04ea701 commit fe40da4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

hiero-enterprise-base/src/test/java/com/openelements/hiero/base/test/FileClientImplTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,33 @@
1717
import org.junit.jupiter.api.Assertions;
1818
import org.junit.jupiter.api.BeforeEach;
1919
import org.junit.jupiter.api.Test;
20+
import org.mockito.Mock;
2021
import org.mockito.Mockito;
2122

2223
import java.time.Instant;
2324

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;
2429
import static org.mockito.ArgumentMatchers.any;
2530
import static org.mockito.Mockito.when;
2631
import static org.mockito.Mockito.verify;
32+
import static org.mockito.Mockito.mock;
2733
import static org.mockito.Mockito.times;
2834

2935
public class FileClientImplTest {
3036
ProtocolLayerClient protocolLayerClient;
3137
FileClientImpl fileClientImpl;
38+
39+
@Mock
40+
private FileClientImpl fileClient;
3241

3342
@BeforeEach
3443
void setup() {
3544
protocolLayerClient = Mockito.mock(ProtocolLayerClient.class);
3645
fileClientImpl = new FileClientImpl(protocolLayerClient);
46+
fileClient = new FileClientImpl(protocolLayerClient);
3747
}
3848

3949
@Test
@@ -266,6 +276,50 @@ void testGetFileSizeThrowsExceptionForNullId() {
266276
Assertions.assertTrue(exception.getMessage().contains(message));
267277
}
268278

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+
269323
@Test
270324
void testReadFile() throws HieroException {
271325
// mock

0 commit comments

Comments
 (0)