#
Junjie
6 小时以前 26784989e73fc36c6315e54939d1b13a50eb5020
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
package com.zy.asrs.controller;
 
import com.core.common.R;
import com.zy.asrs.domain.param.StationCommandMoveParam;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.service.BasDevpService;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.thread.StationThread;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
 
import java.util.Collections;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class StationControllerTest {
 
    @Test
    void commandClearPath_callsThreadClearPath() {
        StationController controller = new StationController();
        BasDevpService basDevpService = mock(BasDevpService.class);
        StationThread stationThread = mock(StationThread.class);
 
        ReflectionTestUtils.setField(controller, "basDevpService", basDevpService);
 
        BasDevp basDevp = new BasDevp();
        basDevp.setStationList("[{\"deviceNo\":1,\"stationId\":145}]");
        when(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
                .thenReturn(Collections.singletonList(basDevp));
        when(stationThread.clearPath(10335)).thenReturn(true);
 
        StationCommandMoveParam param = new StationCommandMoveParam();
        param.setStationId(145);
        param.setTaskNo(10335);
 
        SlaveConnection.put(SlaveType.Devp, 1, stationThread);
        try {
            R result = controller.commandClearPath(param);
 
            assertEquals(200, result.get("code"));
            verify(stationThread).clearPath(10335);
        } finally {
            SlaveConnection.remove(SlaveType.Devp, 1);
        }
    }
}