Search in sources :

Example 1 with Book

use of com.example.demo.entity.Book in project spring-boot-backend-template by paakmau.

the class BookServiceTests method initAll.

@BeforeAll
static void initAll() {
    ModelMapper modelMapper = new ModelMapper();
    books = Arrays.asList(new Book(1L, "Book 1", "Author 1"), new Book(2L, "Book 2", "Author 2"), new Book(3L, "Book 3", "Author 3"));
    bookDtos = books.stream().map(b -> modelMapper.map(b, BookDto.class)).collect(Collectors.toList());
}
Also used : BookDto(com.example.demo.dto.BookDto) Book(com.example.demo.entity.Book) ModelMapper(org.modelmapper.ModelMapper) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with Book

use of com.example.demo.entity.Book in project spring-boot-backend-template by paakmau.

the class BookRepoTests method testGetByTitle.

@Test
void testGetByTitle() {
    for (Book book : bookMap.values()) {
        List<Book> actualBooks = repo.findByTitle(book.getTitle());
        assertEquals(1, actualBooks.size());
        assertEquals(book, actualBooks.get(0));
    }
}
Also used : Book(com.example.demo.entity.Book) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 3 with Book

use of com.example.demo.entity.Book in project spring-boot-backend-template by paakmau.

the class BookServiceTests method testGetByTitle.

@Test
void testGetByTitle() {
    for (Book book : books) {
        Mockito.when(repo.findByTitle(book.getTitle())).thenReturn(Arrays.asList(book));
    }
    for (BookDto dto : bookDtos) {
        List<BookDto> vos = service.getByTitle(dto.getTitle());
        assertEquals(1, vos.size());
        assertEquals(dto, vos.get(0));
    }
}
Also used : BookDto(com.example.demo.dto.BookDto) Book(com.example.demo.entity.Book) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Book (com.example.demo.entity.Book)3 BookDto (com.example.demo.dto.BookDto)2 Test (org.junit.jupiter.api.Test)2 BeforeAll (org.junit.jupiter.api.BeforeAll)1 ModelMapper (org.modelmapper.ModelMapper)1 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1