Skip to content

Commit

Permalink
Merge pull request #139 from Lemeri123/working
Browse files Browse the repository at this point in the history
Added tests for deleteFile method
  • Loading branch information
hendrikebbers authored Jan 16, 2025
2 parents 625f3be + 04ea701 commit fe40da4
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,33 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.time.Instant;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;

public class FileClientImplTest {
ProtocolLayerClient protocolLayerClient;
FileClientImpl fileClientImpl;

@Mock
private FileClientImpl fileClient;

@BeforeEach
void setup() {
protocolLayerClient = Mockito.mock(ProtocolLayerClient.class);
fileClientImpl = new FileClientImpl(protocolLayerClient);
fileClient = new FileClientImpl(protocolLayerClient);
}

@Test
Expand Down Expand Up @@ -266,6 +276,50 @@ void testGetFileSizeThrowsExceptionForNullId() {
Assertions.assertTrue(exception.getMessage().contains(message));
}


//tests for deletefile method
@Test
public void testIsDeleted_FileIsDeleted() throws HieroException {
// Given
FileId fileId = FileId.fromString("0.0.123");
FileInfoResponse response = mock(FileInfoResponse.class);
when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class))).thenReturn(response);
when(response.deleted()).thenReturn(true);

// When
boolean result = fileClient.isDeleted(fileId);

// Then
assertTrue(result);
}

@Test
public void testIsDeleted_FileIsNotDeleted() throws HieroException {
// Given
FileId fileId = FileId.fromString("0.0.123");
FileInfoResponse response = mock(FileInfoResponse.class);
when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class))).thenReturn(response);
when(response.deleted()).thenReturn(false);

// When
boolean result = fileClient.isDeleted(fileId);

// Then
assertFalse(result);
}

@Test
public void testIsDeleted_NullFileId() {
// When
NullPointerException exception = assertThrows(NullPointerException.class, () -> {
fileClient.isDeleted(null);
});

// Then
assertEquals("fileId must not be null", exception.getMessage());
}


@Test
void testReadFile() throws HieroException {
// mock
Expand Down

0 comments on commit fe40da4

Please sign in to comment.