test: Commons for suites based on UserRepository

This commit is contained in:
Piotr Dec 2024-05-22 18:20:45 +02:00
parent 2b0baf6066
commit 28ffe3f962
Signed by: stawros
GPG key ID: F89F27AD8F881A91
3 changed files with 121 additions and 29 deletions

View file

@ -0,0 +1,80 @@
package eu.ztsh.wymiana;
import eu.ztsh.wymiana.data.entity.CurrencyEntity;
import eu.ztsh.wymiana.data.entity.UserEntity;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class EntityCreator {
public static class Constants {
public static String PESEL = "00281018264";
public static String NAME = "Janina";
public static String SURNAME = "Kowalska";
public static double PLN = 20.10;
}
public static UserEntityBuilder user() {
return new UserEntityBuilder();
}
public static class UserEntityBuilder {
String name;
String surname;
String pesel;
double pln;
double usd;
public UserEntityBuilder name(String name) {
this.name = name;
return this;
}
public UserEntityBuilder surname(String surname) {
this.surname = surname;
return this;
}
public UserEntityBuilder pesel(String pesel) {
this.pesel = pesel;
return this;
}
public UserEntityBuilder pln(double pln) {
this.pln = pln;
return this;
}
public UserEntityBuilder usd(double usd) {
this.usd = usd;
return this;
}
public UserEntity build() {
var nonnulPesel = Optional.ofNullable(pesel).orElse(Constants.NAME);
List<CurrencyEntity> currencies = new ArrayList<>();
if (pln > 0) {
currencies.add(new CurrencyEntity(nonnulPesel, "PLN", pln));
}
if (usd > 0) {
currencies.add(new CurrencyEntity(nonnulPesel, "USD", usd));
}
if (currencies.isEmpty()) {
currencies.add(new CurrencyEntity(nonnulPesel, "PLN", Constants.PLN));
}
return new UserEntity(
Optional.ofNullable(name).orElse(Constants.NAME),
Optional.ofNullable(surname).orElse(Constants.SURNAME),
nonnulPesel,
currencies
);
}
}
}