Skip to content

Commit 8ab98d6

Browse files
committed
Remove redundant ReturnNull check + update Javadoc string
1 parent 1f29940 commit 8ab98d6

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

src/main/java/com/codesungrape/hmcts/bookapi/service/BookService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class BookService {
2323
* @return The saved Book entity
2424
* @throws NullPointerException if request is null
2525
* @throws IllegalArgumentException if title is null or blank
26-
* @throws IllegalStateException if the repository fails to save the book
2726
*/
2827
public Book createBook(BookRequest request) {
2928
// Validation check for business rules (e.g., uniqueness, if required)

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@
1717
import java.util.UUID;
1818
import java.util.stream.Stream;
1919

20-
import static org.junit.jupiter.api.Assertions.*;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
2123
import static org.mockito.ArgumentMatchers.any;
22-
import static org.mockito.Mockito.*;
23-
24-
/**
25-
* @ExtendWith(MockitoExtension.class): tells JUnit 5 to use Mockito's extension and automatically
26-
* initializes all @Mock and @InjectMocks fields when running this test class. @Mock: Creates a fake
27-
* version (mock) of the dependency. @InjectMocks: creates an instance of the real class under
28-
* test. @BeforeEach: Runs before each test method in the class. @Test: Marks the method as a test
29-
* case that JUnit should execute.
24+
import static org.mockito.Mockito.never;
25+
import static org.mockito.Mockito.when;
26+
import static org.mockito.Mockito.verify;
27+
import static org.mockito.Mockito.times;
28+
29+
30+
/**.
31+
* Explains how this test class uses Mockito:
32+
* - JUnit is extended using MockitoExtension
33+
* - @Mock creates fake dependencies
34+
* - @InjectMocks creates the real service with mocks injected
35+
* - @BeforeEach runs before every test
36+
* - @Test marks a test method
3037
*/
3138

3239
// Annotation tells JUnit to use Mockito
@@ -203,20 +210,6 @@ void testCreateBook_RepositoryFailure_ThrowsException() {
203210

204211
// ----- EDGE cases ---------
205212

206-
@Test
207-
void testCreateBook_RepositoryReturnsNull_HandlesGracefully() {
208-
// Arrange
209-
when(testBookRepository.save(any(Book.class))).thenReturn(null);
210-
211-
// Act & assert
212-
assertThrows(
213-
IllegalStateException.class,
214-
() -> {
215-
testBookService.createBook(validBookRequest);
216-
}
217-
);
218-
}
219-
220213
@ParameterizedTest(name = "{0}") // Display the test name
221214
@MethodSource("provideLongFieldTestCases")
222215
void testCreateBook_VeryLongFields_Success(

0 commit comments

Comments
 (0)