My application has several entities that are annotated with @Getter and are using the @Builder. I need to create a list of Customers with specific data to test a method. I am unable create a list of OrderDetails and assign it to an Order because this property only has a getter method. I also tried mocking the objects but again I get the error unable set the property. The only way I have been able to test the method is by using an H2 database with test data. Is there another way to test my method without using an H2 database? Thanks.
@Getter
@Entity
public class Customer
private Long customerId;
private String firstName;
private String lastName;
@OneToMany(
mappedBy = "order",
cascade = CascadeType.ALL,
fetch = FetchType.EAGER)
private List<Order> orders = new ArrayList<>();
@Builder(toBuilder = true)
public Customer(Long customerID,
String firstName,
String lastName,
@Getter
@Entity
public class Order
private Long orderId;
private Long orderLocationId;
private OrderStatus orderStatus;
@ManyToOne
private Customer customer;
@OneToMany(mappedBy = "orderLine", cascade = CascadeType.ALL
private List<OrderDetails> orderDetails;
@Builder(toBuilder = true)
public Order(OrderStatus orderStatus,
Long orderLocationId,
Customer customer,
@Getter
@Entity
public class OrderDetails
private Long orderDetailId;
private Long quantity;
private Instant orderTimestamp = Instant.now();
@ManyToOne
private Order order;
@Builder(toBuilder = true)
public OrderDetails(
Integer quantity,
Order order) {
Aucun commentaire:
Enregistrer un commentaire