Search in sources :

Example 6 with BookDto

use of com.example.demo.dto.BookDto 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

BookDto (com.example.demo.dto.BookDto)6 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 MvcResult (org.springframework.test.web.servlet.MvcResult)5 ArrayList (java.util.ArrayList)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Book (com.example.demo.entity.Book)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 AfterAll (org.junit.jupiter.api.AfterAll)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 AutoConfigureMockMvc (org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc)1 MediaType (org.springframework.http.MediaType)1