Skip to content

Commit f11f225

Browse files
committed
Rename variables for better clarity for others
1 parent 686647d commit f11f225

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.stream.Stream;
2424

2525
import static org.junit.jupiter.api.Assertions.assertEquals;
26-
import static org.junit.jupiter.api.Assertions.assertNotNull;
2726
import static org.junit.jupiter.api.Assertions.assertNull;
2827
import static org.junit.jupiter.api.Assertions.assertThrows;
2928
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -131,34 +130,33 @@ void testCreateBook_Success() {
131130
BookRequest specialRequest =
132131
new BookRequest("Java & Friends!", "Synopsis", "Author");
133132

134-
Book expectedBook =
133+
// The "Future" Book (What the DB returns)
134+
Book bookFromDb =
135135
Book.builder()
136136
.id(testId)
137137
.title(specialRequest.title())
138138
.synopsis(specialRequest.synopsis())
139139
.author(specialRequest.author())
140140
.build();
141141

142-
when(testBookRepository.save(any(Book.class))).thenReturn(expectedBook);
142+
when(testBookRepository.save(any(Book.class))).thenReturn(bookFromDb);
143143

144144
// Act
145145
Book result = testBookService.createBook(specialRequest);
146146

147147
// Assert: Verify the Service fulfills its return contract
148-
assertEquals(expectedBook, result, "Service must return the object returned by the repository");
148+
assertEquals(bookFromDb, result, "Service must return the object returned by the repository");
149149

150-
// Assert: capture the Book passed to save()
150+
// Assert: Capture the "Past" Book (What went INTO the DB)
151151
ArgumentCaptor<Book> bookCaptor = ArgumentCaptor.forClass(Book.class);
152152
verify(testBookRepository, times(1)).save(bookCaptor.capture());
153-
Book savedBook = bookCaptor.getValue();
153+
Book bookSentToDb = bookCaptor.getValue();
154154

155155
// Assert
156-
assertNotNull(savedBook);
157-
assertNull(savedBook.getId(), "ID should be null before DB generates it");
158-
assertEquals(specialRequest.title(), savedBook.getTitle());
159-
assertEquals(specialRequest.synopsis(), savedBook.getSynopsis());
160-
assertEquals(specialRequest.author(), savedBook.getAuthor());
161-
156+
assertNull(bookSentToDb.getId(), "ID should be null before DB generates it");
157+
assertEquals(specialRequest.title(), bookSentToDb.getTitle());
158+
assertEquals(specialRequest.synopsis(), bookSentToDb.getSynopsis());
159+
assertEquals(specialRequest.author(), bookSentToDb.getAuthor());
162160
}
163161

164162
@Test

0 commit comments

Comments
 (0)