Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,80 @@ void testUpdateExpirationTimeThrowsExceptionForNullArguments() {
NullPointerException.class, () -> fileClientImpl.updateExpirationTime(null, null)
);
}

@Test
void testIsDeletedReturnsTrueForDeletedFile() throws HieroException {
final FileId fileId = FileId.fromString("1.2.3");
final FileInfoResponse fileInfoResponse = Mockito.mock(FileInfoResponse.class);
when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do way to much mocking to create really reasonable tests. I assume I should some documentation how to create good tests for this project to make it more easy. For for not approving your work :(

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @hendrikebbers Apologies for the late reply I can resolve this using real objects

.thenReturn(fileInfoResponse);
when(fileInfoResponse.deleted()).thenReturn(true);

boolean result = fileClientImpl.isDeleted(fileId);
assertTrue(result);
verify(protocolLayerClient, times(1))
.executeFileInfoQuery(any(FileInfoRequest.class));
}

@Test
void testIsDeletedReturnsFalseForActiveFile() throws HieroException {
final FileId fileId = FileId.fromString("1.2.3");
final FileInfoResponse fileInfoResponse = Mockito.mock(FileInfoResponse.class);

when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class)))
.thenReturn(fileInfoResponse);
when(fileInfoResponse.deleted()).thenReturn(false);

boolean result = fileClientImpl.isDeleted(fileId);

assertFalse(result);
verify(protocolLayerClient, times(1))
.executeFileInfoQuery(any(FileInfoRequest.class));
}

@Test
void testIsDeletedThrowsExceptionForNullFileId() {
final String message = "fileId must not be null";

final NullPointerException exception = assertThrows(
NullPointerException.class, () -> fileClientImpl.isDeleted(null)
);
assertTrue(exception.getMessage().contains(message));
}

@Test
void isDeleted_ReturnsTrue_WhenFileIsDeleted() throws HieroException {
FileId fileId = FileId.fromString("1.2.3");
FileInfoResponse mockResponse = mock(FileInfoResponse.class);
when(mockResponse.deleted()).thenReturn(true);
when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class)))
.thenReturn(mockResponse);

boolean result = fileClientImpl.isDeleted(fileId);
assertTrue(result);
verify(protocolLayerClient).executeFileInfoQuery(any(FileInfoRequest.class));
}

@Test
void isDeleted_ReturnsFalse_WhenFileIsNotDeleted() throws HieroException {
FileId fileId = FileId.fromString("1.2.3");
FileInfoResponse mockResponse = mock(FileInfoResponse.class);
when(mockResponse.deleted()).thenReturn(false);
when(protocolLayerClient.executeFileInfoQuery(any(FileInfoRequest.class)))
.thenReturn(mockResponse);

boolean result = fileClientImpl.isDeleted(fileId);

assertFalse(result);
verify(protocolLayerClient).executeFileInfoQuery(any(FileInfoRequest.class));
}
@Test
void isDeleted_ThrowsNullPointerException_WhenFileIdIsNull() {
NullPointerException exception = assertThrows(
NullPointerException.class,
() -> fileClientImpl.isDeleted(null)
);
assertEquals("fileId must not be null", exception.getMessage());
}

}