yanderong
2026-10-02 bca4733e4b0fcd9b6496e608304549a09f982463
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
package com.ruoyi.other.service.impl;
 
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.api.dto.VinManagementQueryDTO;
import com.ruoyi.account.api.feignClient.FleetUnbindClient;
import com.ruoyi.account.api.feignClient.VinManagementClient;
import com.ruoyi.account.api.model.TVinManagement;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.other.api.domain.TChargeAuthorization;
import com.ruoyi.other.api.domain.TFleet;
import com.ruoyi.other.api.domain.TGroupCompany;
import com.ruoyi.other.api.dto.FleetImportDTO;
import com.ruoyi.other.api.feignClient.FleetOrderAggregateClient;
import com.ruoyi.other.api.vo.FleetOrderAggregateVO;
import com.ruoyi.other.mapper.TChargeAuthorizationMapper;
import com.ruoyi.other.mapper.TFleetMapper;
import com.ruoyi.other.service.CompanyAccountAccessService;
import com.ruoyi.other.service.TGroupCompanyService;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.test.util.ReflectionTestUtils;
 
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
 
/**
 * 车队服务单测(覆盖 VIN 列表分页代理 + 5 列聚合 fillAggregates)。
 * 远程客户端和 Mapper 以 Mock 替代,不依赖 Spring 容器与数据库。
 */
class TFleetServiceImplTest {
 
    @BeforeAll
    static void initTableInfo() {
        // MP 的 lambdaQuery 会通过 TableInfoHelper 取表元数据解析 lambda 列名,
        // 单元测试不启动 Spring,需要手动初始化 TableInfo,否则抛 MybatisPlusException
        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), TFleet.class);
    }
 
    @Test
    void passesFleetIdAndPagingToVinService() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        Page<TVinManagement> expected = new Page<>(1, 10);
        expected.setTotal(1);
        expected.setRecords(Collections.singletonList(vehicle()));
        Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(expected));
 
        Page<TVinManagement> actual = buildService(fleet(4), client, null, null).selectVinPage(4, 1, 10);
 
        assertSame(expected, actual);
        ArgumentCaptor<VinManagementQueryDTO> captor = ArgumentCaptor.forClass(VinManagementQueryDTO.class);
        Mockito.verify(client).getVinPageByFleet(captor.capture());
        assertEquals(4, captor.getValue().getFleetId());
        assertEquals(1, captor.getValue().getPageCurr());
        assertEquals(10, captor.getValue().getPageSize());
    }
 
    @Test
    void fallsBackToDefaultPagingWhenParamsInvalid() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(new Page<>(1, 10)));
 
        buildService(fleet(5), client, null, null).selectVinPage(5, null, 0);
 
        ArgumentCaptor<VinManagementQueryDTO> captor = ArgumentCaptor.forClass(VinManagementQueryDTO.class);
        Mockito.verify(client).getVinPageByFleet(captor.capture());
        assertEquals(1, captor.getValue().getPageCurr());
        assertEquals(10, captor.getValue().getPageSize());
    }
 
    @Test
    void rejectsMissingFleetId() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        TFleetServiceImpl service = buildService(null, client, null, null);
 
        ServiceException ex = assertThrows(ServiceException.class, () -> service.selectVinPage(null, 1, 10));
 
        assertTrue(ex.getMessage().contains("车队ID不能为空"), ex.getMessage());
        Mockito.verifyNoInteractions(client);
    }
 
    @Test
    void rejectsUnknownFleet() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        TFleetServiceImpl service = buildService(null, client, null, null);
 
        ServiceException ex = assertThrows(ServiceException.class, () -> service.selectVinPage(9, 1, 10));
 
        assertTrue(ex.getMessage().contains("车队不存在"), ex.getMessage());
        Mockito.verifyNoInteractions(client);
    }
 
    @Test
    void failsWhenRemoteReturnsError() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.fail("VIN 管理服务调用失败"));
 
        ServiceException ex = assertThrows(ServiceException.class,
                () -> buildService(fleet(4), client, null, null).selectVinPage(4, 1, 10));
 
        assertTrue(ex.getMessage().contains("VIN码车辆查询失败"), ex.getMessage());
    }
 
    @Test
    void failsWhenRemoteReturnsNullData() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(null);
 
        ServiceException ex = assertThrows(ServiceException.class,
                () -> buildService(fleet(4), client, null, null).selectVinPage(4, 1, 10));
 
        assertTrue(ex.getMessage().contains("服务无响应"), ex.getMessage());
    }
 
    @Test
    void fillsCompanyBalanceForSharedAccountMode() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        Page<TVinManagement> page = new Page<>(1, 10);
        page.setRecords(Collections.singletonList(vehicle()));
        Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(page));
 
        TGroupCompanyService groupCompanyService = Mockito.mock(TGroupCompanyService.class);
        TGroupCompany company = new TGroupCompany();
        company.setId(7);
        company.setAccountMode(1);
        company.setAvailableBalance(new BigDecimal("500.00"));
        Mockito.when(groupCompanyService.getById(7)).thenReturn(company);
 
        TFleet fleet = fleet(4);
        fleet.setCompanyId(7);
 
        buildService(fleet, client, null, null, groupCompanyService).selectVinPage(4, 1, 10);
 
        // 共享模式展示公司当前可用余额,而非 VIN 自身余额(vehicle() balance=30.00)
        assertEquals(0, new BigDecimal("500.00").compareTo(page.getRecords().get(0).getAvailableBalance()));
    }
 
    @Test
    void fillsVinBalanceForAllocationAccountMode() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        Page<TVinManagement> page = new Page<>(1, 10);
        page.setRecords(Collections.singletonList(vehicle()));
        Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(page));
 
        TGroupCompanyService groupCompanyService = Mockito.mock(TGroupCompanyService.class);
        TGroupCompany company = new TGroupCompany();
        company.setId(7);
        company.setAccountMode(2);
        company.setAvailableBalance(new BigDecimal("500.00"));
        Mockito.when(groupCompanyService.getById(7)).thenReturn(company);
 
        TFleet fleet = fleet(4);
        fleet.setCompanyId(7);
 
        buildService(fleet, client, null, null, groupCompanyService).selectVinPage(4, 1, 10);
 
        // 分配模式展示 VIN 自身余额
        assertEquals(0, new BigDecimal("30.00").compareTo(page.getRecords().get(0).getAvailableBalance()));
    }
 
    @Test
    void treatsNullAccountModeAsSharedAndKeepsNullWhenCompanyMissing() {
        VinManagementClient client = Mockito.mock(VinManagementClient.class);
        Page<TVinManagement> page = new Page<>(1, 10);
        TVinManagement first = vehicle();
        page.setRecords(Collections.singletonList(first));
        Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(page));
 
        TGroupCompanyService groupCompanyService = Mockito.mock(TGroupCompanyService.class);
        TGroupCompany company = new TGroupCompany();
        company.setId(7);
        company.setAccountMode(null);
        company.setAvailableBalance(new BigDecimal("88.00"));
        Mockito.when(groupCompanyService.getById(7)).thenReturn(company);
 
        TFleet fleet = fleet(4);
        fleet.setCompanyId(7);
        buildService(fleet, client, null, null, groupCompanyService).selectVinPage(4, 1, 10);
 
        // 历史数据账户模式为 null 时按共享模式展示公司余额(与系统"仅 ==2 为分配"口径一致)
        assertEquals(0, new BigDecimal("88.00").compareTo(first.getAvailableBalance()));
 
        // 公司不存在(如已被删除)→ 保持 null,前端显示 '-'
        Mockito.when(groupCompanyService.getById(8)).thenReturn(null);
        TFleet other = fleet(6);
        other.setCompanyId(8);
        Page<TVinManagement> otherPage = new Page<>(1, 10);
        TVinManagement third = vehicle();
        third.setId(3L);
        otherPage.setRecords(Collections.singletonList(third));
        Mockito.when(client.getVinPageByFleet(Mockito.any())).thenReturn(R.ok(otherPage));
 
        buildService(other, client, null, null, groupCompanyService).selectVinPage(6, 1, 10);
 
        assertNull(third.getAvailableBalance());
    }
 
    @Test
    void fillAggregatesPopulatesAllFiveFields() {
        VinManagementClient vinClient = Mockito.mock(VinManagementClient.class);
        FleetOrderAggregateClient aggClient = Mockito.mock(FleetOrderAggregateClient.class);
        TChargeAuthorizationMapper authMapper = Mockito.mock(TChargeAuthorizationMapper.class);
 
        TFleet fleet = fleet(101);
        fleet.setCompanyId(7);
 
        Mockito.when(vinClient.countByFleet(101)).thenReturn(R.ok(8L));
 
        FleetOrderAggregateVO vo = new FleetOrderAggregateVO();
        vo.setCumulativeCharge(new BigDecimal("12.34"));
        vo.setCumulativeElectrovalence(new BigDecimal("56.78"));
        vo.setCumulativeServiceCharge(new BigDecimal("9.10"));
        Mockito.when(aggClient.aggregateByFleet(101)).thenReturn(R.ok(vo));
 
        TChargeAuthorization auth = new TChargeAuthorization();
        auth.setCompanyId(7);
        auth.setSiteIds("1,2,3,2,1");
        Mockito.when(authMapper.selectList(Mockito.any())).thenReturn(Collections.singletonList(auth));
 
        TFleetServiceImpl service = buildService(fleet, vinClient, aggClient, authMapper);
        service.fillAggregates(Arrays.asList(fleet));
 
        assertEquals(8L, fleet.getVinCount());
        assertEquals(3L, fleet.getStationCount());
        assertNotNull(fleet.getCumulativeCharge());
        assertEquals(0, new BigDecimal("12.34").compareTo(fleet.getCumulativeCharge()));
        assertEquals(0, new BigDecimal("56.78").compareTo(fleet.getCumulativeElectrovalence()));
        assertEquals(0, new BigDecimal("9.10").compareTo(fleet.getCumulativeServiceCharge()));
    }
 
    @Test
    void fillAggregatesHandlesNullFleetIdSafely() {
        VinManagementClient vinClient = Mockito.mock(VinManagementClient.class);
        FleetOrderAggregateClient aggClient = Mockito.mock(FleetOrderAggregateClient.class);
        TChargeAuthorizationMapper authMapper = Mockito.mock(TChargeAuthorizationMapper.class);
        TFleetServiceImpl service = buildService(null, vinClient, aggClient, authMapper);
 
        // 传入空集合 / null 不抛异常
        service.fillAggregates(null);
        service.fillAggregates(Collections.emptyList());
        Mockito.verifyNoInteractions(vinClient, aggClient, authMapper);
    }
 
    @Test
    void fillAggregatesFallsBackToZeroOnRemoteFailure() {
        VinManagementClient vinClient = Mockito.mock(VinManagementClient.class);
        FleetOrderAggregateClient aggClient = Mockito.mock(FleetOrderAggregateClient.class);
        TChargeAuthorizationMapper authMapper = Mockito.mock(TChargeAuthorizationMapper.class);
 
        TFleet fleet = fleet(202);
        fleet.setCompanyId(null);
        Mockito.when(vinClient.countByFleet(202)).thenReturn(R.fail("down"));
        Mockito.when(aggClient.aggregateByFleet(202)).thenReturn(null);
        Mockito.when(authMapper.selectList(Mockito.any())).thenReturn(Collections.emptyList());
 
        TFleetServiceImpl service = buildService(fleet, vinClient, aggClient, authMapper);
        service.fillAggregates(Arrays.asList(fleet));
 
        assertEquals(0L, fleet.getVinCount());
        assertEquals(0L, fleet.getStationCount());
        assertEquals(BigDecimal.ZERO, fleet.getCumulativeCharge());
        assertEquals(BigDecimal.ZERO, fleet.getCumulativeElectrovalence());
        assertEquals(BigDecimal.ZERO, fleet.getCumulativeServiceCharge());
    }
 
    private TFleetServiceImpl buildService(TFleet fleet, VinManagementClient client,
                                           FleetOrderAggregateClient aggClient,
                                           TChargeAuthorizationMapper authMapper) {
        return buildService(fleet, client, aggClient, authMapper, Mockito.mock(TGroupCompanyService.class));
    }
 
    private TFleetServiceImpl buildService(TFleet fleet, VinManagementClient client,
                                           FleetOrderAggregateClient aggClient,
                                           TChargeAuthorizationMapper authMapper,
                                           TGroupCompanyService groupCompanyService) {
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        Mockito.doReturn(fleet).when(service).getById(Mockito.any());
        ReflectionTestUtils.setField(service, "vinManagementClient", client);
        ReflectionTestUtils.setField(service, "fleetOrderAggregateClient", aggClient);
        ReflectionTestUtils.setField(service, "chargeAuthorizationMapper", authMapper);
        ReflectionTestUtils.setField(service, "groupCompanyService", groupCompanyService);
        return service;
    }
 
    @Test
    void deleteFleetsUnbindsThenRemoves() {
        FleetUnbindClient unbindClient = Mockito.mock(FleetUnbindClient.class);
        Mockito.when(unbindClient.unbindByFleetIds(Mockito.anyList())).thenReturn(R.ok(3));
 
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        ReflectionTestUtils.setField(service, "fleetUnbindClient", unbindClient);
        Mockito.doReturn(Arrays.asList(fleet(1), fleet(2))).when(service).listByIds(Mockito.anyList());
        Mockito.doReturn(true).when(service).removeByIds(Mockito.anyList());
 
        assertTrue(service.deleteFleets(Arrays.asList(1, 2)));
 
        @SuppressWarnings("unchecked")
        ArgumentCaptor<List<Integer>> idsCaptor = ArgumentCaptor.forClass(List.class);
        Mockito.verify(unbindClient).unbindByFleetIds(idsCaptor.capture());
        assertEquals(Arrays.asList(1, 2), idsCaptor.getValue());
        Mockito.verify(service).removeByIds(Mockito.anyList());
    }
 
    @Test
    void deleteFleetsDeduplicatesAndFiltersNullIds() {
        FleetUnbindClient unbindClient = Mockito.mock(FleetUnbindClient.class);
        Mockito.when(unbindClient.unbindByFleetIds(Mockito.anyList())).thenReturn(R.ok(0));
 
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        ReflectionTestUtils.setField(service, "fleetUnbindClient", unbindClient);
        Mockito.doReturn(Collections.singletonList(fleet(1))).when(service).listByIds(Mockito.anyList());
        Mockito.doReturn(true).when(service).removeByIds(Mockito.anyList());
 
        assertTrue(service.deleteFleets(Arrays.asList(1, null, 1)));
 
        @SuppressWarnings("unchecked")
        ArgumentCaptor<List<Integer>> idsCaptor = ArgumentCaptor.forClass(List.class);
        Mockito.verify(unbindClient).unbindByFleetIds(idsCaptor.capture());
        assertEquals(Collections.singletonList(1), idsCaptor.getValue());
        Mockito.verify(service).removeByIds(Collections.singletonList(1));
    }
 
    @Test
    void deleteFleetsRejectsNullOrEmptyIds() {
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        ReflectionTestUtils.setField(service, "fleetUnbindClient", Mockito.mock(FleetUnbindClient.class));
 
        ServiceException nullEx = assertThrows(ServiceException.class, () -> service.deleteFleets(null));
        assertTrue(nullEx.getMessage().contains("请选择需要删除的车队"), nullEx.getMessage());
        ServiceException emptyEx = assertThrows(ServiceException.class,
                () -> service.deleteFleets(Arrays.asList(null, null)));
        assertTrue(emptyEx.getMessage().contains("请选择需要删除的车队"), emptyEx.getMessage());
    }
 
    @Test
    void deleteFleetsRejectsMissingFleetWithoutUnbinding() {
        FleetUnbindClient unbindClient = Mockito.mock(FleetUnbindClient.class);
 
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        ReflectionTestUtils.setField(service, "fleetUnbindClient", unbindClient);
        Mockito.doReturn(Collections.emptyList()).when(service).listByIds(Mockito.anyList());
 
        ServiceException ex = assertThrows(ServiceException.class, () -> service.deleteFleets(Collections.singletonList(9)));
 
        assertTrue(ex.getMessage().contains("部分车队不存在"), ex.getMessage());
        Mockito.verifyNoInteractions(unbindClient);
        Mockito.verify(service, Mockito.never()).removeByIds(Mockito.anyList());
    }
 
    @Test
    void deleteFleetsAbortsWhenUnbindFails() {
        FleetUnbindClient unbindClient = Mockito.mock(FleetUnbindClient.class);
        Mockito.when(unbindClient.unbindByFleetIds(Mockito.anyList())).thenReturn(R.fail("车队关联数据解绑失败:超时"));
 
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        ReflectionTestUtils.setField(service, "fleetUnbindClient", unbindClient);
        Mockito.doReturn(Collections.singletonList(fleet(1))).when(service).listByIds(Mockito.anyList());
 
        ServiceException ex = assertThrows(ServiceException.class, () -> service.deleteFleets(Collections.singletonList(1)));
 
        // 解绑失败中止删除:车队与绑定关系均保留,两侧数据保持一致
        assertTrue(ex.getMessage().contains("车队关联数据解绑失败"), ex.getMessage());
        Mockito.verify(service, Mockito.never()).removeByIds(Mockito.anyList());
    }
 
    @Test
    void deleteFleetsAbortsWhenRemoteThrows() {
        FleetUnbindClient unbindClient = Mockito.mock(FleetUnbindClient.class);
        Mockito.when(unbindClient.unbindByFleetIds(Mockito.anyList()))
                .thenThrow(new RuntimeException("connect refused"));
 
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        ReflectionTestUtils.setField(service, "fleetUnbindClient", unbindClient);
        Mockito.doReturn(Collections.singletonList(fleet(1))).when(service).listByIds(Mockito.anyList());
 
        ServiceException ex = assertThrows(ServiceException.class, () -> service.deleteFleets(Collections.singletonList(1)));
 
        assertTrue(ex.getMessage().contains("车队关联数据解绑失败"), ex.getMessage());
        Mockito.verify(service, Mockito.never()).removeByIds(Mockito.anyList());
    }
 
    @Test
    void importFleetsForcesCompanyAccountOwnership() {
        // 公司账号:导入车队强制归属本公司,Excel 中的所属公司仅作展示信息,不做公司名校验
        TFleetMapper fleetMapper = Mockito.mock(TFleetMapper.class);
        Mockito.when(fleetMapper.selectCount(Mockito.any())).thenReturn(0L);
        Mockito.when(fleetMapper.insert(Mockito.any(TFleet.class))).thenReturn(1);
        CompanyAccountAccessService access = Mockito.mock(CompanyAccountAccessService.class);
        Mockito.when(access.getCurrentCompanyId()).thenReturn(2);
 
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        ReflectionTestUtils.setField(service, "baseMapper", fleetMapper);
        ReflectionTestUtils.setField(service, "companyAccountAccessService", access);
 
        FleetImportDTO item = new FleetImportDTO();
        item.setFleetName("公司导入车队");
        item.setCompanyName("随意填写的公司");
 
        String result = service.importFleets(Collections.singletonList(item));
 
        assertTrue(result.contains("成功导入"));
        ArgumentCaptor<TFleet> captor = ArgumentCaptor.forClass(TFleet.class);
        Mockito.verify(fleetMapper).insert(captor.capture());
        assertEquals(Integer.valueOf(2), captor.getValue().getCompanyId());
    }
 
    @Test
    void importFleetsRequiresCompanyNameForNonCompanyAccount() {
        // 平台/合作商账号:无公司锁定时所属公司必填
        TFleetMapper fleetMapper = Mockito.mock(TFleetMapper.class);
        CompanyAccountAccessService access = Mockito.mock(CompanyAccountAccessService.class);
        Mockito.when(access.getCurrentCompanyId()).thenReturn(null);
 
        TFleetServiceImpl service = Mockito.spy(new TFleetServiceImpl());
        ReflectionTestUtils.setField(service, "baseMapper", fleetMapper);
        ReflectionTestUtils.setField(service, "companyAccountAccessService", access);
 
        FleetImportDTO item = new FleetImportDTO();
        item.setFleetName("无公司车队");
 
        ServiceException ex = assertThrows(ServiceException.class,
                () -> service.importFleets(Collections.singletonList(item)));
 
        assertTrue(ex.getMessage().contains("所属公司不能为空"), ex.getMessage());
        Mockito.verify(fleetMapper, Mockito.never()).insert(Mockito.any(TFleet.class));
    }
 
    private TFleet fleet(Integer id) {
        TFleet fleet = new TFleet();
        fleet.setId(id);
        return fleet;
    }
 
    private TVinManagement vehicle() {
        TVinManagement item = new TVinManagement();
        item.setId(1L);
        item.setVin("12345678900000000");
        item.setPlateNumber("川A123456");
        item.setFleetId(4);
        item.setBalance(new BigDecimal("30.00"));
        item.setStatus(1);
        return item;
    }
}