forked from pierront/mylibrary-template
refactorr d'un nom de fichier
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record ComandeInfo(List<LigneCommandeInfo> listeLigne ,String modePayement) {
|
||||
}
|
||||
@@ -16,4 +16,10 @@ public class CommandeDTO {
|
||||
private String codePostal;
|
||||
private String pays;
|
||||
private String modePaiement;
|
||||
|
||||
|
||||
private UUID commandeId ;
|
||||
private double montantTotal ;
|
||||
private Integer pointsFideliteGagnes ;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record CommandeInfo(List<LigneCommandeInfo> listeLigne , String modePayement) {
|
||||
}
|
||||
+3
-4
@@ -1,15 +1,14 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.converter;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ComandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
|
||||
public final class CommandeConverter {
|
||||
|
||||
|
||||
public static Commande toDomain(ComandeInfo commandeInfo, AdresseInfo adressInfo, String modePaiement) {
|
||||
public static Commande toDomain(CommandeInfo commandeInfo, AdresseInfo adressInfo, String modePaiement) {
|
||||
return Commande.builder()
|
||||
.lignesCommande(commandeInfo.listeLigne())
|
||||
.rue(adressInfo.rue())
|
||||
@@ -20,7 +19,7 @@ public final class CommandeConverter {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CommandeDTO toDTO(ComandeInfo commandeInfo, AdresseInfo adressInfo, String modePaiement) {
|
||||
public static CommandeDTO toDTO(CommandeInfo commandeInfo, AdresseInfo adressInfo, String modePaiement) {
|
||||
return CommandeDTO.builder()
|
||||
.lignesCommande(commandeInfo.listeLigne())
|
||||
.rue(adressInfo.rue())
|
||||
|
||||
+10
-11
@@ -1,13 +1,12 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.validator;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ComandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidAdressException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidCommandeException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidLigneCommandeException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class CommandeValidator {
|
||||
@@ -28,10 +27,10 @@ public final class CommandeValidator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void validate(ComandeInfo comandeInfo) {
|
||||
public static void validate(CommandeInfo commandeInfo) {
|
||||
|
||||
validateModePaiement(comandeInfo);
|
||||
validateListLigneCommande(comandeInfo);
|
||||
validateModePaiement(commandeInfo);
|
||||
validateListLigneCommande(commandeInfo);
|
||||
}
|
||||
|
||||
public static void validate(AdresseInfo adresseInfo) {
|
||||
@@ -43,16 +42,16 @@ public final class CommandeValidator {
|
||||
|
||||
|
||||
|
||||
private static void validateModePaiement(ComandeInfo comandeInfo) {
|
||||
if(comandeInfo.modePayement()!="CB"&& comandeInfo.modePayement()!="PAYPAL"&&comandeInfo.modePayement()!="POINTS_FIDELITE"){
|
||||
private static void validateModePaiement(CommandeInfo commandeInfo) {
|
||||
if(commandeInfo.modePayement()!="CB"&& commandeInfo.modePayement()!="PAYPAL"&& commandeInfo.modePayement()!="POINTS_FIDELITE"){
|
||||
throw new NotValidCommandeException(MODE_PAIEMENT_IS_NOT_VALIDE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateListLigneCommande(ComandeInfo comandeInfo) {
|
||||
if (comandeInfo.listeLigne() == null
|
||||
|| comandeInfo.listeLigne().isEmpty()
|
||||
|| comandeInfo.listeLigne().stream().anyMatch(Objects::isNull)){
|
||||
private static void validateListLigneCommande(CommandeInfo commandeInfo) {
|
||||
if (commandeInfo.listeLigne() == null
|
||||
|| commandeInfo.listeLigne().isEmpty()
|
||||
|| commandeInfo.listeLigne().stream().anyMatch(Objects::isNull)){
|
||||
throw new NotValidCommandeException(LIST_LIGNE_COMANDE_IS_NOT_VALIDE);
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -22,7 +21,7 @@ public class CommandeConverterTest {
|
||||
LigneCommandeInfo ligne2 = new LigneCommandeInfo(14);
|
||||
listLigne.add(ligne);
|
||||
listLigne.add(ligne2);
|
||||
ComandeInfo commandeInfo = new ComandeInfo(listLigne,modePaiement);
|
||||
CommandeInfo commandeInfo = new CommandeInfo(listLigne,modePaiement);
|
||||
AdresseInfo adressInfo = new AdresseInfo("rue du cheval","La Rochette","77000","France");
|
||||
|
||||
|
||||
@@ -46,7 +45,7 @@ public class CommandeConverterTest {
|
||||
LigneCommandeInfo ligne2 = new LigneCommandeInfo(14);
|
||||
listLigne.add(ligne);
|
||||
listLigne.add(ligne2);
|
||||
ComandeInfo commandeInfo = new ComandeInfo(listLigne,modePaiement);
|
||||
CommandeInfo commandeInfo = new CommandeInfo(listLigne,modePaiement);
|
||||
AdresseInfo adressInfo = new AdresseInfo("rue du cheval","La Rochette","77000","France");
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception;
|
||||
|
||||
public class Test {
|
||||
}
|
||||
-2
@@ -3,8 +3,6 @@ package fr.iut_fbleau.but3.dev62.mylibrary.commande.repository;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.repository.CustomerRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.usecase;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.repository.ComandeRepository;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.customer.usecase.CustomerUseCase;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandeUseCase {
|
||||
|
||||
@Mock
|
||||
private ComandeRepository comandeRepository;
|
||||
|
||||
|
||||
@InjectMocks
|
||||
private CommandeUseCase commandeUseCase;
|
||||
|
||||
private UUID commandeId;
|
||||
private UUID clientId;
|
||||
private Commande testCommande;
|
||||
private CommandeInfo validCommandeInfo;
|
||||
private LigneCommandeInfo validLigneCommandeInfo;
|
||||
private AdresseInfo validAdresseInfo;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
clientId = UUID.randomUUID();
|
||||
commandeId = UUID.randomUUID();
|
||||
List<LigneCommandeInfo> lignesCommande = new ArrayList<>();
|
||||
LigneCommandeInfo commande1 = new LigneCommandeInfo(12);
|
||||
LigneCommandeInfo commande2 = new LigneCommandeInfo(13);
|
||||
lignesCommande.add(commande1);
|
||||
lignesCommande.add(commande2);
|
||||
String rue = "rue du chien";
|
||||
String ville = "LKa Rochette";
|
||||
String codePostal = "7700";
|
||||
String pays = "France";
|
||||
String modePayement = ModePaiement.CB.name();
|
||||
|
||||
testCommande = Commande.builder()
|
||||
.clientId(clientId)
|
||||
.lignesCommande(lignesCommande)
|
||||
.rue(rue)
|
||||
.ville(ville)
|
||||
.codePostal(codePostal)
|
||||
.pays(pays)
|
||||
.modePaiement(modePayement)
|
||||
.commandeId(commandeId)
|
||||
.build();
|
||||
|
||||
|
||||
validCommandeInfo = new CommandeInfo(lignesCommande,ModePaiement.CB.name());
|
||||
validLigneCommandeInfo= new LigneCommandeInfo(12);
|
||||
validAdresseInfo = new AdresseInfo("rue du chien","LKa Rochette","7700","France");
|
||||
}
|
||||
|
||||
|
||||
@Nested
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.validator;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ComandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidAdressException;
|
||||
@@ -47,7 +47,7 @@ public class CommandeValidatorTest {
|
||||
List<LigneCommandeInfo> listeLigne = new ArrayList<>();
|
||||
listeLigne.add(ligneCommandeValide);
|
||||
String modePaiementValide = modePaiement.toString();
|
||||
ComandeInfo commandeValid = new ComandeInfo(listeLigne, modePaiementValide);
|
||||
CommandeInfo commandeValid = new CommandeInfo(listeLigne, modePaiementValide);
|
||||
|
||||
assertDoesNotThrow(() -> CommandeValidator.validate(commandeValid));
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class CommandeValidatorTest {
|
||||
List<LigneCommandeInfo> listeLigne = new ArrayList<>();
|
||||
listeLigne.add(ligneCommandeValide);
|
||||
String modePaiementValide = modePaiementError;
|
||||
ComandeInfo commandeValid = new ComandeInfo(listeLigne, modePaiementValide);
|
||||
CommandeInfo commandeValid = new CommandeInfo(listeLigne, modePaiementValide);
|
||||
|
||||
NotValidCommandeException exception = assertThrows(
|
||||
NotValidCommandeException.class,
|
||||
@@ -72,7 +72,7 @@ public class CommandeValidatorTest {
|
||||
@MethodSource("provideInvalidOrderLists")
|
||||
void testValidateNotValideListLigneCommande(List<LigneCommandeInfo> listeLigne) {
|
||||
String modePaiementValide = ModePaiement.CB.toString();
|
||||
ComandeInfo commandeValid = new ComandeInfo(listeLigne, modePaiementValide);
|
||||
CommandeInfo commandeValid = new CommandeInfo(listeLigne, modePaiementValide);
|
||||
NotValidCommandeException exception = assertThrows(
|
||||
NotValidCommandeException.class,
|
||||
() -> CommandeValidator.validate(commandeValid)
|
||||
|
||||
Reference in New Issue
Block a user