-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
…Controller Fix problem with compiler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…Controller Fix problem with compiler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class BookControllerTest { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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
@InjectMocks | ||
private BookServiceImpl bookService; | ||
|
||
@Mock | ||
private BookRepository bookRepository; | ||
|
||
@Mock | ||
private BookMapper bookMapper; | ||
@Mock | ||
private BookSpecificationBuilder bookSpecificationBuilder; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
public class CategoryServiceTest { | ||
|
||
private static final String VALID_NAME = "Valid name"; |
There was a problem hiding this comment.
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
Fix your checks!!!! |
…Controller