Skip to content

Commit 85fb4ff

Browse files
committed
Add test delete ShouldDoNothing_WhenAlreadyDeleted; 100% coverage
1 parent d753118 commit 85fb4ff

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/java/com/codesungrape/hmcts/bookapi/BookServiceTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,20 @@ void testDeleteBookById_Success() {
319319
verify(testBookRepository, times(1)).findById(testId);
320320
verify(testBookRepository, times(1)).save(persistedBook);
321321
}
322+
323+
@Test
324+
void testDeleteBookById_ShouldDoNothing_WhenAlreadyDeleted() {
325+
326+
// Arrange:
327+
persistedBook.setDeleted(true); // ensure starting state
328+
when(testBookRepository.findById(testId))
329+
.thenReturn(Optional.of(persistedBook));
330+
331+
// Act: call the service method we are testing
332+
testBookService.deleteBookById(testId);
333+
334+
// Assert
335+
// Verify save was NEVER called (it entered the 'false' branch of if)
336+
verify(testBookRepository, never()).save(any(Book.class));
337+
}
322338
}

0 commit comments

Comments
 (0)