Skip to content

Book functionality test || HW#15

Merged
Jelors merged 8 commits into
mainfrom
bft-hw
Feb 7, 2026
Merged

Book functionality test || HW#15
Jelors merged 8 commits into
mainfrom
bft-hw

Conversation

@Jelors

@Jelors Jelors commented Jan 8, 2026

Copy link
Copy Markdown
Owner
image_2026-01-08_124531249

@Elena-Bruyako Elena-Bruyako left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

apply comments for all tests

Comment on lines +35 to +37
@Sql(scripts = "classpath:database/books/add-items-to-categories-table.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "classpath:database/books/add-three-items-to-books-table.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "classpath:database/books/assign-categories-for-books.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

BEFORE_TEST_METHOD is by default

Suggested change
@Sql(scripts = "classpath:database/books/add-items-to-categories-table.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "classpath:database/books/add-three-items-to-books-table.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "classpath:database/books/assign-categories-for-books.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = {"classpath:database/books/add-items-to-categories-table.sql", "classpath:database/books/add-three-items-to-books-table.sql",
"classpath:database/books/assign-categories-for-books.sql"})


Map<String, Object> responseMap = objectMapper.readValue(jsonResponse, new TypeReference<>() {
});
Assertions.assertEquals(3, responseMap.get("totalElements"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use static imports
check all places


String jsonResponse = result.getResponse().getContentAsString();

assertTrue(jsonResponse.contains("Kobzar"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

compare expected and actual dto

@AutoConfigureMockMvc
@WithMockUser(username = "admin", roles = {"ADMIN"})
@Sql(scripts = "classpath:database/books/categories/add-five-items-to-categories-table.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "classpath:database/books/add-three-items-to-books-table.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same comments as in BookControllerTest

@Jelors Jelors requested a review from Elena-Bruyako January 10, 2026 10:13

@Elena-Bruyako Elena-Bruyako left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

see comments

Comment on lines +159 to +163
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getAuthor(), actual.getAuthor());
assertEquals(expected.getTitle(), actual.getTitle());
assertEquals(expected.getPrice(), actual.getPrice());
assertEquals(expected.getCategoryIds(), actual.getCategoryIds());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

check other places, don't complicate code

Suggested change
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getAuthor(), actual.getAuthor());
assertEquals(expected.getTitle(), actual.getTitle());
assertEquals(expected.getPrice(), actual.getPrice());
assertEquals(expected.getCategoryIds(), actual.getCategoryIds());
assertEquals(expected, actual);

}
);
assertEquals(5, actualDtos.size());
assertEquals("Fantasy", actualDtos.get(0).getName());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here

.thenReturn(bookDto);
BookDto actual = bookService.save(requestDto);

EqualsBuilder.reflectionEquals(bookEntity, actual, "id");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

always use assertTrue before reflectionEquals
check other places

Suggested change
EqualsBuilder.reflectionEquals(bookEntity, actual, "id");
assertTrue(EqualsBuilder.reflectionEquals(bookEntity, actual, "id"));


bookService.deleteBookById(1L);

Mockito.verify(bookRepository)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use static imports
check all places

@Jelors Jelors requested a review from Elena-Bruyako January 14, 2026 12:58
@Jelors Jelors merged commit 923ce47 into main Feb 7, 2026
2 checks passed
@Jelors Jelors deleted the bft-hw branch February 7, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants