дописал тест
This commit is contained in:
parent
37462491b7
commit
fdee063ff2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -68,7 +68,7 @@ public class DemoApplication implements CommandLineRunner {
|
||||
List<OrderLineEntity> lines = new ArrayList();
|
||||
lines.add(new OrderLineEntity(null, 3));
|
||||
final var user1 = userService.create(new UserEntity(null, "Alex", "Kryukov", "akryu@mail.ru", "password"));
|
||||
orderService.create(new OrderEntity(null, user1, null));
|
||||
orderService.create(new OrderEntity(null, user1, lines, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,17 @@ import java.util.Objects;
|
||||
|
||||
public class OrderEntity extends BaseEntity {
|
||||
private UserEntity user;
|
||||
@JsonManagedReference
|
||||
private final List<OrderLineEntity> lines = new ArrayList<>();
|
||||
private List<OrderLineEntity> lines = new ArrayList<>();
|
||||
private Double totalPrice;
|
||||
|
||||
public OrderEntity() {
|
||||
super();
|
||||
}
|
||||
|
||||
public OrderEntity(Long id, UserEntity user, Double totalPrice) {
|
||||
public OrderEntity(Long id, UserEntity user, List<OrderLineEntity> lines, Double totalPrice) {
|
||||
super(id);
|
||||
this.user = user;
|
||||
this.lines = lines;
|
||||
this.totalPrice = totalPrice;
|
||||
}
|
||||
|
||||
|
@ -29,21 +29,22 @@ class OrderServiceTests {
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTest() {
|
||||
orderService.create(new OrderEntity(null, null, null));
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
List<OrderLineEntity> lines = new ArrayList();
|
||||
lines.add(new OrderLineEntity(null, 4));
|
||||
lines.add(new OrderLineEntity(null, 5));
|
||||
lines.add(new OrderLineEntity(null, 6));
|
||||
lines.add(new OrderLineEntity(null, 7));
|
||||
orderService.create(new OrderEntity(null, null, lines, null));
|
||||
|
||||
// Создаем тестовую сущность OrderEntity
|
||||
OrderEntity testOrder = new OrderEntity(null, null, null);
|
||||
OrderEntity testOrder = new OrderEntity(null, null, lines, null);
|
||||
// Вызываем метод create() и сохраняем созданную сущность
|
||||
OrderEntity createdOrder = orderService.create(testOrder);
|
||||
// Проверяем, что метод create() вернул не null
|
||||
Assertions.assertNotNull(createdOrder);
|
||||
// Проверяем, что созданная сущность имеет назначенный ID
|
||||
Assertions.assertNotNull(createdOrder.getId());
|
||||
// Проверяем количество строк
|
||||
int linesize = 4;
|
||||
// проверяем вернет ли нам нужное количество (в данном случае - 4)
|
||||
Assertions.assertEquals(linesize, createdOrder.getLines().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user