✅ Reussite du test converter ToDomain
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.book;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
public class BookDTO {
|
||||||
|
private ArrayList<String> categories = new ArrayList<>();
|
||||||
|
private String description ;
|
||||||
|
private String language;
|
||||||
|
private String title;
|
||||||
|
private String author;
|
||||||
|
private String editor;
|
||||||
|
private LocalDate date;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.book.converter;
|
||||||
|
|
||||||
|
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDTO;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDetails;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
||||||
|
|
||||||
|
public final class BookConverter {
|
||||||
|
private BookConverter(){}
|
||||||
|
|
||||||
|
public static BookDTO ToDomain(BookInfo bookinfo, BookDetails bookdetails){
|
||||||
|
return BookDTO.builder()
|
||||||
|
.title(bookinfo.title())
|
||||||
|
.author(bookinfo.author())
|
||||||
|
.editor(bookinfo.editor())
|
||||||
|
.date(bookinfo.date())
|
||||||
|
.categories(bookdetails.getCategories())
|
||||||
|
.description(bookdetails.getDescription())
|
||||||
|
.language(bookdetails.getLanguage())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,8 +11,8 @@ import java.util.ArrayList;
|
|||||||
@Builder
|
@Builder
|
||||||
public class Book {
|
public class Book {
|
||||||
private ArrayList<String> categories = new ArrayList<>();
|
private ArrayList<String> categories = new ArrayList<>();
|
||||||
private String description ;
|
private String description ;
|
||||||
private String language;
|
private String language;
|
||||||
private String title;
|
private String title;
|
||||||
private String author;
|
private String author;
|
||||||
private String editor;
|
private String editor;
|
||||||
|
|||||||
+3
-3
@@ -4,6 +4,7 @@ import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDTO;
|
|||||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
|
||||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDetails;
|
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDetails;
|
||||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -12,7 +13,6 @@ import java.util.ArrayList;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
|
|
||||||
@DisplayName("BookConverterTest Unit Tests")
|
@DisplayName("BookConverterTest Unit Tests")
|
||||||
public class BookConverterTest {
|
public class BookConverterTest {
|
||||||
@@ -28,13 +28,13 @@ public class BookConverterTest {
|
|||||||
ArrayList<String> categories = new ArrayList<>();
|
ArrayList<String> categories = new ArrayList<>();
|
||||||
categories.add("Thriller");
|
categories.add("Thriller");
|
||||||
categories.add("Biographie");
|
categories.add("Biographie");
|
||||||
BookDetails.builder()
|
BookDetails bookdetails = BookDetails.builder()
|
||||||
.categories(categories)
|
.categories(categories)
|
||||||
.description("C'était un brave partit trop tôt")
|
.description("C'était un brave partit trop tôt")
|
||||||
.language("Français")
|
.language("Français")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Book result = BookConvert.ToDomain(bookinfo,bookdetails);
|
BookDTO result = BookConverter.ToDomain(bookinfo, bookdetails);
|
||||||
|
|
||||||
//assertNotNull(result);
|
//assertNotNull(result);
|
||||||
assertEquals(bookinfo.title(), result.getTitle());
|
assertEquals(bookinfo.title(), result.getTitle());
|
||||||
|
|||||||
Reference in New Issue
Block a user