liujie
2026-09-15 5a95ec36565d7ecc1a5ecb261f26752c90dec120
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.estate.expert.admin.service;
 
import com.estate.expert.admin.domain.business.car.*;
import com.estate.expert.admin.domain.common.EntityRef;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.List;
 
@Slf4j
@SpringBootTest
@ExtendWith(SpringExtension.class)
@Transactional
public class CarServiceTest {
 
    @Autowired
    private CarService carService;
 
    @Resource
    private UserService userService;
 
 
    Car currentCar;
 
    @BeforeEach
    public void setUp() {
        var car = CarDto.builder()
                .name("京ADR6379")
                .departmentPath("/1")
                .model("别克君越")
                .build();
 
        currentCar = carService.add(userService.getSystemUser(), car);
        Assertions.assertNotNull(currentCar);
    }
 
    @AfterEach
    public void tearDown() {
        carService.deleteAllById(List.of(currentCar.getId()));
    }
 
    @Test
    public void testEdit() {
        var request = CarDto.builder()
                .id(currentCar.getId())
                .model("别克君越111")
                .driver(EntityRef.of(2, "张三"))
                .build();
 
        carService.edit(request);
        var car = carService.get(currentCar.getId());
        Assertions.assertEquals("别克君越111", car.getName());
 
        Assertions.assertNotNull(car.getDriver());
        Assertions.assertEquals(2, car.getDriver().getId());
    }
 
    @Test
    public void testList() {
        var list = carService.list(null, "京ADR6");
        Assertions.assertFalse(list.isEmpty());
 
        list = carService.list(null, "京ADD37");
        Assertions.assertTrue(list.isEmpty());
 
        carService.deleteAllById(List.of(currentCar.getId()));
 
        list = carService.list(null, "京ADR6");
        Assertions.assertTrue(list.isEmpty());
    }
 
 
}