Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to BookService, CategoryService, BookController and Category… #14

Merged
merged 5 commits into from
Dec 25, 2023

Conversation

AntonBabychP1T
Copy link
Owner

Screenshot 2023-12-22 115314
…Controller

Copy link

@Rommelua Rommelua left a comment

Choose a reason for hiding this comment

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

Java Cl checks failed. Before making a Pull Request (or a new commit to an already existing PR), you need to write the mvn clean package command in the terminal and make sure that all checks pass. After that, the mentor will be able to review the homework

image

Copy link

@Sanderfuck Sanderfuck left a comment

Choose a reason for hiding this comment

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

image
Fix your tests at first


@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class BookControllerTest {

Choose a reason for hiding this comment

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

Suggested change

Comment on lines 132 to 159
BookDto firstBook = new BookDto();
firstBook.setId(1L);
firstBook.setTitle("First title");
firstBook.setAuthor("First Author");
firstBook.setPrice(BigDecimal.valueOf(9.99));
firstBook.setIsbn("1ISBN01");
firstBook.setDescription("description");
firstBook.setCoverImage("coverimage");
BookDto secondBook = new BookDto();
secondBook.setId(2L);
secondBook.setAuthor("Second Author");
secondBook.setTitle("Second title");
secondBook.setPrice(BigDecimal.valueOf(19.99));
secondBook.setIsbn("2ISBN02");
secondBook.setDescription("description");
secondBook.setCoverImage("coverimage");
BookDto thirdBook = new BookDto();
thirdBook.setId(3L);
thirdBook.setAuthor("Third Author");
thirdBook.setTitle("Third title");
thirdBook.setPrice(BigDecimal.valueOf(19.99));
thirdBook.setIsbn("3ISBN03");
thirdBook.setDescription("description");
thirdBook.setCoverImage("coverimage");
List<BookDto> expected = new ArrayList<>();
expected.add(firstBook);
expected.add(secondBook);
expected.add(thirdBook);

Choose a reason for hiding this comment

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

Create templates of entities and reuse it in every test what you need

Comment on lines 48 to 57
@InjectMocks
private BookServiceImpl bookService;

@Mock
private BookRepository bookRepository;

@Mock
private BookMapper bookMapper;
@Mock
private BookSpecificationBuilder bookSpecificationBuilder;

Choose a reason for hiding this comment

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

Manage your empty lines! Inject place after Mock

//when
List<BookDto> bookDtos = bookService.findAll(pageable);

//then

Choose a reason for hiding this comment

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

Don`t needs comment in this case

Comment on lines +30 to +32
public class CategoryServiceTest {

private static final String VALID_NAME = "Valid name";

Choose a reason for hiding this comment

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

Keep one style of empty line after naming class

@Sanderfuck
Copy link

Fix your checks!!!!

@AntonBabychP1T AntonBabychP1T merged commit dc0e346 into master Dec 25, 2023
2 checks passed
@AntonBabychP1T AntonBabychP1T deleted the test-impementation branch December 25, 2023 13:37
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.

3 participants