Skip to content

Commit 83d84e5

Browse files
committed
Added tests for deleteFile method
Signed-off-by: Lemeri123 <[email protected]>
1 parent bce1fb8 commit 83d84e5

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,32 @@
1313
import org.junit.jupiter.api.Assertions;
1414
import org.junit.jupiter.api.BeforeEach;
1515
import org.junit.jupiter.api.Test;
16+
import org.mockito.Mock;
1617
import org.mockito.Mockito;
1718

1819
import java.time.Instant;
1920

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;
2025
import static org.mockito.ArgumentMatchers.any;
2126
import static org.mockito.Mockito.when;
2227
import static org.mockito.Mockito.verify;
28+
import static org.mockito.Mockito.mock;
2329
import static org.mockito.Mockito.times;
2430

2531
public class FileClientImplTest {
2632
ProtocolLayerClient protocolLayerClient;
2733
FileClientImpl fileClientImpl;
34+
@Mock
35+
private FileClientImpl fileClient;
2836

2937
@BeforeEach
3038
void setup() {
3139
protocolLayerClient = Mockito.mock(ProtocolLayerClient.class);
3240
fileClientImpl = new FileClientImpl(protocolLayerClient);
41+
fileClient = new FileClientImpl(protocolLayerClient);
3342
}
3443

3544
@Test
@@ -163,4 +172,47 @@ void testGetFileSizeThrowsExceptionForNullId() {
163172
);
164173
Assertions.assertTrue(exception.getMessage().contains(message));
165174
}
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+
166218
}

0 commit comments

Comments
 (0)